本文整理汇总了Python中nupic.support.configuration.Configuration类的典型用法代码示例。如果您正苦于以下问题:Python Configuration类的具体用法?Python Configuration怎么用?Python Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newPosition
def newPosition(self, globalBestPosition, rng):
"""See comments in base class."""
# First, update the velocity. The new velocity is given as:
# v = (inertia * v) + (cogRate * r1 * (localBest-pos))
# + (socRate * r2 * (globalBest-pos))
#
# where r1 and r2 are random numbers between 0 and 1.0
lb=float(Configuration.get("nupic.hypersearch.randomLowerBound"))
ub=float(Configuration.get("nupic.hypersearch.randomUpperBound"))
self._velocity = (self._velocity * self._inertia + rng.uniform(lb, ub) *
self._cogRate * (self._bestPosition - self.getPosition()))
if globalBestPosition is not None:
self._velocity += rng.uniform(lb, ub) * self._socRate * (
globalBestPosition - self.getPosition())
# update position based on velocity
self._position += self._velocity
# Clip it
self._position = max(self.min, self._position)
self._position = min(self.max, self._position)
# Return it
return self.getPosition()
示例2: __init__
def __init__(self, clamodel, anomalyParams=None):
if anomalyParams is None:
anomalyParams = {}
if anomalyParams is None:
anomalyParams = {}
self.clamodel = clamodel
self._version = CLAModelClassifierHelper.__VERSION__
self._classificationMaxDist = 0.1
if 'autoDetectWaitRecords' not in anomalyParams or \
anomalyParams['autoDetectWaitRecords'] is None:
self._autoDetectWaitRecords = int(Configuration.get(
'nupic.model.temporalAnomaly.wait_records'))
else:
self._autoDetectWaitRecords = anomalyParams['autoDetectWaitRecords']
if 'autoDetectThreshold' not in anomalyParams or \
anomalyParams['autoDetectThreshold'] is None:
self._autoDetectThreshold = float(Configuration.get(
'nupic.model.temporalAnomaly.auto_detect_threshold'))
else:
self._autoDetectThreshold = anomalyParams['autoDetectThreshold']
if 'anomalyCacheRecords' not in anomalyParams or \
anomalyParams['anomalyCacheRecords'] is None:
self._history_length = int(Configuration.get(
'nupic.model.temporalAnomaly.window_length'))
else:
self._history_length = anomalyParams['anomalyCacheRecords']
if 'anomalyVectorType' not in anomalyParams or \
anomalyParams['anomalyVectorType'] is None:
self._vectorType = str(Configuration.get(
'nupic.model.temporalAnomaly.anomaly_vector'))
else:
self._vectorType = anomalyParams['anomalyVectorType']
self._activeColumnCount = \
self.clamodel._getSPRegion().getSelf().getParameter('numActiveColumnsPerInhArea')
# Storage for last run
self._anomalyVectorLength = None
self._classificationVector = numpy.array([])
self._prevPredictedColumns = numpy.array([])
self._prevTPCells = numpy.array([])
# Array of CLAClassificationRecord's used to recompute and get history
self.saved_states = []
self.saved_categories = []
示例3: _getCommonSteadyDBArgsDict
def _getCommonSteadyDBArgsDict():
""" Returns a dictionary of arguments for DBUtils.SteadyDB.SteadyDBConnection
constructor.
"""
return dict(
creator = pymysql,
host = Configuration.get('nupic.cluster.database.host'),
port = int(Configuration.get('nupic.cluster.database.port')),
user = Configuration.get('nupic.cluster.database.user'),
passwd = Configuration.get('nupic.cluster.database.passwd'),
charset = 'utf8',
use_unicode = True,
setsession = ['SET AUTOCOMMIT = 1'])
示例4: __setstate__
def __setstate__(self, state):
version = 1
if "_version" in state:
version = state["_version"]
# Migrate from version 1 to version 2
if version == 1:
self._vectorType = str(Configuration.get(
'nupic.model.temporalAnomaly.anomaly_vector'))
self._autoDetectWaitRecords = state['_classificationDelay']
elif version == 2:
self._autoDetectWaitRecords = state['_classificationDelay']
elif version == 3:
pass
else:
raise Exception("Error while deserializing %s: Invalid version %s"
%(self.__class__, version))
if '_autoDetectThreshold' not in state:
self._autoDetectThreshold = 1.1
for attr, value in state.iteritems():
setattr(self, attr, value)
self._version = CLAModelClassifierHelper.__VERSION__
示例5: __init__
def __init__(self, steps="1", alpha=0.001, verbosity=0, implementation=None, maxCategoryCount=None):
# Set default implementation
if implementation is None:
implementation = Configuration.get("nupic.opf.claClassifier.implementation")
# Convert the steps designation to a list
self.classifierImp = implementation
self.steps = steps
self.stepsList = eval("[%s]" % (steps))
self.alpha = alpha
self.verbosity = verbosity
# Initialize internal structures
self._claClassifier = CLAClassifierFactory.create(
steps=self.stepsList, alpha=self.alpha, verbosity=self.verbosity, implementation=implementation
)
self.learningMode = True
self.inferenceMode = False
self.maxCategoryCount = maxCategoryCount
self.recordNum = 0
self._initEphemerals()
# Flag to know if the compute() function is ever called. This is to
# prevent backward compatibilities issues with the customCompute() method
# being called at the same time as the compute() method. Only compute()
# should be called via network.run(). This flag will be removed once we
# get to cleaning up the clamodel.py file.
self._computeFlag = False
示例6: __init__
def __init__(self, steps="1", alpha=0.001, clVerbosity=0, implementation=None, maxCategoryCount=None):
# Set default implementation
if implementation is None:
implementation = Configuration.get("nupic.opf.sdrClassifier.implementation")
self.implementation = implementation
# Convert the steps designation to a list
self.steps = steps
self.stepsList = [int(i) for i in steps.split(",")]
self.alpha = alpha
self.verbosity = clVerbosity
# Initialize internal structures
self._sdrClassifier = None
self.learningMode = True
self.inferenceMode = False
self.maxCategoryCount = maxCategoryCount
self.recordNum = 0
# Flag to know if the compute() function is ever called. This is to
# prevent backward compatibilities issues with the customCompute() method
# being called at the same time as the compute() method. Only compute()
# should be called via network.run(). This flag will be removed once we
# get to cleaning up the clamodel.py file.
self._computeFlag = False
示例7: dbValidator
def dbValidator():
"""
Let the user know what NuPIC config file is being used
and whether or not they have mysql set up correctly for
swarming.
"""
fileused = getFileUsed()
# Get the values we need from NuPIC's configuration
host = Configuration.get("nupic.cluster.database.host")
port = int(Configuration.get("nupic.cluster.database.port"))
user = Configuration.get("nupic.cluster.database.user")
passwd = "*" * len(Configuration.get("nupic.cluster.database.passwd"))
print "This script will validate that your MySQL is setup correctly for "
print "NuPIC. MySQL is required for NuPIC swarming. The settings are"
print "defined in a configuration file found in "
print "$NUPIC/src/nupic/support/nupic-default.xml Out of the box those "
print "settings contain MySQL's default access credentials."
print
print "The nupic-default.xml can be duplicated to define user specific "
print "changes calling the copied file "
print "$NUPIC/src/nupic/support/nupic-site.xml Refer to the "
print "nupic-default.xml for additional instructions."
print
print "Defaults: localhost, 3306, root, no password"
print
print "Retrieved the following NuPIC configuration using: ", fileused
print " host : ", host
print " port : ", port
print " user : ", user
print " passwd : ", passwd
if testDbConnection(host, port, user, passwd):
print "Connection successful!!"
else:
print ("Couldn't connect to the database or you don't have the "
"permissions required to create databases and tables. "
"Please ensure you have MySQL\n installed, running, "
"accessible using the NuPIC configuration settings, "
"and the user specified has permission to create both "
"databases and tables.")
示例8: create
def create(*args, **kwargs):
impl = kwargs.pop("implementation", None)
if impl is None:
impl = Configuration.get("nupic.opf.claClassifier.implementation")
if impl == "py":
return SequenceClassifier(*args, **kwargs)
elif impl == "cpp":
raise ValueError("cpp version not yet implemented")
else:
raise ValueError("Invalid classifier implementation (%r). Value must be " '"py" or "cpp".' % impl)
示例9: create
def create(*args, **kwargs):
impl = kwargs.pop('implementation', None)
if impl is None:
impl = Configuration.get('nupic.opf.claClassifier.implementation')
if impl == 'py':
return SequenceClassifier(*args, **kwargs)
elif impl == 'cpp':
raise ValueError('cpp version not yet implemented')
else:
raise ValueError('Invalid classifier implementation (%r). Value must be '
'"py" or "cpp".' % impl)
示例10: __init__
def __init__(self, min, max, stepSize=None, inertia=None, cogRate=None,
socRate=None):
"""Construct a variable that permutes over floating point values using
the Particle Swarm Optimization (PSO) algorithm. See descriptions of
PSO (i.e. http://en.wikipedia.org/wiki/Particle_swarm_optimization)
for references to the inertia, cogRate, and socRate parameters.
Parameters:
-----------------------------------------------------------------------
min: min allowed value of position
max: max allowed value of position
stepSize: if not None, the position must be at min + N * stepSize,
where N is an integer
inertia: The inertia for the particle.
cogRate: This parameter controls how much the particle is affected
by its distance from it's local best position
socRate: This parameter controls how much the particle is affected
by its distance from the global best position
"""
super(PermuteFloat, self).__init__()
self.min = min
self.max = max
self.stepSize = stepSize
# The particle's initial position and velocity.
self._position = (self.max + self.min) / 2.0
self._velocity = (self.max - self.min) / 5.0
# The inertia, cognitive, and social components of the particle
self._inertia = (float(Configuration.get("nupic.hypersearch.inertia"))
if inertia is None else inertia)
self._cogRate = (float(Configuration.get("nupic.hypersearch.cogRate"))
if cogRate is None else cogRate)
self._socRate = (float(Configuration.get("nupic.hypersearch.socRate"))
if socRate is None else socRate)
# The particle's local best position and the best global position.
self._bestPosition = self.getPosition()
self._bestResult = None
示例11: create
def create(*args, **kwargs):
impl = kwargs.pop('implementation', None)
if impl is None:
impl = Configuration.get('nupic.opf.claClassifier.implementation')
if impl == 'py':
return CLAClassifier(*args, **kwargs)
elif impl == 'cpp':
return FastCLAClassifier(*args, **kwargs)
elif impl == 'diff':
return CLAClassifierDiff(*args, **kwargs)
else:
raise ValueError('Invalid classifier implementation (%r). Value must be '
'"py" or "cpp".' % impl)
示例12: getFileUsed
def getFileUsed():
"""
Determine which NuPIC configuration file is being used and returns the
name of the configuration file it is using. Either DEFAULT_CONFIG or
USER_CONFIG.
"""
# output will be {} if the file passed into Configuration._readConfigFile
# can not be found in the standard paths returned by
# Configuration._getConfigPaths.
output = Configuration._readConfigFile(USER_CONFIG) #pylint: disable=protected-access
if output != {}:
return USER_CONFIG
return DEFAULT_CONFIG
示例13: createAndStartSwarm
def createAndStartSwarm(client, clientInfo="", clientKey="", params="",
minimumWorkers=None, maximumWorkers=None,
alreadyRunning=False):
"""Create and start a swarm job.
Args:
client - A string identifying the calling client. There is a small limit
for the length of the value. See ClientJobsDAO.CLIENT_MAX_LEN.
clientInfo - JSON encoded dict of client specific information.
clientKey - Foreign key. Limited in length, see ClientJobsDAO._initTables.
params - JSON encoded dict of the parameters for the job. This can be
fetched out of the database by the worker processes based on the jobID.
minimumWorkers - The minimum workers to allocate to the swarm. Set to None
to use the default.
maximumWorkers - The maximum workers to allocate to the swarm. Set to None
to use the swarm default. Set to 0 to use the maximum scheduler value.
alreadyRunning - Insert a job record for an already running process. Used
for testing.
"""
if minimumWorkers is None:
minimumWorkers = Configuration.getInt(
"nupic.hypersearch.minWorkersPerSwarm")
if maximumWorkers is None:
maximumWorkers = Configuration.getInt(
"nupic.hypersearch.maxWorkersPerSwarm")
return ClientJobsDAO.get().jobInsert(
client=client,
cmdLine="$HYPERSEARCH",
clientInfo=clientInfo,
clientKey=clientKey,
alreadyRunning=alreadyRunning,
params=params,
minimumWorkers=minimumWorkers,
maximumWorkers=maximumWorkers,
jobType=ClientJobsDAO.JOB_TYPE_HS)
示例14: create
def create(*args, **kwargs):
"""
Create a SDR classifier factory.
The implementation of the SDR Classifier can be specified with
the "implementation" keyword argument.
The SDRClassifierFactory uses the implementation as specified in
src/nupic/support/nupic-default.xml
"""
impl = kwargs.pop("implementation", None)
if impl is None:
impl = Configuration.get("nupic.opf.sdrClassifier.implementation")
if impl == "py":
return SDRClassifier(*args, **kwargs)
else:
raise ValueError("Invalid classifier implementation (%r). Value must be " '"py".' % impl)
示例15: create
def create(*args, **kwargs):
"""
Create a SDR classifier factory.
The implementation of the SDR Classifier can be specified with
the "implementation" keyword argument.
The SDRClassifierFactory uses the implementation as specified in
`Default NuPIC Configuration <default-config.html>`_.
"""
impl = kwargs.pop('implementation', None)
if impl is None:
impl = Configuration.get('nupic.opf.sdrClassifier.implementation')
if impl == 'py':
return SDRClassifier(*args, **kwargs)
elif impl == 'cpp':
return FastSDRClassifier(*args, **kwargs)
else:
raise ValueError('Invalid classifier implementation (%r). Value must be '
'"py" or "cpp".' % impl)