Utilities

Common Models

nupic.frameworks.opf.common_models.cluster_params.getScalarMetricWithTimeOfDayAnomalyParams(metricData, minVal=None, maxVal=None, minResolution=None, tmImplementation='cpp')

Return a dict that can be used to create an anomaly model via OPF’s ModelFactory.

Parameters:
  • metricData – numpy array of metric data. Used to calculate minVal and maxVal if either is unspecified
  • minVal – minimum value of metric. Used to set up encoders. If None will be derived from metricData.
  • maxVal – maximum value of metric. Used to set up input encoders. If None will be derived from metricData
  • minResolution – minimum resolution of metric. Used to set up encoders. If None, will use default value of 0.001.
  • tmImplementation – string specifying type of temporal memory implementation. Valid strings : {“cpp”, “tm_cpp”}
Returns:

a dict containing “modelConfig” and “inferenceArgs” top-level properties. The value of the “modelConfig” property is for passing to the OPF ModelFactory.create() method as the modelConfig parameter. The “inferenceArgs” property is for passing to the resulting model’s enableInference() method as the inferenceArgs parameter. NOTE: the timestamp field corresponds to input “c0”; the predicted field corresponds to input “c1”.

Return type:

dict

Example:

from nupic.frameworks.opf.modelfactory import ModelFactory from nupic.frameworks.opf.common_models.cluster_params import (

getScalarMetricWithTimeOfDayAnomalyParams)
params = getScalarMetricWithTimeOfDayAnomalyParams(
metricData=[0], tmImplementation=”cpp”, minVal=0.0, maxVal=100.0)

model = ModelFactory.create(modelConfig=params[“modelConfig”]) model.enableLearning() model.enableInference(params[“inferenceArgs”])

Helpers

nupic.frameworks.opf.opfhelpers.getExperimentDescriptionInterfaceFromModule(module)

module: imported description.py module

Returns: An expdescriptionapi.DescriptionIface-based instance that
represents the experiment description
nupic.frameworks.opf.opfhelpers.loadExperiment(path)

Loads the experiment description file from the path.

Args:
path: The path to a directory containing a description.py file or the file
itself.
Returns:
(config, control)
nupic.frameworks.opf.opfhelpers.loadExperimentDescriptionScriptFromDir(experimentDir)

Loads the experiment description python script from the given experiment directory.

experimentDir: experiment directory path

Returns: module of the loaded experiment description scripts