niml.model package¶
Subpackages¶
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, boost_frequency=1, decay_cnt_target=None, seed=None, sdr_set_bits=None, boost_strength=0.175, boost_bend_factor=0.25, boost_table_length=128, force_software=False, _clsfr_enabled=True, pooler_regions=None, subclass_thresh=None, unknown_thresh=None, min_overlap=None)¶
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, optional) – A previously stored model state in the form of a file name string
sdr_width (integer) – Represents the full width of SDRs for all features to be processed by the compute method
neurons (int) – Value defining how many columns to use for training the model
active_neurons (int) – Indicates the number of winning columns to use in creating the oSDR signature (must be less than neurons parameter)
input_pct (float) – Used during configuration to force a certain percentage of the synapses in a column to be turned off (set to 0). A lower number will force more synapses to be turned off (must be between 0 and 1 inclusive)
learning (bool) – Informs the model to update synapses with new information(True) or to maintain existing state(False)
synapse_inc (int) – Value added to the synaptic strength value for a synapse that matches the iSDR signature to encourage winning by perpetual losing neurons (only applies when learning is on and must be >= 1)
synapse_dec (int) – Value subtracted from the synaptic strength value for a synapse that did not match the iSDR signature to discourage excessive winning by the same neurons (only applies when learning is on and must be >= 1)
boost_frequency (int) – Indicates the upper and lower bounds when the pooler will trigger a boost table index increment or decrement; this is the outer loop that gets invoked when the decay_cnt_target is reached (only applies when learning is on and must be >= 1)
boost_frequency – Indicates the upper and lower bounds when the pooler will trigger a boost table index increment or decrement; this is the outer loop that gets invoked when the decay_cnt_target is reached (only applies when learning is on and must be >= 1)
decay_cnt_target (int) – Sets the number of iSDRs to process before triggering an adjustment to the outer boost_frequency loop (only applies when learning and must be between 2 and 256 inclusive)
sdr_set_bits (int) – The number of set-bits used in a complete sdr
boost_strength (float) – Determines the highest possible value for boost table entries. 0 < boost_strength <= 1.0. Default value = 0.175
boost_bend_factor (float) – Determines the sharpness of the curve in the boost table. Higher values correspond to tighter curves and a steeper slope of the boost curve. Practical maximum value 0.5. 0 < boost_bend_factor <= 1.0. Default value = 0.175
boost_table_length (int) – 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_table_length <= 256, Default value = 1
seed – Value that ge ts passed to the random initialization function to allow for repeatable output0
force_software (bool, optional) –
- When true, disalows the use of a hardware pooler, even if
available.
- When false, a hardware pooler will be used if available. Defaults
to False.
sdr_width – the largest symbol an SDR might contain+1, typically the number of neurons in the pooler.
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) – A value that 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)
min_overlap (float) – A value that represents 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
Notes
All input parameters are marked as optional; however, either a model_state or all other parameters except ‘force_software’ 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 Requires 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, verbose=False)¶
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 creation
- 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.
verbose (bool, optional) – When True, the beginning of each epoch will be reported to stdout defaults to False.
- 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
- 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) – A string representing a file path where the binary representation of the model state will be written
- Raises
TypeError – Raised if a pathname is not supplied. written to the file