// save and restore knowledge void Intel_PMT::beginSaveMode(void) { nsr_save = regRead16(NSR); // set save/restore mode in the NSR regWrite16( NSR, regRead16(NSR) | NSR_NET_MODE); // reset the chain to 0th neuron regWrite16( RSTCHAIN, 0); }
// pass the function a structure to save data into uint16_t Intel_PMT::iterateNeuronsToSave(neuronData& array ) { array.context = regRead16( NCR ); for( int i=0; i < saveRestoreSize; i++) { array.vector[i] = regRead16(COMP); } array.influence = regRead16( AIF ); array.minInfluence = regRead16( MINIF ); array.category = regRead16( CAT ); return array.category; }
// retrieve the data of a specific neuron element by ID, between 1 and 128. uint16_t Intel_PMT::readNeuron( int32_t neuronID, neuronData& data_array) { uint16_t dummy = 0; // range check the ID - technically, this should be an error. if( neuronID < firstNeuronID ) neuronID = firstNeuronID; if(neuronID > lastNeuronID ) neuronID = lastNeuronID; // use the beginSaveMode method beginSaveMode(); //iterate over n elements in order to reach the one we want. for( int i = 0; i < (neuronID -1); i++) { dummy = regRead16( CAT ); } // retrieve the data using the iterateToSave method iterateNeuronsToSave( data_array); //restore the network to how we found it. endSaveMode(); return 0; }
Intel_PMT::PATTERN_MATCHING_CLASSIFICATION_MODE Intel_PMT::getClassifierMode( void ) // RBF or KNN { if( regRead16( NSR ) & NSR_CLASS_MODE ) return KNN_Mode; return RBF_Mode; }
void Intel_PMT::setDistanceMode( Intel_PMT::PATTERN_MATCHING_DISTANCE_MODE mode) // L1 or LSup { uint16_t rd = regRead16(GCR); // do a read modify write on the GCR register regWrite16(GCR, (mode == LSUP_Distance) ? rd | GCR_DIST : rd & ~GCR_DIST); }
uint16_t Intel_PMT::learn(uint8_t *pattern_vector, int32_t vector_length, uint16_t category) { if( vector_length > maxVectorSize ) vector_length = maxVectorSize; for( int i = 0; i < vector_length -1; i++ ) { regWrite16( COMP , pattern_vector[i] ); } regWrite16( LCOMP, pattern_vector[ vector_length - 1 ] ); /* Mask off the 15th bit-- valid categories range from 1-32766, * and bit 15 is used to indicate if a firing neuron has degenerated */ regWrite16(CAT, (regRead16(CAT) & ~CAT_CATEGORY) | (category & CAT_CATEGORY)); return regRead16( FORGET_NCOUNT ); }
void Intel_PMT::setClassifierMode( Intel_PMT::PATTERN_MATCHING_CLASSIFICATION_MODE mode ) { uint16_t mask = regRead16(NSR ); mask &= ~NSR_CLASS_MODE; if( mode == KNN_Mode ) mask |= NSR_CLASS_MODE; regWrite16( NSR, mask); }
void Intel_PMT::configure( uint16_t global_context, PATTERN_MATCHING_DISTANCE_MODE distance_mode, PATTERN_MATCHING_CLASSIFICATION_MODE classification_mode, uint16_t minAIF, uint16_t maxAIF ) { regWrite16( GCR , (global_context | (distance_mode << 7))); regWrite16( NSR , regRead16( NSR) | (classification_mode << 5) ); regWrite16( MINIF, minAIF); regWrite16( MAXIF, maxAIF); }
uint16_t Intel_PMT::classify(uint8_t *pattern_vector, int32_t vector_length) { uint8_t *current_vector = pattern_vector; uint8_t index = 0; if (vector_length > maxVectorSize) return -1; for (index = 0; index < (vector_length - 1); index++) { regWrite16(COMP, current_vector[index]); } regWrite16( LCOMP , current_vector[vector_length - 1] ); // Sort matching categories by (We don't care about the returned value here; // reading the distance register sorts matched categories by distance) regRead16(IDX_DIST); // Return the category with the lowest distance to point return (regRead16(CAT) & CAT_CATEGORY); }
// Default initializer void Intel_PMT::begin(void) { uint16_t savedNSR = regRead16( NSR ); forget(); regWrite16( NSR, (uint16_t) NSR_NET_MODE); for( int i = 0; i < maxNeurons; i++) { regWrite16( TESTCOMP, 0 ); } regWrite16( TESTCAT, 0); regWrite16( NSR, savedNSR ); }
int SDICameraControl::read(byte data[], int dataLength) const { if (!available()) return 0; // Read control data incoming length and data int availableLength = regRead16(kRegICLENGTH); if (availableLength > dataLength) return -1; regRead(kRegICDATA, data, availableLength); // Arm the control data incoming bank regWrite8(kRegICARM, kRegICARM_ARM_Mask); return availableLength; }
uint16_t Intel_PMT::getRSTCHAIN( void ) { return regRead16(RSTCHAIN); }
uint16_t Intel_PMT::getGCR( void ) { return regRead16(GCR); }
uint16_t Intel_PMT::getNID( void ) { return regRead16(NID); }
uint16_t Intel_PMT::getMAXIF( void ) { return regRead16(MAXIF); }
uint16_t Intel_PMT::getAIF( void ) { return regRead16(AIF); }
// A valid context value is in the range of 1-127. A context // value of 0 enables all neurons, without regard to their context void Intel_PMT::setGlobalContext(uint16_t context) { uint16_t gcrMask = ~GCR_GLOBAL & regRead16(GCR); gcrMask |= (context & GCR_GLOBAL); regWrite16(GCR, gcrMask); }
uint16_t Intel_PMT::getLCOMP( void ) { return regRead16(LCOMP); }
Intel_PMT::PATTERN_MATCHING_DISTANCE_MODE // L1 or LSup Intel_PMT::getDistanceMode(void) { return (GCR_DIST & regRead16(GCR)) ? LSUP_Distance : L1_Distance; }
// valid range is 1-127 void Intel_PMT::setNeuronContext(uint16_t context) { uint16_t ncrMask = ~NCR_CONTEXT & regRead16(NCR); ncrMask |= (context & NCR_CONTEXT); regWrite16(NCR, ncrMask); }
uint16_t Intel_PMT::getNeuronContext(void) { return (NCR_CONTEXT & regRead16(NCR)); }
uint16_t Intel_PMT::getNSR( void ) { return regRead16(NSR); }
uint16_t Intel_PMT::getFORGET_NCOUNT( void ) { return regRead16(FORGET_NCOUNT); }
uint16_t Intel_PMT::getIDX_DIST( void ) { return regRead16(IDX_DIST); }
uint16_t Intel_PMT::getCAT( void ) { return regRead16(CAT); }
uint16_t Intel_PMT::getGlobalContext(void) { return (GCR_GLOBAL & regRead16(GCR)); }