niml.model package¶
Submodules¶
niml.model.model module¶
- class niml.model.model.Model(model_state=None, sdr_width=None, neurons=None, active_neurons=None, input_pct=None, learning=True, synapse_inc=None, synapse_dec=None, activity_reset_cnt=1, decay_cnt_target=None, seed=None, subclass_thresh=None, unknown_thresh=None, history_depth=None, min_overlap=None, enc_set_bits=None, feat_count=None, boost_max=None, boost_str=None, boost_tbl_size=None, boost_tbl_step=None, _clsfr_enabled=True)¶
Provides common access using familiar method names for performing fit, evaluate, and predict operations on iSDR data. The model class will not perform these operations directly, but will pass the data to the requisite functions in the pooler and classifier
- Parameters
model_state (basestring or file-like object, optional) – A previously configured model state in the form of a file name string or python file handle
sdr_width (int, optional) – Indicates the full width of the input SDRs that will be submitted to the fit, evaluate, or predict methods
neurons (int, optional) – Indicates how many neurons to use for training the model
active_neurons (int, optional) – Indicates the number of neurons to use as the best representation of a class of data
input_pct (float, optional) – Indicates the percentage of iSDR bit width mapped to each neuron by a synapse.
learning (bool, optional) – Indicates to the model whether to update synapses and signatures with new information or maintain existing state and just evaluate/classify input SDR data
synapse_inc (int, optional) – Amount to strengthen a synapse to a winning neuron when the corresponding iSDR location is true. (only applies when learning is on)
synapse_dec (int, optional) – Amount to weaken a synapse to a winning neuron when the corresponding iSDR location is false. (only applies when learning is on)
activity_reset_cnt (int, optional) – Indicates to the model when to reset the strength by which the model encourage/discourages neurons that are losing or winning too frequently (affects boosting and only applies when learning is on)
decay_cnt_target (int) – Sets the number of iSDRs to process before triggering an adjustment to the outer activity_reset_cnt loop (only applies when learning and must be between 2 and 256 inclusive)
seed (int, optional) – Passed to the random initialization function to allow for repeatable output
subclass_thresh (float) – A value that directs the model when to create a new subclass during fit. Anything below the threshold will cause the creation of a new subclass
unknown_thresh (float, optional) – Indicates when the model needs to create a new subclass during continuous learning. Anything below the threshold will cause the creation of a new subclass (only applies when learning is on)
history_depth (int, optional) – Indicates the number of class signatures for the model to retain for determining class association
min_overlap (float, optional) – Indicates the minimum percentage of overlap between an output SDR and subclass signature to determine if the item represented by the output SDR should be considered a member of the subclass
enc_set_bits (int, optional) – The number of set-bits used per-feature during the encoding process. Should be the same value as provided to the encoder as the set_bits parameter
feat_count (int, optional) – The number of features present in the observation data, usually represented by the number of columns in a dataset minus the label column if labels are present
boost_max (int, optional) –
Maximum boost value to be allowed in the boost table as a percentage of total SDR set bits across all features:
max_boost_value = enc_set_bits * feature_count * boost_max
boost_str (int, optional) – Determines the x-intercept of the boost curve. a higher value will result in a higher x-intercept and lower will intercept lower
boost_tbl_size (int, optional) –
Sets the total number of boost table steps. A higher value will result in a more gradual boosting profile and a lower number will cause boosting to change more rapidly:
1 < boost_tbl_size <= 256
boost_tbl_step (int, optional) –
Determines the distance along the boost curve between each value of the boost table:
0.1 <= boost_tbl_size <= 1.0
Notes
All input parameters are marked as optional; however, either a model_state or all other parameters, except seed, are required
- evaluate(encoder_state=None, labels=None, isdrs=None)¶
Provides measurement of the performance of the pooler/classifier by making predictions for the given observations, then generating statistics based on the predictions verses the ground-truth labels Requies either and encoder state or labels and isdrs
- Parameters
encoder_state (dict, optional) – a state dictionary from the encoder
labels (list, optional) – ground-truth labels for iSDRs
isdrs (list of lists, optional) – encoded iSDRs
- Returns
accuracy_results – contains results of f1 score, accuracy score, and confusion matrix calculations
- Return type
dict
- Raises
AttributeError – Raised if an error occurs while parsing the input parameters
Notes
All input parameters are marked as optional; however, either an encoder_state or list of labels and a list of isdrs is required, all parameters cannot be empty or None
- fit(encoder_state=None, labels=None, isdrs=None, epochs=1, batch_size=1)¶
Given an encoder state or lists of labels and iSDRs, it will train the pooler by sending the iSDRs through the pooler for the requested number of epochs. It will then send the oSDRs generated from the final epoch to the classifier for signature createion
- Parameters
encoder_state (dict, optional) – a state dictionary from the encoder
labels (list, optional) – ground-truth labels for iSDRs
isdrs (list of lists, optional) – encoded iSDRs
epochs (int, optional) – number of iterations the data should be processed through the pooler
batch_size (int, optional) – number SDRs to process between updates of boost factor and synaptic connection status.
- Returns
signatures – Representation of the neurons that uniquely identify each label and sub-classification
- Return type
dict of sets
- Raises
AttributeError – Raised if an error occurs while parsing the input parameters
Notes
All input parameters are marked as optional; however, either an encoder_state or list of labels and a list of isdrs is required, all parameters except epochs cannot be empty or None
- get_subclass_predictions()¶
Convenience method for accessing full predictions with subclass
- Returns
predictions – Ordered list of (label, subclass index)
- Return type
list of tuples
- load_model(load_file)¶
Loads the current model state from load_file, which can be either a filename or a file-like object
- Parameters
load_file (basestring or file-like object) – Either a string representing a file path or a file-like object where the json representation of the model state will loaded from
- Raises
IOError – Raised if an error occurs and the json text cannot be read from the file
- predict(encoder_state=None, isdrs=None)¶
Evaluates oSDR data against known class / subclass signatures and assigns the observation data row to the best matching signature if the match exceeds the subclass_thresh
- Parameters
encoder_state (basestring or file-like object, optional) – Either a string representing a file path or a file-like object where the json representation of the encoder state can be loaded from
isdrs (list of lists, optional) – List of encoded observation data
- Returns
predictions – List of class labels for each observation data row
- Return type
list
- Raises
AttributeError – Raised if an error occurs while parsing the input parameters
Notes
Both input parameters are marked as optional; however, either an encoder_state or list of isdrs is required, both parameters cannot be empty or None
- reset_classifications()¶
Allows a user to clear the classifier signatures while retaining all the configuration parameters
- save_model(output_file, indent=None)¶
Saves the current model state, which is simply the pooler state combined with the classifier state
- Parameters
output_file (basestring or file-like object) – Either a string representing a file path or a file-like object where the json representation of the model state will be written
- Raises
IOError – Raised if an error occurs and the json text cannot be written to the file