def generateSymbol(self, matrix, maxIterations=20, movieFilename=None): self.matrix = matrix[:] self._matrixWidth = len(self.matrix) mainQuadrant = _Quadrant(quadrantWidth=self._matrixWidth, leftCoordinate=0, topCoordinate=0) self.initialEntropy = self.__calcEntropy(mainQuadrant) self._maxIterations = maxIterations self._imageFrame = 0 self._movieFilename = movieFilename if self._movieFilename is not None: self._imageFileNamePrefix = self._movieFilename exputils.writeMatrixImage(matrix=self.matrix, filename=self._imageFileNamePrefix + str(self._imageFrame).zfill(5) + ".png") self._imageFrame = self._imageFrame + 1 self.finalEntropy = self.__process(quadrant=mainQuadrant) if self._movieFilename is not None: exputils.generateMovie( pngFilenamePattern=self._imageFileNamePrefix + "*.png", outputFilename=self._movieFilename, fps=5)
entropy["entropy"]) + " me = " + str(entropy["metricEntropy"]) unflattenedInput = exputils.unflattenArray(flatInput, inputWidth) if generateOutputMovie: exputils.writeMatrixImage( unflattenedInput, outputImagePrefix + str(cycle).zfill(5) + ".png") spatialPoolerOutput = numpy.zeros(shape=flatInputLength, dtype="int32") spatialPooler.compute(inputVector=flatInput, learn=True, activeArray=spatialPoolerOutput) #print "Spatial Pooler output from input: " #print exputils.vectorToString(spatialPoolerOutput) #print "\n" temporalPooler.compute(bottomUpInput=spatialPoolerOutput, enableLearn=True, computeInfOutput=True) predictedCells = temporalPooler.getPredictedState() #exputils.printPredictedCells(predictedCells) predictionVector = exputils.getPredictionVector(predictedCells) #print "-" * len(predictionVector) #print exputils.vectorToString(predictionVector) #print "Transformed flat input: " #print exputils.vectorToString(flatInput) applyTransform(flatInput, predictionVector) #print exputils.vectorToString(flatInput) if generateOutputMovie: exputils.generateMovie(outputImageMask, outputImagePrefix + "movie.gif")