当前位置: 首页>>代码示例>>Python>>正文


Python scalar.ScalarEncoder类代码示例

本文整理汇总了Python中nupic.encoders.scalar.ScalarEncoder的典型用法代码示例。如果您正苦于以下问题:Python ScalarEncoder类的具体用法?Python ScalarEncoder怎么用?Python ScalarEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ScalarEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testCloseness

 def testCloseness(self):
   """Test closenessScores for a periodic encoder"""
   encoder = ScalarEncoder(w=7, minval=0, maxval=7, radius=1, periodic=True,
                           name="day of week", forced=True)
   scores = encoder.closenessScores((2, 4, 7), (4, 2, 1), fractional=False)
   for actual, score in itertools.izip((2, 2, 1), scores):
     self.assertEqual(actual, score)
开发者ID:leotam,项目名称:cupic,代码行数:7,代码来源:scalar_test.py

示例2: testScalarEncoder

  def testScalarEncoder(self):
      """Testing ScalarEncoder..."""

      # -------------------------------------------------------------------------
      # test missing values
      mv = ScalarEncoder(name='mv', n=14, w=3, minval=1, maxval=8, periodic=False, forced=True)
      empty = mv.encode(SENTINEL_VALUE_FOR_MISSING_DATA)
      print "\nEncoded missing data \'None\' as %s" % empty
      self.assertEqual(empty.sum(), 0)
开发者ID:AI-Cdrone,项目名称:nupic,代码行数:9,代码来源:scalar_test.py

示例3: testScalarEncoder

  def testScalarEncoder(self):
    """Testing ScalarEncoder..."""

    # -------------------------------------------------------------------------
    # test missing values
    mv = ScalarEncoder(name="mv", n=14, w=3, minval=1, maxval=8,
                       periodic=False, forced=True)
    empty = mv.encode(SENTINEL_VALUE_FOR_MISSING_DATA)
    self.assertEqual(empty.sum(), 0)
开发者ID:leotam,项目名称:cupic,代码行数:9,代码来源:scalar_test.py

示例4: __init__

 def __init__(self):
     self.lat = ScalarEncoder(name='latitude',  w=3, n=100, minval=-90, maxval=90,
                     periodic=False)
     self.long= ScalarEncoder(name='longitude',  w=3, n=100, minval=-180, maxval=180,
                     periodic=True)
     self.timeenc= DateEncoder(season=0, dayOfWeek=1, weekend=3, timeOfDay=5)
     self.likes = ScalarEncoder(name='likes',  w=3, n=50, minval=0, maxval=100000,
                     periodic=False)
     self.people = ScalarEncoder(name='numpeople',  w=3, n=20, minval=0, maxval=100,
                     periodic=False)
     self.categories = SDRCategoryEncoder(n=87, w=3, categoryList = None,
                          name="cats", verbosity=0)
     self.run()
开发者ID:firetix,项目名称:BoringFriends,代码行数:13,代码来源:AnomalyDetector.py

示例5: profileEnc

def profileEnc(maxValue, nRuns):
  minV=0
  maxV=nRuns
  # generate input data
  data=numpy.random.randint(minV, maxV+1, nRuns)
  # instantiate measured encoders
  encScalar = ScalarEncoder(w=21, minval=minV, maxval=maxV, resolution=1)
  encRDSE = RDSE(resolution=1)
  
  # profile!  
  for d in data:
    encScalar.encode(d)
    encRDSE.encode(d)

  print "Scalar n=",encScalar.n," RDSE n=",encRDSE.n
开发者ID:AaronZhangL,项目名称:nupic,代码行数:15,代码来源:enc_profile.py

