void SubRegion::Contextual(unsigned parentContext){ //parentContext is name output from parent // NO NEED to pre-create entries - only the ones that are required will be created std::map<AccessKey, double> lIter; AccessKey lKey(parentContext, cMemIndex); // Returns false if entry did not exist if ( (*cCPDMatrix)[lKey] == 0.0 ) { // Initialize new entry (note that it has been created by the attempted access (*cCPDMatrix)[lKey] = 1.0; } else { (*cCPDMatrix)[lKey] += 1.0; } // Use insert to speed things up // May be quicker but may crash //lSuccess = cCPDMatrix->insert(std::make_pair(lKey, 1.0)).second; //if ( !lSuccess ) // i.e. row exists //{ // (*cCPDMatrix)[lKey] += 1.0; //} }
CString MR_PreProcLine(const char *pLine) { // scan the line and seardh for predefined keyword CString lReturnValue; if(pLine != NULL) { const char *lPtr = pLine; BOOL lEnd = FALSE; const char *lTokenStart = NULL; while(!lEnd) { switch (*lPtr) { case 0: lEnd = TRUE; case ' ': case ',': case '\n': case '\r': case '\t': if(lTokenStart) { CString lValue; CString lKey(lTokenStart, lPtr - lTokenStart); lTokenStart = NULL; if(gDefineMap.Lookup(lKey, lValue)) { lReturnValue += lValue; } else { lReturnValue += lKey; } } if(!lEnd) { lReturnValue += *lPtr; } break; default: if(!lTokenStart) { lTokenStart = lPtr; } break; } lPtr++; } } return lReturnValue; }
CLightProbe::CLightProbe( const CXMLTreeNode& aXMLNode ) { for ( int i = 0, l_NumChilds = aXMLNode.GetNumChildren(); i < l_NumChilds; ++i ) { CXMLTreeNode& l_CurrentNode = aXMLNode( i ); std::string lTagName( l_CurrentNode.GetName() ); if (lTagName == "center") mPosition = l_CurrentNode.GetAttribute<Math::Vect3f>( "pos", Math::Vect3f(0.0f) ); if (lTagName == "vertexs") { for ( int j = 0, l_NumVertexs = l_CurrentNode.GetNumChildren(); j < l_NumVertexs; ++j ) { CXMLTreeNode l_VertexNode = l_CurrentNode( j ); std::string lVertexTag( l_VertexNode.GetName() ); if (lVertexTag == "vertex") { Math::Vect3f lPos( l_VertexNode.GetAttribute<Math::Vect3f>( "pos", Math::Vect3f(0.0f) )); Math::Vect2f lUV( l_VertexNode.GetAttribute<Math::Vect2f>( "uv", Math::Vect2f(0.0f) )); Math::Vect3f lDir( lPos - mPosition ); lDir.Normalize(); CLightProbeVertex* v = new CLightProbeVertex(lPos, lUV); std::string lKey( "" ); if (lDir.x > 0.9f) lKey = "x"; if (lDir.x < -0.9f) lKey = "-x"; if (lDir.y > 0.9f) lKey = "y"; if (lDir.y < -0.9f) lKey = "-y"; if (lDir.z > 0.9f) lKey = "z"; if (lDir.z < -0.9f) lKey = "-z"; ASSERT(lKey != "", "LightProbe incorrect.") mVertexs[lKey] = v; } } } } }
//lambda is evidence from children, measures NumberOfChildren x MemCount //for Level0: lambda[r][c] is probability that the input to the child r is //the memorized pattern c (how close is the input to the memorized pattern) //assume size(piOut) = number of children void SubRegion::recognize(vector<vector<double> > &lambda, vector<vector<double> > &piOut) { unsigned r, c; AccessKey lKey(0,0); unsigned rowCount = myRegion.getParent() -> getMemCount(); //cPiIn.size(); ? unsigned colCount = myRegion.getMemCount(); //multiply all lambdas into lambdaProd //lambdaProd[c] is combined probability from children that the input to ALL of them //(total input to this Sub-region) is the memorized pattern c //(AND operation - multiplication) vector<double> lambdaProd(colCount, 1.0); for(c = 0; c < colCount; c++) for(r = 0; r < lambda.size(); r++) //lambda.size() = NumberOfChildren lambdaProd[c] *= lambda[r][c]; // DG. I think if we try to add new learning and forget rare memories that have been referenced by higher level memories, // the program can crash due to these orphaned memories still being in cCPDMatrix. // (This version of the program does not allow addition of learning). // We could consider deleting the orphaned memories from cCPDMatrix at this point. // // Exptl - can recalculate required array size in case forgetting memories results in incorrect value // Probably not a very good strategy but code may be useful anyway. // std::map<AccessKey, double>::iterator lIter0, lIterEnd0; // lIterEnd0 = cCPDMatrix->end(); //for ( lIter0 = cCPDMatrix->begin(); lIter0 != lIterEnd0; lIter0++ ) //{ // const std::pair<unsigned,unsigned> lPosition= lIter0->first.cPosition; // r=lPosition.first; // c=lPosition.second; // if ( r > rowCount ) // rowCount = r; // if ( c > colCount ) // colCount = c; //} vector<double> v(colCount, 0); // fxu is the probability that the current input (classified as c) is // part of the higher-level pattern r // Optimisation by Greg Kochaniak - fxu does not have to be a matrix if we just have a single loop. double fxu, lOut; belStar.assign(colCount, 0); lambdaOut.assign(rowCount, 0); std::map<AccessKey, double>::iterator lIter, lIterEnd; lIterEnd = cpdMatrix.end(); for ( lIter = cpdMatrix.begin(); lIter != lIterEnd; lIter++ ) { const std::pair<unsigned,unsigned> lPosition= lIter->first.cPosition; r=lPosition.first; c=lPosition.second; double lVal = lIter->second; lOut = lambdaProd[c] * lVal; fxu = lOut * piIn[r]; if( belStar[c] < fxu ) { belStar[c] = fxu; } if( lambdaOut[r] < lOut ) { lambdaOut[r] = lOut; } } /* The following code is no longer needed //cBelStar (belStarX) is the max for each column in fxu (max over u) // colCount is the number of memorised spatial pattern coincidences cBelStar.resize(colCount, 0); cBelStar.assign(colCount, 0); for(r = 0; r < rowCount; r++) for(c = 0; c < colCount; c++) if(cBelStar[c] < fxu[r][c]) cBelStar[c] = fxu[r][c]; //cLambdaOut is the max for each row in fxu divided by cPiIn - message to our parent cLambdaOut.resize(rowCount, 0); cLambdaOut.assign(rowCount, 0); for(r = 0; r < rowCount; r++) if(cPiIn[r] == 0) cLambdaOut[r] = 0; else{ for(c = 0; c < colCount; c++) //max of each row if(cLambdaOut[r] < fxu[r][c]) cLambdaOut[r] = fxu[r][c]; cLambdaOut[r] /= cPiIn[r]; } //lambda.size() = piOut.size() = InputCount(NumberOfChildren) (or 1 for lowest level) piOut.resize(lambda.size()); for(r = 0; r < piOut.size(); r++){ piOut[r].resize(colCount); for(c = 0; c < colCount; c++) if(lambda[r][c] == 0) piOut[r][c] = 0; else piOut[r][c] = cBelStar[c] / lambda[r][c]; } */ }