Skip to content

Commit

Permalink
Standardization of the stream class
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkmyter committed May 23, 2018
1 parent 5a13cb5 commit 4f80388
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 172 deletions.
265 changes: 191 additions & 74 deletions src/skmultiflow/data/base_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,132 +24,249 @@ def __init__(self):
self.current_sample_x = None
self.current_sample_y = None
self.sample_idx = 0
self.feature_names = []
self.target_names = []

@property
def n_features(self):
""" Retrieve the number of features.
@abstractmethod
def n_remaining_samples(self):
""" Returns the estimated number of remaining samples.
Returns
-------
int
Remaining number of samples. -1 if infinite (e.g. generator)
The total number of features.
"""
raise NotImplementedError
return self._n_features

@abstractmethod
def has_more_samples(self):
raise NotImplementedError
@n_features.setter
def n_features(self, n_features):
""" Set the number of features
"""
self._n_features = n_features

@property
def n_cat_features(self):
""" Retrieve the number of integer features.
@abstractmethod
def next_sample(self, batch_size=1):
""" Generates or returns next `batch_size` samples in the stream.
Parameters
----------
batch_size: int
How many samples at a time to return.
Returns
-------
tuple or tuple list
A numpy.ndarray of shape (batch_size, n_features) and an array-like of size
n_targets, representing the next batch_size samples.
int
The number of integer features in the stream.
"""
raise NotImplementedError
return self._n_cat_features

@abstractmethod
def last_sample(self):
""" Retrieves last `batch_size` samples in the stream.
@n_cat_features.setter
def n_cat_features(self, n_cat_features):
""" Set the number of integer features
Parameters
----------
n_cat_features: int
"""
self._n_cat_features = n_cat_features

@property
def n_num_features(self):
""" Retrieve the number of numerical features.
Returns
-------
tuple or tuple list
A numpy.ndarray of shape (batch_size, n_features) and an array-like of shape
(batch_size, n_targets), representing the next batch_size samples.
int
The number of numerical features in the stream.
"""
raise NotImplementedError
return self._n_num_features

@abstractmethod
def is_restartable(self):
""" Determine if the stream is restartable. """
raise NotImplementedError
@n_num_features.setter
def n_num_features(self, n_num_features):
""" Set the number of numerical features
@abstractmethod
def restart(self):
""" Restart the stream. """
raise NotImplementedError
Parameters
----------
n_num_features: int
@abstractmethod
def get_n_features(self):
""" Retrieve the number of features.
"""
self._n_num_features = n_num_features

@property
def n_targets(self):
""" Retrieve the number of targets
Returns
-------
int
The total number of features.
the number of targets in the stream.
"""
return self._n_targets

@n_targets.setter
def n_targets(self, n_targets):
""" Set the number of targets.
Parameters
----------
n_targets: int
"""
raise NotImplementedError
self._n_targets = n_targets

@property
def targets(self):
""" Retrieve all classes in the stream for each target.
@abstractmethod
def get_n_cat_features(self):
""" Retrieve the number of nominal features.
Returns
-------
int
The number of nominal features in the stream.
list
list of lists of all classes for each target
"""
raise NotImplementedError
return self._targets

@abstractmethod
def get_n_num_features(self):
""" Retrieve the number of numerical atfeaturestributes.
@targets.setter
def targets(self, targets):
""" Set the list for all classes in the stream.
Parameters
----------
targets
"""
self._targets = targets

@property
def feature_names(self):
""" Retrieve the names of the features.
Returns
-------
int
The number of numerical features in the stream.
list
names of the features
"""
return self._feature_names

@feature_names.setter
def feature_names(self, feature_names):
""" Set the name of the features in the stream.
Parameters
----------
feature_names: list
"""
self._feature_names = feature_names

@property
def target_names(self):
""" Retrieve the names of the targets.
Returns
-------
list
the names of the targets in the stream.
"""
raise NotImplementedError
return self._target_names

@abstractmethod
def get_n_targets(self):
raise NotImplementedError
@target_names.setter
def target_names(self, target_names):
""" Set the names of the targets in the stream.
@abstractmethod
def get_targets(self):
""" Get all classes in the stream. """
raise NotImplementedError
Parameters
----------
target_names: list
@abstractmethod
def get_feature_names(self):
raise NotImplementedError
"""
self._target_names = target_names

@abstractmethod
def get_target_names(self):
raise NotImplementedError
@property
def random_state(self):
""" Retrieve the random state of the stream.
Returns
-------
RandomState
"""
return self._random_state

@random_state.setter
def random_state(self, random_state):
""" Set the random state of the stream
Parameters
----------
random_state
Returns
-------
"""
self._random_state = random_state

@abstractmethod
def prepare_for_use(self):
""" prepare_for_use
Prepare the stream for use. Can be the reading of a file, or
the generation of a function, or anything necessary for the
Prepare the stream for use. Can be the reading of a file, or
the generation of a function, or anything necessary for the
stream to work after its initialization.
Notes
-----
Every time a stream is created this function has to be called.
"""
raise NotImplementedError

@abstractmethod
def next_sample(self, batch_size=1):
""" Generates or returns next `batch_size` samples in the stream.
Parameters
----------
batch_size: int
How many samples at a time to return.
Returns
-------
tuple or tuple list
A numpy.ndarray of shape (batch_size, n_features) and an array-like of size
n_targets, representing the next batch_size samples.
"""
raise NotImplementedError

def last_sample(self):
""" Retrieves last `batch_size` samples in the stream.
Returns
-------
tuple or tuple list
A numpy.ndarray of shape (batch_size, n_features) and an array-like of shape
(batch_size, n_targets), representing the next batch_size samples.
"""
return self.current_sample_x, self.current_sample_y

def is_restartable(self):
""" Determine if the stream is restartable. """
return True

def restart(self):
""" Restart the stream. """
self.prepare_for_use()

def n_remaining_samples(self):
""" Returns the estimated number of remaining samples.
Returns
-------
int
Remaining number of samples. -1 if infinite (e.g. generator)
"""
return -1

def has_more_samples(self):
return True

@abstractmethod
def get_name(self):
""" get_name
Expand Down

0 comments on commit 4f80388

Please sign in to comment.