示例6: testReadWrite

  def testReadWrite(self):
    """Test ScalarEncoder Cap'n Proto serialization implementation."""
    originalValue = self._l.encode(1)

    proto1 = ScalarEncoderProto.new_message()
    self._l.write(proto1)

    # Write the proto to a temp file and read it back into a new proto
    with tempfile.TemporaryFile() as f:
      proto1.write(f)
      f.seek(0)
      proto2 = ScalarEncoderProto.read(f)

    encoder = ScalarEncoder.read(proto2)

    self.assertIsInstance(encoder, ScalarEncoder)
    self.assertEqual(encoder.w, self._l.w)
    self.assertEqual(encoder.minval, self._l.minval)
    self.assertEqual(encoder.maxval, self._l.maxval)
    self.assertEqual(encoder.periodic, self._l.periodic)
    self.assertEqual(encoder.n, self._l.n)
    self.assertEqual(encoder.radius, self._l.radius)
    self.assertEqual(encoder.resolution, self._l.resolution)
    self.assertEqual(encoder.name, self._l.name)
    self.assertEqual(encoder.verbosity, self._l.verbosity)
    self.assertEqual(encoder.clipInput, self._l.clipInput)
    self.assertTrue(numpy.array_equal(encoder.encode(1), originalValue))
    self.assertEqual(self._l.decode(encoder.encode(1)),
                     encoder.decode(self._l.encode(1)))

    # Feed in a new value and ensure the encodings match
    result1 = self._l.encode(7)
    result2 = encoder.encode(7)
    self.assertTrue(numpy.array_equal(result1, result2))
开发者ID:leotam,项目名称:cupic,代码行数:34,代码来源:scalar_test.py

示例7: __init__

  def __init__(self, w, categoryList, name="category", verbosity=0, forced=False):
    self.encoders = None
    self.verbosity = verbosity

    # number of categories includes "unknown"
    self.ncategories = len(categoryList) + 1

    self.categoryToIndex = dict()
    self.indexToCategory = dict()
    self.indexToCategory[0] = UNKNOWN
    for i in xrange(len(categoryList)):
      self.categoryToIndex[categoryList[i]] = i+1
      self.indexToCategory[i+1] = categoryList[i]

    self.encoder = ScalarEncoder(w, minval=0, maxval=self.ncategories - 1,
                      radius=1, periodic=False, forced=forced)
    self.width = w * self.ncategories
    assert self.encoder.getWidth() == self.width

    self.description = [(name, 0)]
    self.name = name

    # These are used to support the topDownCompute method
    self._topDownMappingM = None

    # This gets filled in by getBucketValues
    self._bucketValues = None
开发者ID:alfonsokim,项目名称:nupic,代码行数:27,代码来源:category.py

示例8: __init__

  def __init__(self, w, categoryList, name="category", verbosity=0, forced=False):
    """params:
       forced (default False) : if True, skip checks for parameters' settings; see encoders/scalar.py for details
    """

    self.encoders = None
    self.verbosity = verbosity

    # number of categories includes "unknown"
    self.ncategories = len(categoryList) + 1

    self.categoryToIndex = dict()                                 # check_later: what is the purpose of categoryToIndex and indexToCategory?
    self.indexToCategory = dict()
    self.indexToCategory[0] = UNKNOWN
    for i in xrange(len(categoryList)):
      self.categoryToIndex[categoryList[i]] = i+1
      self.indexToCategory[i+1] = categoryList[i]

    self.encoder = ScalarEncoder(w, minval=0, maxval=self.ncategories - 1,
                      radius=1, periodic=False, forced=forced)
    self.width = w * self.ncategories
    assert self.encoder.getWidth() == self.width

    self.description = [(name, 0)]
    self.name = name

    # These are used to support the topDownCompute method
    self._topDownMappingM = None

    # This gets filled in by getBucketValues
    self._bucketValues = None
开发者ID:trung-duc,项目名称:mac-nupic,代码行数:31,代码来源:category.py

示例9: ScalarBucketEncoder

class ScalarBucketEncoder(Encoder):

  def __init__(self):
    self.encoder = NupicScalarEncoder(w=1, minval=0, maxval=40000, n=22, forced=True)

  def encode(self, symbol):
    encoding = self.encoder.encode(symbol)
    return encoding
开发者ID:andrewmalta13,项目名称:nupic.research,代码行数:8,代码来源:run_lstm_suite.py

示例10: addEncoder

 def addEncoder(encoderAttr, offsetAttr):
   protoVal = getattr(proto, encoderAttr)
   if protoVal.n:
     setattr(encoder, encoderAttr, ScalarEncoder.read(protoVal))
     innerEncoder = getattr(encoder, encoderAttr)
     setattr(encoder, offsetAttr, encoder.width)
     innerOffset = getattr(encoder, offsetAttr)
     encoder.width += innerEncoder.getWidth()
     encoder.description.append((innerEncoder.name, innerOffset))
     encoder.encoders.append((innerEncoder.name, innerEncoder, innerOffset))
   else:
     setattr(encoder, encoderAttr, None)
开发者ID:NunoEdgarGub1,项目名称:nupic,代码行数:12,代码来源:date.py

