class Patcher(object):


  def __init__(self, dataDir="/tmp/cerebro2/model"):
    self.paths = Paths(dataDir, deleteExisting=True)


  def patchCLAModel(self, model):
    # Get internal Spatial Pooler Python object
    sp = model._getSPRegion().getSelf()._sfdr
    self.patchSP(sp)

    # Get internal Temporal Pooler Python object
    tp = model._getTPRegion().getSelf()._tfdr
    self.patchTP(tp, sp=sp)


  def patchSP(self, sp):
    SPPatch(self).patch(sp)


  def patchTP(self, tp, sp=None):
    TPPatch(self).patch(tp, sp=sp)


  def patchEncoder(self, encoder, name):
    EncoderPatch(self).patch(encoder, name)


  def patchCoordinateEncoder(self, encoder, name):
    CoordinateEncoderPatch(self).patch(encoder, name)


  def saveDimensions(self, dimensions, layer):
    writeJSON(dimensions, self.paths.dimensions(layer))


  def saveActiveColumns(self, activeColumns, layer, iteration):
    writeJSON(activeColumns, self.paths.activeColumns(layer, iteration))


  def saveActiveCells(self, activeCells, layer, iteration):
    writeJSON(activeCells, self.paths.activeCells(layer, iteration))


  def savePredictedCells(self, predictedCells, layer, iteration):
    writeJSON(predictedCells, self.paths.predictedCells(layer, iteration))


  def saveProximalSynapses(self, proximalSynapses, layer, iteration):
    writeJSON(proximalSynapses, self.paths.proximalSynapses(layer, iteration))
Beispiel #2
0
class Patcher(object):


  def __init__(self, dataDir="/tmp/cerebro2/model"):
    self.paths = Paths(dataDir, deleteExisting=True)


  def patchCLAModel(self, model):
    # Get internal Spatial Pooler Python object
    sp = model._getSPRegion().getSelf()._sfdr
    self.patchSP(sp)

    # Get internal Temporal Pooler Python object
    tp = model._getTPRegion().getSelf()._tfdr
    self.patchTP(tp, sp=sp)


  def patchSP(self, sp):
    SPPatch(self).patch(sp)


  def patchTP(self, tp, sp=None):
    TPPatch(self).patch(tp, sp=sp)


  def patchEncoder(self, encoder, name):
    EncoderPatch(self).patch(encoder, name)


  def patchCoordinateEncoder(self, encoder, name):
    CoordinateEncoderPatch(self).patch(encoder, name)


  def saveDimensions(self, dimensions, layer):
    writeJSON(dimensions, self.paths.dimensions(layer))


  def saveActiveColumns(self, activeColumns, layer, iteration):
    writeJSON(activeColumns, self.paths.activeColumns(layer, iteration))


  def saveActiveCells(self, activeCells, layer, iteration):
    writeJSON(activeCells, self.paths.activeCells(layer, iteration))


  def savePredictedCells(self, predictedCells, layer, iteration):
    writeJSON(predictedCells, self.paths.predictedCells(layer, iteration))


  def saveProximalSynapses(self, proximalSynapses, layer, iteration):
    writeJSON(proximalSynapses, self.paths.proximalSynapses(layer, iteration))
 def __init__(self, dataDir="/tmp/cerebro2/model"):
   self.paths = Paths(dataDir, deleteExisting=True)
Beispiel #4
0
 def __init__(self, dataDir="/tmp/cerebro2/model"):
   self.paths = Paths(dataDir, deleteExisting=True)
 def GET(self):
   paths = Paths(DATA_DIR)
   statesDir = paths.states()
   states = os.listdir(statesDir)
   states = [state for state in states if not state.startswith(".")]
   return jsonResponse(len(states))
Beispiel #6
0
 def __init__(self, dataDir='/tmp/cerebro2/model', modelID=None):
     self._paths = Paths(dataDir, deleteExisting=False)
Beispiel #7
0
class History():
    def __init__(self, dataDir='/tmp/cerebro2/model', modelID=None):
        self._paths = Paths(dataDir, deleteExisting=False)
    
    def getNumberOfIterations(self):
        fileNames = os.listdir(self._paths.states())
        listOfIterations = [state for state in fileNames if not state.startswith(".")]
        return len(listOfIterations)
        
        
        
    def inputDimensions(self):
        return readJSON(self._paths.dimensions("input"))
    
    def dimensions(self):
        return readJSON(self._paths.dimensions("output"))
    
    def inputVector(self):
        inputVector = []       
        for iteration in xrange(1,self.getNumberOfIterations()+1):
            inputVector.append(readJSON(self._paths.activeCells("input", iteration)))
        return inputVector
    
    def activeColumns(self):
        activeColumns = []       
        for iteration in xrange(1,self.getNumberOfIterations()+1):
            activeColumns.append(readJSON(self._paths.activeColumns("output", iteration)))
        return activeColumns
        
    def activeCells(self):
        activeCells = []       
        for iteration in xrange(1,self.getNumberOfIterations()+1):
            activeCells.append(readJSON(self._paths.activeCells("output", iteration)))
        return activeCells
    
    def predictiveCells(self):
        predictiveCells = []       
        for iteration in xrange(1,self.getNumberOfIterations()+1):
            predictiveCells.append(readJSON(self._paths.predictedCells("output", iteration)))
        return predictiveCells
    
    def proximalSynapses(self):
        proximalSynapses = []       
        for iteration in xrange(1,self.getNumberOfIterations()+1):
            proximalSynapses.append(readJSON(self._paths.proximalSynapses("output", iteration)))
        return proximalSynapses

        
    #encoder stuff
    def encoderInputs(self):
        encoderInputs = {}
        for encoderDetails in readJSON(self._paths.encoders()):
            name = encoderDetails['name']
            encoderInputs[name] = []
            for iteration in xrange(1,self.getNumberOfIterations()+1):
                encoderInputs[name].append(readJSON(self._paths.encoderInput(name, iteration)))
        return encoderInputs
        
    def encoderOutputs(self):
        encoderOutputs = {}
        for encoderDetails in readJSON(self._paths.encoders()):
            name = encoderDetails['name']
            encoderOutputs[name] = []
            for iteration in xrange(1,self.getNumberOfIterations()+1):
                encoderOutputs[name].append(readJSON(self._paths.encoderOutput(name, iteration)))
        return encoderOutputs
        
    def encoderNeighbors(self):
        encoderNeighbors = {}
        for encoderDetails in readJSON(self._paths.encoders()):
            name = encoderDetails['name']
            encoderNeighbors[name] = []
            for iteration in xrange(1,self.getNumberOfIterations()+1):
                encoderNeighbors[name].append(readJSON(self._paths.coordinateEncoderNeighbors(name, iteration)))
        return encoderNeighbors

    def encoderTopWCoordinates(self):
        encoderTopWCoordinates = {}
        for encoderDetails in readJSON(self._paths.encoders()):
            name = encoderDetails['name']
            encoderTopWCoordinates[name] = []
            for iteration in xrange(1,self.getNumberOfIterations()+1):
                encoderTopWCoordinates[name].append(readJSON(self._paths.coordinateEncoderTopWCoordinates(name, iteration)))
        return encoderTopWCoordinates