Ejemplo n.º 1
0
 def testCompute(self):
     """ Check that there are no errors in call to compute. """
     inputs = SDR(100).randomize(.05)
     active = SDR(100)
     sp = SP(inputs.dimensions, active.dimensions, stimulusThreshold=1)
     sp.compute(inputs, True, active)
     assert (active.getSum() > 0)
Ejemplo n.º 2
0
def createSpatialPooler():
    sparsity = 0.02
    numColumns = 2048
    sparseCols = int(numColumns * sparsity)

    sp = SP(inputDimensions=(inputSize, ),
            columnDimensions=(numColumns, ),
            potentialRadius=int(0.5 * inputSize),
            numActiveColumnsPerInhArea=sparseCols,
            globalInhibition=True,
            synPermActiveInc=0.0001,
            synPermInactiveDec=0.0005,
            synPermConnected=0.5,
            maxBoost=1.0,
            spVerbosity=1)
    return sp
Ejemplo n.º 3
0
  def POST(self):
    """
    Creates a new Spatial Pooler with a unique ID.

    No URL params expected.

    POST params:

    states: (string array):  List of the SP states you want back. Active columns
                             are always sent. Otherwise, you can find a list of
                             available states in snapshots.py.

    :return: requested state from the sp instance in JSON, keyed by strings in
             POST "states" param.
    """
    global modelCache
    requestPayload = json.loads(web.data())
    params = requestPayload["params"]
    states = requestPayload["states"]
    save = requestPayload["save"]

    from pprint import pprint; pprint(params)
    sp = SpFacade(SP(**params), ioClient)

    modelId = sp.getId()

    payload = {
      "id": modelId,
      "iteration": -1,
      "state": {}
    }
    payload["state"] = sp.getState(*states)

    if save:
      print "\tSaving SP {} to disk...".format(modelId)
      sp.save()

    print "\tSaving SP {} to memory...".format(modelId)
    modelCache[modelId] = {
      "sp": sp,
      "save": save,
    }

    web.header("Content-Type", "application/json")
    return json.dumps(payload)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    def __init__(self, fp_length):
        """
		 Parameters:
		 ----------
		 fp_length	:	The length of a fingerprint.
		 """
        self.fp_length = fp_length
        self.num_columns = 2048
        self.input_array = np.zeros(self.fp_length, dtype="int32")
        self.active_array = np.zeros(self.num_columns, dtype="int32")
        self.lemma_to_sdr = dict()

        self.sp = SP(
            (self.fp_length, 1),
            (self.num_columns, 1),
            potentialRadius=512,
            numActiveColumnsPerInhArea=int(0.02 * self.num_columns),
            globalInhibition=True,
            synPermActiveInc=0.0,  # default 0.01
            synPermInactiveDec=0.0,  # default 0.01
            spVerbosity=1,
            maxBoost=1.0,  # down from 10
            potentialPct=0.8  # up from .5
        )