def POST(self):
        global spFacades
        params = json.loads(web.data())
        requestInput = web.input()
        # We will always return the initial state of columns and overlaps because
        # they are cheap.
        returnSnapshots = [SNAPS.ACT_COL, SNAPS.OVERLAPS]
        saveSnapshots = []
        if __name__ == '__main__':
            if "save" in requestInput and len(requestInput["save"]) > 0:
                saveSnapshots += [
                    str(s) for s in requestInput["save"].split(",")
                ]
                # Be sure to also return any snapshots that were specified to be saved.
                returnSnapshots += saveSnapshots
                # Remove potential duplicates from both
                returnSnapshots = list(set(returnSnapshots))
                saveSnapshots = list(set(saveSnapshots))

        sp = SP(**params)
        spFacade = spHistory.create(sp, save=saveSnapshots)
        spId = spFacade.getId()
        spFacades[spId] = spFacade

        print "Created SP {} | Saving: {}".format(spId, saveSnapshots)

        payload = {"meta": {"id": spId, "saving": returnSnapshots}}
        spState = spFacade.getState(*returnSnapshots)
        for key in spState:
            payload[key] = spState[key]

        web.header("Content-Type", "application/json")
        return json.dumps(payload)
    def _initSpatialPooler(self):

        print "Creating spatial pooler .."

        spatialPooler = SP(
            self.inputSize,
            self.columnDimensions,
            numActiveColumnsPerInhArea=int(0.02 * self.columnNumber),
            globalInhibition=True,
            synPermActiveInc=0.01,
            potentialPct=
            1,  # Essential parameter: Neurons can connect to 100% of input
            potentialRadius=self.inputSize
            # stimulusThreshold = 0,
            # synPermInactiveDec = 0.01,
            # synPermActiveInc = 0.1,
            # synPermConnected = 0.1, # Connected threshold
            # maxBoost = 3
        )
        return spatialPooler
示例#3
0
  def __init__(self, inputDimensions, columnDimensions):
    """
     Parameters:
     ----------
     _inputDimensions: The size of the input. (m,n) will give a size m x n
     _columnDimensions: The size of the 2 dimensional array of columns
     """
    self.inputDimensions = inputDimensions
    self.columnDimensions = columnDimensions
    self.inputSize = np.array(inputDimensions).prod()
    self.columnNumber = np.array(columnDimensions).prod()
    self.inputArray = np.zeros(self.inputSize)
    self.activeArray = np.zeros(self.columnNumber)

    self.sp = SP(self.inputDimensions,
                 self.columnDimensions,
                 potentialRadius = self.inputSize,
                 numActiveColumnsPerInhArea = int(0.02*self.columnNumber),
                 globalInhibition = True,
                 synPermActiveInc = 0.01)
示例#4
0
    def __init__(self, inputShape, columnDimensions):
        """
     Parameters:
     ----------
     _inputShape	:	The size of the input. The product of the first and second elements of this parameter determines the size of the input vectors
     _columnDimensions:	The size of the 2 dimensional array of columns
     """
        self.inputShape = inputShape
        self.columnDimensions = columnDimensions
        self.inputSize = np.array(inputShape).prod()
        self.columnNumber = np.array(columnDimensions).prod()
        self.inputArray = np.zeros(self.inputSize)
        self.activeArray = np.zeros(self.columnNumber)

        self.sp = SP(self.inputShape,
                     self.columnDimensions,
                     potentialRadius=self.inputSize,
                     numActiveColumnsPerInhArea=int(0.02 * self.columnNumber),
                     globalInhibition=True,
                     synPermActiveInc=0.01)
示例#5
0
def createSpatialPooler(inputSize):
  return SP(
    inputDimensions=(inputSize,),
    columnDimensions=(200,),
    potentialRadius=16,
    potentialPct=0.85,
    globalInhibition=True,
    localAreaDensity=-1.0,
    numActiveColumnsPerInhArea=40.0,
    stimulusThreshold=1,
    synPermInactiveDec=0.008,
    synPermActiveInc=0.05,
    synPermConnected=0.10,
    minPctOverlapDutyCycle=0.001,
    minPctActiveDutyCycle=0.001,
    dutyCyclePeriod=1000,
    maxBoost=2.0,
    seed=-1,
    spVerbosity=0,
    wrapAround=True
  )
