def initialize(self): """ Initialize this node. """ Node.initialize(self) # Initialize input bits self.bits = [] for x in range(self.width): for y in range(self.height): bit = Bit() bit.x = x bit.y = y self.bits.append(bit) if self.dataSourceType == DataSourceType.file: """ Initialize this node opening the file and place cursor on the first record. """ # If file name provided is a relative path, use project file path if self.fileName != '' and os.path.dirname(self.fileName) == '': fullFileName = os.path.dirname(Global.project.fileName) + '/' + self.fileName else: fullFileName = self.fileName # Open file if not os.path.isfile(fullFileName): QtGui.QMessageBox.warning(None, "Warning", "Input stream file '" + fullFileName + "' was not found or specified.", QtGui.QMessageBox.Ok) return if self.inputFormat == InputFormat.htm: self._file = open(fullFileName, "rb") # Get dimensions of the record width = 0 height = 0 character = 0 while True: # Read next character character = self._file.read(1) # Check if character is 'return' and not a number, i.e. if the first record was read if character == '\r': character = self._file.read(1) if character == '\n': break # Pass over the line until find a 'return' character in order to get the width width = 0 while character != '\n': width += 1 character = self._file.read(1) if character == '\r': character = self._file.read(1) # Increments height height += 1 elif self.inputFormat == InputFormat.raw: pass elif self.dataSourceType == DataSourceType.database: pass # If current file record dimensions is not the same to sensor size then throws exception if self.width != width or self.height != height: self.width = width self.height = height
def initialize(self): """ Initialize this node. """ if len(self.children) == 0: QtGui.QMessageBox.warning( None, "Warning", "Region '" + self.name + "' does not have any child!") return Node.initialize(self) for child in self.children: child.initialize() # Create the input map # An input map is a set of input elements (cells or sensor bits) that can be are grouped or combined # For example, if we have 2 children (#1 and #2) with dimensions 6 and 12 respectively, # a grouped input map would be something like: # 111111222222222222 # while a combined one would be something like: # 122122122122122122 self._inputMap = [] sumDimension = 0 if self.inputMapType == InputMapType.grouped: elemIdx = 0 for child in self.children: dimension = child.width * child.height sumDimension += dimension # Arrange input from child into input map of this region if child.type == NodeType.region: for column in child.columns: inputElem = column.cells[0] self._inputMap.append(inputElem) else: for bit in child.bits: inputElem = bit self._inputMap.append(inputElem) elemIdx += 1 elif self.inputMapType == InputMapType.combined: # Get the overall dimension and the minimum dimension among all children minDimension = self.children[0].width * self.children[0].height for child in self.children: dimension = child.width * child.height sumDimension += dimension if dimension < minDimension: minDimension = dimension # Use the minimum dimension as a multiplication common factor to determine the frequency of each child element in a sequence frequencies = [] nextIdx = [] for child in self.children: dimension = child.width * child.height if dimension % minDimension == 0: frequency = dimension / minDimension frequencies.append(frequency) nextIdx.append(0) else: QtGui.QMessageBox.warning( None, "Warning", "Children dimensions should have a common multiple factor!" ) return # Distribute alternatively child elements into input map according to their frequencies childIdx = 0 for elemIdx in range(sumDimension): if childIdx == len(self.children): childIdx = 0 child = self.children[childIdx] # Start distribution taking in account the last inserted element i0 = nextIdx[childIdx] iN = i0 + frequencies[childIdx] nextIdx[childIdx] = iN for i in range(i0, iN): if child.type == NodeType.region: inputElem = child.columns[i].cells[0] self._inputMap.append(inputElem) else: inputElem = child.bits[i] self._inputMap.append(inputElem) # Alternate children childIdx += 1 # Initialize elements self.columns = [] colIdx = 0 for x in range(self.width): for y in range(self.height): column = Column() column.x = x column.y = y for z in range(self.numCellsPerColumn): cell = Cell() cell.index = (colIdx * self.numCellsPerColumn) + z cell.z = z column.cells.append(cell) self.columns.append(column) colIdx += 1 # Create Spatial Pooler instance with appropriate parameters self.spatialPooler = SpatialPooler( inputDimensions=(sumDimension, 1), columnDimensions=(self.width, self.height), potentialRadius=self.potentialRadius, potentialPct=self.potentialPct, globalInhibition=self.globalInhibition, localAreaDensity=self.localAreaDensity, numActiveColumnsPerInhArea=self.numActiveColumnsPerInhArea, stimulusThreshold=self.stimulusThreshold, synPermInactiveDec=self.proximalSynPermDecrement, synPermActiveInc=self.proximalSynPermIncrement, synPermConnected=self.proximalSynConnectedPerm, minPctOverlapDutyCycle=self.minPctOverlapDutyCycle, minPctActiveDutyCycle=self.minPctActiveDutyCycle, dutyCyclePeriod=self.dutyCyclePeriod, maxBoost=self.maxBoost, seed=-1, spVerbosity=False) # Create Temporal Pooler instance with appropriate parameters self.temporalPooler = TemporalPooler( columnDimensions=(self.width, self.height), cellsPerColumn=self.numCellsPerColumn, learningRadius=self.learningRadius, initialPermanence=self.distalSynInitialPerm, connectedPermanence=self.distalSynConnectedPerm, minThreshold=self.minThreshold, maxNewSynapseCount=self.maxNumNewSynapses, permanenceIncrement=self.distalSynPermIncrement, permanenceDecrement=self.distalSynPermDecrement, activationThreshold=self.activationThreshold, seed=42) return True
def initialize(self): """ Initialize this node. """ Node.initialize(self) for child in self.children: child.initialize() # Create the input map # An input map is a set of input elements (cells or sensor bits) that can be are grouped or combined # For example, if we have 2 children (#1 and #2) with dimensions 6 and 12 respectively, # a grouped input map would be something like: # 111111222222222222 # while a combined one would be something like: # 122122122122122122 self._inputMap = [] sumDimension = 0 self.inputMapType = InputMapType.grouped if self.inputMapType == InputMapType.grouped: for child in self.children: dimension = child.width * child.height sumDimension += dimension # Arrange input from child into input map of this region if child.type == NodeType.region: for column in child.columns: inputElem = column.cells[0] self._inputMap.append(inputElem) else: for bit in child.bits: inputElem = bit self._inputMap.append(inputElem) elif self.inputMapType == InputMapType.combined: # Get the overall dimension and the minimum dimension among all children minDimension = self.children[0].width * self.children[0].height for child in self.children: dimension = child.width * child.height sumDimension += dimension if dimension < minDimension: minDimension = dimension # Use the minimum dimension as a multiplication common factor to determine the frequency of each child element in a sequence frequencies = [] nextIdx = [] for child in self.children: dimension = child.width * child.height if dimension % minDimension == 0: frequency = dimension / minDimension frequencies.append(frequency) nextIdx.append(0) else: QtGui.QMessageBox.warning(None, "Warning", "Children dimensions should have a common multiple factor!") return # Distribute alternatively child elements into input map according to their frequencies for elemIdx in range(sumDimension): for childIdx in range(len(self.children)): child = self.children[childIdx] # Start distribution taking in account the last inserted element i0 = nextIdx[childIdx] iN = i0 + frequencies[childIdx] nextIdx[childIdx] = iN + 1 for i in range(i0, iN): if child.type == NodeType.region: inputElem = child.columns[i].cells[0] self._inputMap.append(inputElem) else: inputElem = child.bits[i] self._inputMap.append(inputElem) # Initialize elements self.columns = [] for x in range(self.width): for y in range(self.height): column = Column() column.x = x column.y = y for z in range(self.numCellsPerColumn): cell = Cell() cell.z = z column.cells.append(cell) self.columns.append(column) # Create Spatial Pooler instance with appropriate parameters self.spatialPooler = SpatialPooler( inputDimensions = (sumDimension, 1), columnDimensions = (self.width, self.height), potentialRadius = self.potentialRadius, potentialPct = self.potentialPct, globalInhibition = self.globalInhibition, localAreaDensity = self.localAreaDensity, numActiveColumnsPerInhArea = self.numActiveColumnsPerInhArea, stimulusThreshold = self.stimulusThreshold, synPermInactiveDec = self.proximalSynPermDecrement, synPermActiveInc = self.proximalSynPermIncrement, synPermConnected = self.proximalSynConnectedPerm, minPctOverlapDutyCycle = self.minPctOverlapDutyCycle, minPctActiveDutyCycle = self.minPctActiveDutyCycle, dutyCyclePeriod = self.dutyCyclePeriod, maxBoost = self.maxBoost, seed = -1, spVerbosity = False) # Create Temporal Pooler instance with appropriate parameters self.temporalPooler = TemporalPooler( columnDimensions = (self.width, self.height), cellsPerColumn = self.numCellsPerColumn, learningRadius = self.learningRadius, initialPermanence = self.distalSynInitialPerm, connectedPermanence = self.distalSynConnectedPerm, minThreshold = self.minThreshold, maxNewSynapseCount = self.maxNumNewSynapses, permanenceIncrement = self.distalSynPermIncrement, permanenceDecrement = self.distalSynPermDecrement, activationThreshold = self.activationThreshold, seed = 42)
def initialize(self): """ Initialize this node. """ Node.initialize(self) # Initialize input bits self.bits = [] for x in range(self.width): for y in range(self.height): bit = Bit() bit.x = x bit.y = y self.bits.append(bit) if self.dataSourceType == DataSourceType.file: """ Initialize this node opening the file and place cursor on the first record. """ # If file name provided is a relative path, use project file path if self.fileName != '' and os.path.dirname(self.fileName) == '': fullFileName = os.path.dirname( Global.project.fileName) + '/' + self.fileName else: fullFileName = self.fileName # Check if file really exists if not os.path.isfile(fullFileName): QtGui.QMessageBox.warning( None, "Warning", "Input stream file '" + fullFileName + "' was not found or specified.", QtGui.QMessageBox.Ok) return # Create a data source for read the file self.dataSource = FileRecordStream(fullFileName) elif self.dataSourceType == DataSourceType.database: pass self.encoder = MultiEncoder() for encoding in self.encodings: encoding.initialize() # Create an instance class for an encoder given its module, class and constructor params encoding.encoder = getInstantiatedClass(encoding.encoderModule, encoding.encoderClass, encoding.encoderParams) # Take the first part of encoder field name as encoder name # Ex: timestamp_weekend.weekend => timestamp_weekend encoding.encoder.name = encoding.encoderFieldName.split('.')[0] # Add sub-encoder to multi-encoder list self.encoder.addEncoder(encoding.dataSourceFieldName, encoding.encoder) # If encoder size is not the same to sensor size then throws exception encoderSize = self.encoder.getWidth() sensorSize = self.width * self.height if encoderSize > sensorSize: QtGui.QMessageBox.warning( None, "Warning", "'" + self.name + "': Encoder size (" + str(encoderSize) + ") is different from sensor size (" + str(self.width) + " x " + str(self.height) + " = " + str(sensorSize) + ").", QtGui.QMessageBox.Ok) return return True
def initialize(self): """ Initialize this node. """ Node.initialize(self) # Initialize input bits self.bits = [] for x in range(self.width): for y in range(self.height): bit = Bit() bit.x = x bit.y = y self.bits.append(bit) if self.dataSourceType == DataSourceType.file: """ Initialize this node opening the file and place cursor on the first record. """ # If file name provided is a relative path, use project file path if self.fileName != '' and os.path.dirname(self.fileName) == '': fullFileName = os.path.dirname( Global.project.fileName) + '/' + self.fileName else: fullFileName = self.fileName # Open file if not os.path.isfile(fullFileName): QtGui.QMessageBox.warning( None, "Warning", "Input stream file '" + fullFileName + "' was not found or specified.", QtGui.QMessageBox.Ok) return if self.inputFormat == InputFormat.htm: self._file = open(fullFileName, "rb") # Get dimensions of the record width = 0 height = 0 character = 0 while True: # Read next character character = self._file.read(1) # Check if character is 'return' and not a number, i.e. if the first record was read if character == '\r': character = self._file.read(1) if character == '\n': break # Pass over the line until find a 'return' character in order to get the width width = 0 while character != '\n': width += 1 character = self._file.read(1) if character == '\r': character = self._file.read(1) # Increments height height += 1 elif self.inputFormat == InputFormat.raw: pass elif self.dataSourceType == DataSourceType.database: pass # If current file record dimensions is not the same to sensor size then throws exception if self.width != width or self.height != height: self.width = width self.height = height
def initialize(self): """ Initialize this node. """ if len(self.children) == 0: QtGui.QMessageBox.warning(None, "Warning", "Region '" + self.name + "' does not have any child!") return Node.initialize(self) for child in self.children: child.initialize() # Create the input map # An input map is a set of input elements (cells or sensor bits) that should are grouped # For example, if we have 2 children (#1 and #2) with dimensions 6 and 12 respectively, # a input map would be something like: # 111111222222222222 self._inputMap = [] sumDimension = 0 elemIdx = 0 for child in self.children: dimension = child.width * child.height sumDimension += dimension # Arrange input from child into input map of this region if child.type == NodeType.region: for column in child.columns: inputElem = column.cells[0] self._inputMap.append(inputElem) else: for bit in child.bits: inputElem = bit self._inputMap.append(inputElem) elemIdx += 1 # Initialize elements self.columns = [] colIdx = 0 for x in range(self.width): for y in range(self.height): column = Column() column.x = x column.y = y for z in range(self.numCellsPerColumn): cell = Cell() cell.index = (colIdx * self.numCellsPerColumn) + z cell.z = z column.cells.append(cell) self.columns.append(column) colIdx += 1 # Create Spatial Pooler instance with appropriate parameters self.spatialPooler = SpatialPooler( inputDimensions = (sumDimension, 1), columnDimensions = (self.width, self.height), potentialRadius = self.potentialRadius, potentialPct = self.potentialPct, globalInhibition = self.globalInhibition, localAreaDensity = self.localAreaDensity, numActiveColumnsPerInhArea = self.numActiveColumnsPerInhArea, stimulusThreshold = self.stimulusThreshold, synPermInactiveDec = self.proximalSynPermDecrement, synPermActiveInc = self.proximalSynPermIncrement, synPermConnected = self.proximalSynConnectedPerm, minPctOverlapDutyCycle = self.minPctOverlapDutyCycle, minPctActiveDutyCycle = self.minPctActiveDutyCycle, dutyCyclePeriod = self.dutyCyclePeriod, maxBoost = self.maxBoost, seed = self.spSeed, spVerbosity = False) # Create Temporal Pooler instance with appropriate parameters self.temporalPooler = TemporalPooler( columnDimensions = (self.width, self.height), cellsPerColumn = self.numCellsPerColumn, learningRadius = self.learningRadius, initialPermanence = self.distalSynInitialPerm, connectedPermanence = self.distalSynConnectedPerm, minThreshold = self.minThreshold, maxNewSynapseCount = self.maxNumNewSynapses, permanenceIncrement = self.distalSynPermIncrement, permanenceDecrement = self.distalSynPermDecrement, activationThreshold = self.activationThreshold, seed = self.tpSeed) return True
def initialize(self): """ Initialize this node. """ Node.initialize(self) # Initialize input bits self.bits = [] for x in range(self.width): for y in range(self.height): bit = Bit() bit.x = x bit.y = y self.bits.append(bit) if self.dataSourceType == DataSourceType.file: """ Initialize this node opening the file and place cursor on the first record. """ # If file name provided is a relative path, use project file path if self.fileName != '' and os.path.dirname(self.fileName) == '': fullFileName = os.path.dirname(Global.project.fileName) + '/' + self.fileName else: fullFileName = self.fileName # Open file if not os.path.isfile(fullFileName): QtGui.QMessageBox.warning(None, "Warning", "Input stream file '" + fullFileName + "' was not found or specified.", QtGui.QMessageBox.Ok) return if self.inputFormat == InputFormat.htm: self._file = open(fullFileName, "rb") # Get dimensions of the record width = 0 height = 0 character = 0 while True: # Read next character character = self._file.read(1) # Check if character is 'return' and not a number, i.e. if the first record was read if character == '\r': character = self._file.read(1) if character == '\n': break # Pass over the line until find a 'return' character in order to get the width width = 0 while character != '\n': width += 1 character = self._file.read(1) if character == '\r': character = self._file.read(1) # Increments height height += 1 # If current file record dimensions is not the same to sensor size then throws exception if self.width != width or self.height != height: QtGui.QMessageBox.warning(None, "Warning", "'" + self.name + "': File input size (" + width + " x " + height + ") is different from sensor size (" + self.width + " x " + self.height + ").", QtGui.QMessageBox.Ok) return # Put the pointer back to initial position self._file.seek(0) elif self.inputFormat == InputFormat.raw: self._file = open(fullFileName) # Create an instance class for an encoder given its module, class and constructor params self.encoder = getInstantiatedClass(self.encoderModule, self.encoderClass, self.encoderParams) # If encoder size is not the same to sensor size then throws exception encoderSize = self.encoder.getWidth() sensorSize = self.width * self.height if encoderSize > sensorSize: QtGui.QMessageBox.warning(None, "Warning", "'" + self.name + "': Encoder size (" + str(encoderSize) + ") is different from sensor size (" + str(self.width) + " x " + str(self.height) + " = " + str(sensorSize) + ").", QtGui.QMessageBox.Ok) return elif self.dataSourceType == DataSourceType.database: pass # Create Classifier instance with appropriate parameters self.minProbabilityThreshold = 0.0001 self.steps = [] for step in range(maxFutureSteps): self.steps.append(step+1) self.classifier = CLAClassifier(steps=self.steps)
def initialize(self): """ Initialize this node. """ # Check if this region has nodes that feed it numFeeders = len(Global.project.network.getFeederNodes(self)) if numFeeders == 0: QtGui.QMessageBox.warning( None, "Warning", "Region '" + self.name + "' does not have any child!") return # Initialize this node and the nodes that feed it Node.initialize(self) # Create the input map # An input map is a set of input elements (cells or sensor bits) that should are grouped # For example, if we have 2 nodes that feed this region (#1 and #2) with dimensions 6 and 12 respectively, # a input map would be something like: # 111111222222222222 self._inputMap = [] elemIdx = 0 for feeder in Global.project.network.getFeederNodes(self): # Arrange input from feeder into input map of this region if feeder.type == NodeType.region: for column in feeder.columns: inputElem = column.cells[0] self._inputMap.append(inputElem) else: for bit in feeder.bits: inputElem = bit self._inputMap.append(inputElem) elemIdx += 1 # Initialize elements self.columns = [] colIdx = 0 for x in range(self.width): for y in range(self.height): column = Column() column.x = x column.y = y for z in range(self.numCellsPerColumn): cell = Cell() cell.index = (colIdx * self.numCellsPerColumn) + z cell.z = z column.cells.append(cell) self.columns.append(column) colIdx += 1 # Create Spatial Pooler instance with appropriate parameters self.spatialPooler = SpatialPooler( inputDimensions=(self.getInputSize(), 1), columnDimensions=(self.width, self.height), potentialRadius=self.potentialRadius, potentialPct=self.potentialPct, globalInhibition=self.globalInhibition, localAreaDensity=self.localAreaDensity, numActiveColumnsPerInhArea=self.numActiveColumnsPerInhArea, stimulusThreshold=self.stimulusThreshold, synPermInactiveDec=self.proximalSynPermDecrement, synPermActiveInc=self.proximalSynPermIncrement, synPermConnected=self.proximalSynConnectedPerm, minPctOverlapDutyCycle=self.minPctOverlapDutyCycle, minPctActiveDutyCycle=self.minPctActiveDutyCycle, dutyCyclePeriod=self.dutyCyclePeriod, maxBoost=self.maxBoost, seed=self.spSeed, spVerbosity=False) # Create Temporal Pooler instance with appropriate parameters self.temporalPooler = TemporalPooler( columnDimensions=(self.width, self.height), cellsPerColumn=self.numCellsPerColumn, learningRadius=self.learningRadius, initialPermanence=self.distalSynInitialPerm, connectedPermanence=self.distalSynConnectedPerm, minThreshold=self.minThreshold, maxNewSynapseCount=self.maxNumNewSynapses, permanenceIncrement=self.distalSynPermIncrement, permanenceDecrement=self.distalSynPermDecrement, activationThreshold=self.activationThreshold, seed=self.tpSeed) return True