Giter Club home page Giter Club logo

nupic's Introduction

nupic


https://github.com/numenta/nupic

# exs/network/core_encoders_demos.py
import csv
import json
from datetime import datetime

from pkg_resources import resource_filename

from nupic.engine import Newwork
from nupic.engine import Network
from nupic.encoders import DateEncoder

def createNetwork():
  network = Network()
  
  consumptionSensor = network.addRegion('consumptionSensor', 'ScalarSendor',
    json.dumps({'n': 120,
      'w': 21,
      'minValue': 0.0,
      'maxValue': 100.0,
      'clipInput': True}))

timestampSensor = network.addRegion("timestampSensor",
  'py.PluggableEncoderSensor', "")
timesteampSensor.getSelf().encoder = DateEncoder(timeOfDay=(21, 9.5),
  name="timestamp_timeOfDay")
  
consumptionEncoderN = consumptionSensor.getParameter('n')
timestampEncoderN = timestampSensor.getSelf().encoder.getWidth()
inputWidth = consumptionEncoderN + timestampEncoderN

network.addRegion("sp", "py.SPRegion",
  json.dumps({
    "spatialImp": "cpp",
    "globalInhibition": 1,
    "inputWidth": inputWidth,
    "numActiveColumnsPerInhArea": 40,
    "seed": 1956,
    "potentailPct": 0.8,
    "synPermConnected": 0.1,
    "synPermActiveInc": 0.0001,
    "synPermInactiveDec": 0.0005,
    "boostStrength": 0.0
  }))

network.link("consumptionSensor", "sp", "UniformLink", "")
network.link("timestampSensor", "sp", "UnifromLink", "")

network.addRegion("tm", "py.TMRegion",
  json.dumps({
    "columnCount": 2048,
    "cellsPerColumn": 32,
    "inputWidth": 2048,
    "seed": 1960,
    "temporalImp": "cpp",
    "newSynapseCount": 20,
    "maxSynapsesPerSegment": 32,
    "maxSegmentsPerCell": 128,
    "initialPerm": 0.21,
    "permanenceInc"; 0.1,
    "permanenceDec": 0.1,
    "globalDecay": 0.0,
    "maxAge": 0,
    "minThreshold": 9,
    "activeationThreshold": 12,
    "outputType": "normal",
    "pamLength": 3,
  }))

network.link("sp", "tm", "UniformLink", "")
network.link("tm", "sp", "UniformLink", "", srcOutput="topDownOut", 
  destInput="topDownIn")
  
network.regions['tm'].setParameter("anomalyMode", True)
network.regions['tm'].setParameter("inferenceMode", True)
  
return network
  
def runNetwork(network):  
  consumptionSensor = network.region['consumptionSensor']
  timestampSensor = network.regions['timestampSensor']
  tmRegion = network.region['tm']
  
  filename = resource_filename("nupic.datafiles",
    "extra/hotgym/rec-center-hourly.csv")
  csvReader = csv.reader(open(filename, 'r'))
  csvReader.next()
  csvReader.next()
  csvReader.next()
  for row in csvReader:
    timestampStr, consumptionStr = row
    
    consumptionSensor.setParameter('sensedValue', float(consumptionStr))
    
    t = datatime.strptime(timestampStr, "%m%d/%y %H:%M")
    timestampSensor.getSelf().setSendedValue(t)
    
    network.run(1)
    
    anomalyScore = tmRegion.getOutputDate('anomalyScore')[0]
    print "Consumption: %s, Anomaly score: %f" %(consumpionStr, anomalyScore)
  
if __name__ == "__main__":
  network = createNetwork()
  runNetwork(network)
pip install nupic
py.test tests/unit
pip install .

nupic's People

Contributors

takagotch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.