示例#6
0
def runSaveTest():
    inputSize = 600
    outputSize = 2048

    sp = SP(inputDimensions=(inputSize, ),
            columnDimensions=(outputSize, ),
            potentialRadius=16,
            potentialPct=0.85,
            globalInhibition=True,
            localAreaDensity=-1.0,
            numActiveColumnsPerInhArea=40.0,
            stimulusThreshold=1,
            synPermInactiveDec=0.008,
            synPermActiveInc=0.05,
            synPermConnected=0.10,
            minPctOverlapDutyCycle=0.001,
            minPctActiveDutyCycle=0.001,
            dutyCyclePeriod=1000,
            maxBoost=2.0,
            seed=-1,
            spVerbosity=0,
            wrapAround=True)
    # Totally nukes any SP History data that exists in Redis.
    spHistory.nuke()
    # Create a facade around the SP that saves history as it runs.
    sp = spHistory.create(sp)
    # If the SP Facade is "active" that means it has a life spatial pooler. If it
    # is not active, it cannot compute, only playback the history.
    assert sp.isActive()
    for _ in range(0, 10):
        encoding = np.zeros(shape=(inputSize, ))
        for j, _ in enumerate(encoding):
            if random() < 0.1:
                encoding[j] = 1
        # For each compute cycle, save the SP state to Redis for playback later.
        sp.compute(encoding, learn=True, save=True)
    # This SP's history can be retrieved with an id.
    return sp.getId()
示例#7
0
    minThreshold=8,
    maxNewSynapseCount=20,
    permanenceIncrement=0.1,
    permanenceDecrement=0.0,
    activationThreshold=8,
)

sp = SP(inputDimensions=(2325, ),
        columnDimensions=(2048, ),
        potentialRadius=16,
        potentialPct=0.5,
        globalInhibition=True,
        localAreaDensity=-1.0,
        numActiveColumnsPerInhArea=10.0,
        stimulusThreshold=0,
        synPermInactiveDec=0.008,
        synPermActiveInc=0.05,
        synPermConnected=0.10,
        minPctOverlapDutyCycle=0.001,
        dutyCyclePeriod=1000,
        maxBoost=20.0,
        seed=-1,
        spVerbosity=0,
        wrapAround=True)

sdr = SDR(steps=(3, ), alpha=0.001, actValueAlpha=0.3, verbosity=0)


def createEncoder():
    volume_encoder = ScalarEncoder(21,
                                   0.0,
示例#8
0
uintType = "uint32"
inputDimensions = (1000,1)
columnDimensions = (2048,1)
inputSize = np.array(inputDimensions).prod()
columnNumber = np.array(columnDimensions).prod()
inputArray = np.zeros(inputSize, dtype=uintType)

for i in range(inputSize):
  inputArray[i] = random.randrange(2)
  
activeCols = np.zeros(columnNumber, dtype=uintType)
sp = SP(inputDimensions, 
  columnDimensions, 
  potentialRadius = int(0.5*inputSize),
  numActiveColumnsPerInhArea = int(0.02*columnNumber),
  globalInhibition = True,
  seed = 1,
  synPermActiveInc = 0.01,
  synPermInactiveDec = 0.008
   )

# Part 1: 
# -------
# A column connects to a subset of the input vector (specified
# by both the potentialRadius and potentialPct). The overlap score
# for a column is the number of connections to the input that become
# active when presented with a vector. When learning is 'on' in the SP,
# the active connections are reinforced, whereas those inactive are
# depressed (according to parameters synPermActiveInc and synPermInactiveDec.
# In order for the SP to create a sparse representation of the input, it
# will select a small percentage (usually 2%) of its most active columns,