def nextStep(self): """ Perfoms actions related to time step progression. """ Node.nextStep(self) for column in self.columns: column.nextStep() # Get input from sensors or lower regions and put into a single input map. input = self.getInput() # Send input to Spatial Pooler and get processed output (i.e. the active columns) # First initialize the vector for representing the current record columnDimensions = (self.width, self.height) columnNumber = numpy.array(columnDimensions).prod() activeColumns = numpy.zeros(columnNumber) self.spatialPooler.compute(input, self.enableSpatialLearning, activeColumns) # Send active columns to Temporal Pooler and get processed output (i.e. the predicting cells) # First convert active columns from float array to integer set activeColumnsSet = set() for colIdx in range(len(activeColumns)): if activeColumns[colIdx] == 1: activeColumnsSet.add(colIdx) self.temporalPooler.compute(activeColumnsSet, self.enableTemporalLearning) # Update elements regarding spatial pooler self.updateSpatialElements(activeColumns) # Update elements regarding temporal pooler self.updateTemporalElements() # Get the predicted values self.getPredictions()
def nextStep(self): """ Performs actions related to time step progression. """ # Update states machine by remove the first element and add a new element in the end for encoding in self.encodings: encoding.currentValue.rotate() if encoding.enableInference: encoding.predictedValues.rotate() encoding.bestPredictedValue.rotate() Node.nextStep(self) for bit in self.bits: bit.nextStep() # Get record value from data source # If the last record was reached just rewind it data = self.dataSource.getNextRecordDict() if not data: self.dataSource.rewind() data = self.dataSource.getNextRecordDict() # Pass raw values to encoder and get a concatenated array outputArray = numpy.zeros(self.encoder.getWidth()) self.encoder.encodeIntoArray(data, outputArray) # Get values obtained from the data source. outputValues = self.encoder.getScalars(data) # Get raw values and respective encoded bit array for each field prevOffset = 0 for i in range(len(self.encodings)): encoding = self.encodings[i] # Convert the value to its respective data type currValue = outputValues[i] if encoding.encoderFieldDataType == FieldDataType.boolean: currValue = bool(currValue) elif encoding.encoderFieldDataType == FieldDataType.integer: currValue = int(currValue) elif encoding.encoderFieldDataType == FieldDataType.decimal: currValue = float(currValue) elif encoding.encoderFieldDataType == FieldDataType.dateTime: currValue = dateutil.parser.parse(str(currValue)) elif encoding.encoderFieldDataType == FieldDataType.string: currValue = str(currValue) encoding.currentValue.setForCurrStep(currValue) # Update sensor bits for i in range(len(outputArray)): if outputArray[i] > 0.: self.bits[i].isActive.setForCurrStep(True) else: self.bits[i].isActive.setForCurrStep(False) # Mark falsely predicted bits for bit in self.bits: if bit.isPredicted.atPreviousStep() and not bit.isActive.atCurrStep(): bit.isFalselyPredicted.setForCurrStep(True) self._output = outputArray
def nextStep(self): """ Performs actions related to time step progression. """ # Update states machine by remove the first element and add a new element in the end for encoding in self.encodings: encoding.currentValue.rotate() if encoding.enableInference: encoding.predictedValues.rotate() encoding.bestPredictedValue.rotate() Node.nextStep(self) for bit in self.bits: bit.nextStep() # Get record value from data source # If the last record was reached just rewind it data = self.dataSource.getNextRecordDict() if not data: self.dataSource.rewind() data = self.dataSource.getNextRecordDict() # Pass raw values to encoder and get a concatenated array outputArray = numpy.zeros(self.encoder.getWidth()) self.encoder.encodeIntoArray(data, outputArray) # Get values obtained from the data source. outputValues = self.encoder.getScalars(data) # Get raw values and respective encoded bit array for each field prevOffset = 0 for i in range(len(self.encodings)): encoding = self.encodings[i] # Convert the value to its respective data type currValue = outputValues[i] if encoding.encoderFieldDataType == FieldDataType.boolean: currValue = bool(currValue) elif encoding.encoderFieldDataType == FieldDataType.integer: currValue = int(currValue) elif encoding.encoderFieldDataType == FieldDataType.decimal: currValue = float(currValue) elif encoding.encoderFieldDataType == FieldDataType.dateTime: currValue = dateutil.parser.parse(str(currValue)) elif encoding.encoderFieldDataType == FieldDataType.string: currValue = str(currValue) encoding.currentValue.setForCurrStep(currValue) # Update sensor bits for i in range(len(outputArray)): if outputArray[i] > 0.: self.bits[i].isActive.setForCurrStep(True) else: self.bits[i].isActive.setForCurrStep(False) # Mark falsely predicted bits for bit in self.bits: if bit.isPredicted.atPreviousStep( ) and not bit.isActive.atCurrStep(): bit.isFalselyPredicted.setForCurrStep(True) self._output = outputArray
def nextStep(self): """ Performs actions related to time step progression. """ # Update states machine by remove the first element and add a new element in the end for encoding in self.encodings: encoding.current_value.rotate() if encoding.enable_inference: encoding.predicted_values.rotate() encoding.best_predicted_value.rotate() Node.nextStep(self) for bit in self.bits: bit.nextStep() # Get record value from data source # If the last record was reached just rewind it data = self.data_source.getNextRecordDict() if not data: self.data_source.rewind() data = self.data_source.getNextRecordDict() # Pass raw values to encoder and get a concatenated array output_array = numpy.zeros(self.encoder.getWidth()) self.encoder.encodeIntoArray(data, output_array) # Get values obtained from the data source. output_values = self.encoder.getScalars(data) # Get raw values and respective encoded bit array for each field for i in range(len(self.encodings)): encoding = self.encodings[i] # Convert the value to its respective data type curr_value = output_values[i] if encoding.encoder_field_data_type == FieldDataType.BOOLEAN: curr_value = bool(curr_value) elif encoding.encoder_field_data_type == FieldDataType.INTEGER: curr_value = int(curr_value) elif encoding.encoder_field_data_type == FieldDataType.DECIMAL: curr_value = float(curr_value) elif encoding.encoder_field_data_type == FieldDataType.DATE_TIME: curr_value = dateutil.parser.parse(str(curr_value)) elif encoding.encoder_field_data_type == FieldDataType.STRING: curr_value = str(curr_value) encoding.current_value.setForCurrStep(curr_value) # Update sensor bits for i in range(len(output_array)): if output_array[i] > 0.0: self.bits[i].is_active.setForCurrStep(True) else: self.bits[i].is_active.setForCurrStep(False) # Mark falsely predicted bits for bit in self.bits: if bit.is_predicted.atPreviousStep() and not bit.is_active.atCurrStep(): bit.is_falsely_predicted.setForCurrStep(True) self.output = output_array