Exemple #1
0
    def __init__(self, sp_trainer):
        """
		Parameters:
		----------
		sp_trainer	:	The spatial pooler trainer
		"""
        self.sp_trainer = sp_trainer
        self.input_array = np.zeros(self.sp_trainer.fp_length, dtype="int32")
        self.active_array = np.zeros(self.sp_trainer.num_columns,
                                     dtype="int32")
        self.is_learning = True
        self.compute_inference = False

        self.tp = TP(numberOfCols=self.sp_trainer.num_columns,
                     cellsPerColumn=2,
                     initialPerm=0.5,
                     connectedPerm=0.5,
                     minThreshold=10,
                     newSynapseCount=10,
                     permanenceInc=0.1,
                     permanenceDec=0.0,
                     activationThreshold=5,
                     globalDecay=0,
                     burnIn=1,
                     checkSynapseConsistency=False,
                     pamLength=10)
Exemple #2
0
    def __init__(self,
                 numberOfCols=16384,
                 cellsPerColumn=8,
                 initialPerm=0.5,
                 connectedPerm=0.5,
                 minThreshold=164,
                 newSynapseCount=164,
                 permanenceInc=0.1,
                 permanenceDec=0.0,
                 activationThreshold=164,
                 pamLength=10,
                 checkpointDir=None):

        self.tp = TP(
            numberOfCols=numberOfCols,
            cellsPerColumn=cellsPerColumn,
            initialPerm=initialPerm,
            connectedPerm=connectedPerm,
            minThreshold=minThreshold,
            newSynapseCount=newSynapseCount,
            permanenceInc=permanenceInc,
            permanenceDec=permanenceDec,

            # 1/2 of the on bits = (16384 * .02) / 2
            activationThreshold=activationThreshold,
            globalDecay=0,
            burnIn=1,
            checkSynapseConsistency=False,
            pamLength=pamLength)

        self.checkpointDir = checkpointDir
        self.checkpointPath = None
        self._initCheckpoint()
def run():
    tp = TP(numberOfCols=121,
            cellsPerColumn=4,
            initialPerm=0.5,
            connectedPerm=0.5,
            minThreshold=11,
            newSynapseCount=11,
            permanenceInc=0.1,
            permanenceDec=0.05,
            activationThreshold=2,
            globalDecay=0,
            burnIn=1,
            checkSynapseConsistency=False,
            pamLength=3)
    Patcher().patchTP(tp)

    inputArray = numpy.zeros(tp.numberOfCols, dtype='int32')

    for i in range(100):
        generateInput(inputArray)
        tp.compute(inputArray, enableLearn=True, computeInfOutput=True)
        print "Ran iteration:\t{0}".format(i)
Exemple #4
0
    def __init__(self):
        """
    Instantiate temporal pooler, encoder, audio sampler, filter, & freq plot
    """
        self.vis = Visualizations()
        """
    The number of columns in the input and therefore the TP
     2**9 = 512
     Trial and error pulled that out
     numCols should be tested during benchmarking
    """
        self.numCols = 2**9
        sparsity = 0.10
        self.numInput = int(self.numCols * sparsity)
        """
    Create a bit map encoder
    
    From the encoder's __init__ method:
     1st arg: the total bits in input
     2nd arg: the number of bits used to encode each input bit
    """
        self.e = SparsePassThroughEncoder(self.numCols, 1)
        """
    Sampling details
     rate: The sampling rate in Hz of my soundcard
     buffersize: The size of the array to which we will save audio segments (2^12 = 4096 is very good)
     secToRecord: The length of each sampling
     buffersToRecord: how many multiples of buffers are we recording?
    """
        rate = 44100
        secToRecord = .1
        self.buffersize = 2**12
        self.buffersToRecord = int(rate * secToRecord / self.buffersize)
        if not self.buffersToRecord:
            self.buffersToRecord = 1
        """
    Filters in Hertz
     highHertz: lower limit of the bandpass filter, in Hertz
     lowHertz: upper limit of the bandpass filter, in Hertz
       max lowHertz = (buffersize / 2 - 1) * rate / buffersize
    """
        highHertz = 500
        lowHertz = 10000
        """
    Convert filters from Hertz to bins
     highpass: convert the highHertz into a bin for the FFT
     lowpass: convert the lowHertz into a bin for the FFt
     NOTES:
      highpass is at least the 1st bin since most mics only pick up >=20Hz
      lowpass is no higher than buffersize/2 - 1 (highest array index)
      passband needs to be wider than size of numInput - not checking for that
    """
        self.highpass = max(int(highHertz * self.buffersize / rate), 1)
        self.lowpass = min(int(lowHertz * self.buffersize / rate),
                           self.buffersize / 2 - 1)
        """
    The call to create the temporal pooler region
    """
        self.tp = TP(numberOfCols=self.numCols,
                     cellsPerColumn=4,
                     initialPerm=0.5,
                     connectedPerm=0.5,
                     minThreshold=10,
                     newSynapseCount=10,
                     permanenceInc=0.1,
                     permanenceDec=0.07,
                     activationThreshold=8,
                     globalDecay=0.02,
                     burnIn=2,
                     checkSynapseConsistency=False,
                     pamLength=100)
        """
    Creating the audio stream from our mic
    """
        p = pyaudio.PyAudio()
        #self.inStream = p.open(format=pyaudio.paInt32,channels=1,rate=rate,input=True,frames_per_buffer=self.buffersize)
        self.inStream = p.open(format=pyaudio.paInt32,
                               channels=1,
                               rate=rate,
                               input=True,
                               input_device_index=4,
                               frames_per_buffer=self.buffersize)

        #参考 成功したpyaudio の設定
        #stream = audio.open(format=pyaudio.paInt16, channels=CHANNELS,rate=RATE, input=True,input_device_index=4,frames_per_buffer=CHUNK)
        """
    Setting up the array that will handle the timeseries of audio data from our input
    """
        self.audio = numpy.empty((self.buffersToRecord * self.buffersize),
                                 dtype="uint32")
        """
    Print out the inputs
    """
        print "Number of columns:\t" + str(self.numCols)
        print "Max size of input:\t" + str(self.numInput)
        print "Sampling rate (Hz):\t" + str(rate)
        print "Passband filter (Hz):\t" + str(highHertz) + " - " + str(
            lowHertz)
        print "Passband filter (bin):\t" + str(self.highpass) + " - " + str(
            self.lowpass)
        print "Bin difference:\t\t" + str(self.lowpass - self.highpass)
        print "Buffersize:\t\t" + str(self.buffersize)
        """
    Setup the plot
     Use the bandpass filter frequency range as the x-axis
     Rescale the y-axis
    """
        plt.ion()
        bin = range(self.highpass, self.lowpass)
        xs = numpy.arange(len(bin)) * rate / self.buffersize + highHertz
        self.freqPlot = plt.plot(xs, xs)[0]
        plt.ylim(0, 10**12)

        while True:
            self.processAudio()