示例11: __init__

    def __init__(self, filename="simple_pattern2.txt", with_classifier=True, delay=50, animate=True):
        self.b = CHTMBrain(cells_per_region=self.CPR, min_overlap=1, r1_inputs=self.N_INPUTS)
        self.b.initialize()
        self.printer = CHTMPrinter(self.b)
        self.printer.setup()
        self.classifier = None
        self.animate = animate
        self.current_batch_target = 0
        self.current_batch_counter = 0
        self.delay = delay
        if with_classifier:
            self.classifier = CHTMClassifier(self.b, categories=self.ALPHA, region_index=len(self.CPR)-1, history_window=self.CROP_FILE/2)

        if True:
            self.encoder = SimpleFullWidthEncoder(n_inputs=self.N_INPUTS, n_cats=len(self.ALPHA))
        else:
            self.encoder = ScalarEncoder(n=self.N_INPUTS, w=5, minval=1, maxval=self.N_INPUTS, periodic=False, forced=True)

        with open(self.DATA_DIR+"/"+filename, 'r') as myfile:
            self.data = myfile.read()

        self.cursor = 0
开发者ID:onejgordon,项目名称:pphtm,代码行数:22,代码来源:test_chtm.py

示例12: read

 def read(cls, proto):
     encoder = object.__new__(cls)
     encoder.verbosity = proto.verbosity
     encoder.minScaledValue = proto.minScaledValue
     encoder.maxScaledValue = proto.maxScaledValue
     encoder.clipInput = proto.clipInput
     encoder.minval = proto.minval
     encoder.maxval = proto.maxval
     encoder.encoder = ScalarEncoder.read(proto.encoder)
     encoder.name = proto.name
     encoder.width = encoder.encoder.getWidth()
     encoder.description = [(encoder.name, 0)]
     encoder._bucketValues = None
     return encoder
开发者ID:08s011003,项目名称:nupic,代码行数:14,代码来源:logenc.py

示例13: read

  def read(cls, proto):
    encoder = object.__new__(cls)

    encoder.verbosity = proto.verbosity
    encoder.encoder = ScalarEncoder.read(proto.encoder)
    encoder.width = proto.width
    encoder.description = [(proto.name, 0)]
    encoder.name = proto.name
    encoder.indexToCategory = {x.index: x.category
                               for x in proto.indexToCategory}
    encoder.categoryToIndex = {category: index
                               for index, category
                               in encoder.indexToCategory.items()
                               if category != UNKNOWN}
    encoder._topDownMappingM = None
    encoder._bucketValues = None

    return encoder
开发者ID:NunoEdgarGub1,项目名称:nupic,代码行数:18,代码来源:category.py

示例14: __init__

  def __init__(self):
    self.encoder = CoordinateEncoder(n=1024,
                                w=21)
    self.motorEncoder = ScalarEncoder(21, -1, 1,
                                 n=1024)
    self.tm = MonitoredExtendedTemporalMemory(
      columnDimensions=[2048],
      cellsPerColumn=1,
      initialPermanence=0.5,
      connectedPermanence=0.6,
      permanenceIncrement=0.1,
      permanenceDecrement=0.02,
      minThreshold=35,
      activationThreshold=35,
      maxNewSynapseCount=40)
    self.plotter = Plotter(self.tm, showOverlaps=False, showOverlapsValues=False)

    self.lastState = None
    self.lastAction = None
开发者ID:andrewmalta13,项目名称:nupic.research,代码行数:19,代码来源:run_sm.py

示例15: __init__

 def __init__(self, n, w, rate, chunk, minval=20, maxval=20000, name=None):
   """
   @param n int the length of the encoded SDR
   @param w int the number of 1s in the encoded SDR
   @param rate int the number of sound samples per second
   @param chunk int the number of samples in an input
   @param minval float the lowest possible frequency detected
   @param maxval float the highest possible frequency detected
   @param name string the name of the encoder
   """
   self.n = n
   self.w = w
   self.rate = rate
   self.chunk  = chunk
   self.minval = minval
   self.maxval = maxval
   self.name = name
   self._scalarEncoder = ScalarEncoder(name="scalar_"+str(name), n=n, w=w,
                                       minval=minval, maxval=maxval)
开发者ID:Starcounter-Jack,项目名称:nupic.research,代码行数:19,代码来源:sound_encoder.py


注:本文中的nupic.encoders.scalar.ScalarEncoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。