#from nupic.research.TP import TP from nupic.research.TP10X2 import TP10X2 as TP os.system("clear") print "Executing Matt's HTM Experiment 1\n" #--------------------------------------- setup ---------------------------------- outputImagePrefix = "exp_1_" outputImageMask = outputImagePrefix + "*.png" exputils.deleteImages(outputImageMask) exputils.deleteImages(outputImagePrefix + "*.gif") inputWidth = 50 inputHeight = 50 input = exputils.getRandom2dBoolMatrix(inputWidth, inputHeight) generateOutputMovie = True flatInput = input.flatten() flatInputLength = len(flatInput) print "initializing spacial pooler" spColumnHeight = flatInputLength spatialPooler = SpatialPooler(inputDimensions=flatInputLength, columnDimensions=spColumnHeight, potentialRadius=10, numActiveColumnsPerInhArea=1, globalInhibition=True, synPermActiveInc=0.03, potentialPct=1.00) print "spacial pooler initialization complete\n"
import os import random os.system("clear") print "Executing Matt's HTM Experiment 2\n" #--------------------------------------- setup ---------------------------------- outputImagePrefix = "exp_2_" outputImageMask = outputImagePrefix + "*.png" exputils.deleteImages(outputImageMask) exputils.deleteImages(outputImagePrefix + "*.gif") inputWidth = 8 inputHeight = 8 input = exputils.getRandom2dBoolMatrix(inputWidth, inputHeight) generateOutputMovie = True flatInput = input.flatten() flatInputLength = len(flatInput) #--------------------- define transform ----------------------- def magic(b, c, d): if b == 0: notb = 1 else: notb = 0 return (b and c) or (notb and d)
def bundleMatrices(matrices): matrixCount = len(matrices) if matrixCount != 4: raise ValueError("bundleMatrices expected 4 matrices, not" + str(matrixCount)) topMatrices = numpy.concatenate((matrices[0], matrices[1]), axis=1) bottomMatrices = numpy.concatenate((matrices[2], matrices[3]), axis=1) outputMatrix = numpy.concatenate((topMatrices, bottomMatrices), axis=0) return outputMatrix #imageArray = exputils.getBitArrayFromBitmapFile("plus_sign_2.bmp") #squareImageArray = exputils.unflattenArray(imageArray, 512) inputWidth = 8192 input1 = exputils.getRandom2dBoolMatrix(inputWidth, inputWidth) # #for y in xrange(106, 406): # for x in xrange(226, 286): # input1[y, x] = 0 # #for y in xrange(226, 286): # for x in xrange(106, 406): # input1[y, x] = 0 # exputils.writeMatrixImage(input1, "input_1_raw.png") inputData = input1 previousEntropy = -1 for cycle in xrange(0, 20):
os.system("clear") print "Executing Matt's HTM Experiment 4\n" #--------------------------------------- setup ---------------------------------- outputImagePrefix = "exp_4_" outputImageMask = outputImagePrefix + "*.png" exputils.deleteImages(outputImageMask) exputils.deleteImages(outputImagePrefix + "*.gif") inputWidth = 1000 inputHeight = 1000 generateOutputMovie = True i1 = exputils.getRandom2dBoolMatrix(inputWidth, inputHeight) flati1 = i1.flatten() i2 = exputils.getRandom2dBoolMatrix(inputWidth, inputHeight) flati2 = i2.flatten() def xorInputs(i1, i2): length = len(i1) outputData = numpy.zeros(shape=length, dtype="uint8") for x in xrange(0, len(i1)): if i1[x] != i2[x]: outputData[x] = 1 return outputData