Exemple #5
0
            s += ' '
        s += str(x[c])
    s += ' '
    return s


#######################################################################
#
# Step 1: create Temporal Pooler instance with appropriate parameters
tp = TP(numberOfCols=50,
        cellsPerColumn=1,
        initialPerm=0.5,
        connectedPerm=0.5,
        minThreshold=10,
        newSynapseCount=10,
        permanenceInc=0.1,
        permanenceDec=0.0,
        activationThreshold=8,
        globalDecay=0,
        burnIn=1,
        checkSynapseConsistency=False,
        pamLength=10)

#######################################################################
#
# Step 2: create input vectors to feed to the temporal pooler. Each input vector
# must be numberOfCols wide. Here we create a simple sequence of 5 vectors
# representing the sequence A -> B -> C -> D -> E
x = numpy.zeros((5, tp.numberOfCols), dtype="uint32")
x[0, 0:10] = 1  # Input SDR representing "A"
x[1, 10:20] = 1  # Input SDR representing "B"
Exemple #6
0
        flatInput = input.flatten()
        #print "flatInput = ", flatInput
        iterationOutput = numpy.zeros(shape=flatInputLength, dtype="uint8")
        spatialPooler.compute(inputVector=flatInput,
                              learn=True,
                              activeArray=iterationOutput)
        print "Iteration " + str(i) + ":", iterationOutput

print "Initializing temporal pooler"
temporalPooler = TP(
    numberOfCols=flatInputLength,
    cellsPerColumn=104,  # c++ version max = 104
    initialPerm=0.5,
    connectedPerm=0.5,
    minThreshold=10,
    newSynapseCount=10,
    permanenceInc=0.1,
    permanenceDec=0.0,
    activationThreshold=1,
    globalDecay=0,
    burnIn=1,
    checkSynapseConsistency=False,
    pamLength=1)
print "temporal pooler initiaization complete\n"

## train temporal pooler with all potential spatial pooler outputs
#print "training temporal pooler"
#for x in xrange(0, inputWidth * inputHeight):
#	trainingData = numpy.zeros(shape = flatInputLength, dtype = "int32")
#	trainingData[x] = 1
#	temporalPooler.compute(bottomUpInput = trainingData, enableLearn = True, computeInfOutput = False)
#print "training temporal pooler complete\n"
__author__ = 'chandanmaruthi'
from nupic.research.TP10X2 import TP
import numpy
import os
import cPickle as pickle
# Step 1: create Temporal Pooler instance with appropriate parameters
tp = TP(numberOfCols=50, cellsPerColumn=5,
        initialPerm=0.5, connectedPerm=0.5,
        minThreshold=10, newSynapseCount=10,
        permanenceInc=0.1, permanenceDec=0.0,
        activationThreshold=8,
        globalDecay=0, burnIn=1,
        checkSynapseConsistency=False,
        pamLength=10)

path = os.path.abspath("/home/chandanmaruthi/chandan/code/brainscience/tptest.p")

# Step 2: create input vectors to feed to the temporal pooler. Each input vector
# must be numberOfCols wide. Here we create a simple sequence of 5 vectors
# representing the sequence A -> B -> C -> D -> E
x = numpy.zeros((5, tp.numberOfCols), dtype="uint32")
x[0,0:10]  = 1   # Input SDR representing "A", corresponding to columns 0-9
x[1,10:20] = 1   # Input SDR representing "B", corresponding to columns 10-19
x[2,20:30] = 1   # Input SDR representing "C", corresponding to columns 20-29
x[3,30:40] = 1   # Input SDR representing "D", corresponding to columns 30-39
x[4,40:50] = 1   # Input SDR representing "E", corresponding to columns 40-49


# Step 3: send this simple sequence to the temporal pooler for learning
# We repeat the sequence 10 times
test=1