int PursuitLayer::recvSynapticInput(HyPerConn * conn, const PVLayerCube * activity, int arborID) { if (parent->simulationTime()<nextUpdate) return PV_SUCCESS; nextUpdate += updatePeriod; recvsyn_timer->start(); assert(arborID >= 0); if (conn->usingSharedWeights() == false) { fprintf(stderr, "Error: PursuitLayer can only be the postsynaptic layer of a connection using shared weights (this condition should be removed eventually).\n"); abort(); } HyPerLayer * pre = conn->preSynapticLayer(); const PVLayerLoc * pre_loc = pre->getLayerLoc(); if (pre_loc->nx != getLayerLoc()->nx || pre_loc->ny != getLayerLoc()->ny) { fprintf(stderr, "Error: PursuitLayer requires incoming connections to be one-to-one.\n"); abort(); } #ifdef DEBUG_OUTPUT int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); //printf("[%d]: HyPerLayr::recvSyn: neighbor=%d num=%d actv=%p this=%p conn=%p\n", rank, neighbor, numExtended, activity, this, conn); printf("[%d]: HyPerLayr::recvSyn: neighbor=%d num=%d actv=%p this=%p conn=%p\n", rank, 0, numExtended, activity, this, conn); fflush(stdout); #endif // DEBUG_OUTPUT const int numExtended = activity->numItems; for (int kPre = 0; kPre < numExtended; kPre++) { float a = activity->data[kPre]; if (a == 0.0f) continue; PVPatch * weights = conn->getWeights(kPre, arborID); // WARNING - assumes every value in weights maps into a valid value in GSyn // - assumes patch stride sf is 1 int nk = conn->fPatchSize() * weights->nx; int ny = weights->ny; int sy = conn->getPostNonextStrides()->sy; // stride in layer int syw = conn->yPatchStride(); // stride in patch pvdata_t * gSynPatchHead = this->getChannel(conn->getChannel()); pvdata_t * gSynPatchStart = gSynPatchHead + conn->getGSynPatchStart(kPre, arborID); pvwdata_t * data = conn->get_wData(arborID,kPre); for (int y = 0; y < ny; y++) { (conn->accumulateFunctionPointer)(nk, gSynPatchStart + y*sy, a, data + y*syw, NULL); } } // Set |w(:,:,f)|^2. Since this is a one-to-one connection with one presynaptic feature, // only have to do once for each feature of a single (x,y) site and then copy. int nxp = conn->xPatchSize(); int nyp = conn->yPatchSize(); int nfp = conn->fPatchSize(); int num_weights = nxp*nyp*nfp; assert(zUnitCellSize(pre->getXScale(), getXScale())==1); assert(zUnitCellSize(pre->getYScale(), getYScale())==1); assert(conn->getNumDataPatches()==1); for (int kf=0; kf<nfp; kf++) { pvwdata_t * weight = conn->get_wDataHead(arborID, 0); pvdata_t sum = 0.0; for (int k=0; k<num_weights; k+=nfp) { pvwdata_t w = weight[k + kf]; // Assumes stride in features is 1. //TODO-CER-2014.4.4 - convert weights sum += w*w; } wnormsq[kf] = sum; } pvdata_t * gSynStart = GSyn[conn->getChannel()]; int nx = getLayerLoc()->nx; int ny = getLayerLoc()->ny; int nxy = nx*ny; // TODO: Can I compute energyDropsBestFeature and minLocationsBestFeature without storing all the energyDrops and minimumLocations? for (int kxy=0; kxy<nxy; kxy++) { for (int kf=0; kf<nfp; kf++) { int k=kxy*nfp+kf; // Assumes stride in features is 1. minimumLocations[k] = gSynStart[k]/wnormsq[kf]; energyDrops[k] = -gSynStart[k]*minimumLocations[k]/2; } } for (int kxy=0; kxy<nxy; kxy++) { minFeatures[kxy] = -1; energyDropsBestFeature[kxy] = FLT_MAX; int index0 = kxy*nfp; // assumes stride in features is 1. if (foundFeatures[kxy]>=0) { energyDropsBestFeature[kxy] = energyDrops[kxy*nfp+foundFeatures[kxy]]; minFeatures[kxy] = foundFeatures[kxy]; } else { for (int kf=0; kf<nfp; kf++) { if (energyDrops[index0+kf] < energyDropsBestFeature[kxy]) { minFeatures[kxy] = kf; energyDropsBestFeature[kxy] = energyDrops[index0+kf]; } } } } for (int kxy=0; kxy<nxy; kxy++) { assert(minFeatures[kxy]>=0 && minFeatures[kxy]<nfp); int baseindex = kxy*nfp; minLocationsBestFeature[kxy] = minimumLocations[baseindex+minFeatures[kxy]]; } bool mask[nxy]; memset(mask, false, nxy*sizeof(*mask)); pvdata_t smallestEnergyDrop; int minloc; while (constrainMinima(), minloc = filterMinEnergies(mask, &smallestEnergyDrop), smallestEnergyDrop<FLT_MAX) { assert(foundFeatures[minloc]<0 || foundFeatures[minloc]==minFeatures[minloc]); foundFeatures[minloc] = minFeatures[minloc]; gSynSparse[minloc] += minLocationsBestFeature[minloc]; if (gSynSparse[minloc] < 1e-4) { gSynSparse[minloc]=0; foundFeatures[minloc] = -1; } int minlocx = kxPos(minloc,nx,ny,1); int maskstartx = minlocx-(nxp-1); if (maskstartx<0) maskstartx=0; int maskstopx = minlocx+nxp; if (maskstopx>nx) maskstopx=nx; int minlocy = kyPos(minloc,nx,ny,1); int maskstarty = minlocy-(nyp-1); if (maskstarty<0) maskstarty=0; int maskstopy = minlocy+nyp; if (maskstopy>ny) maskstopy=ny; for (int ky=maskstarty; ky<maskstopy; ky++) { for (int kx=maskstartx; kx<maskstopx; kx++) { mask[kIndex(kx,ky,0,nx,ny,1)]=true; } } } recvsyn_timer->stop(); updateReady = true; return 0; }
/* ** decrementYScale ** Decreases the yScale to yScale/2 */ float ofxOscilloscope::decrementYScale() { setYScale(getYScale() / 2); return getYScale(); }
/* ** plot ** Plots the data in the buffer */ void ofxOscilloscope::plot(){ // Legend Background ofEnableAlphaBlending(); ofSetColor(_backgroundColor); ofPoint legendMax = ofPoint(_min.x + _legendWidth, _max.y); ofRect(ofRectangle(_min, legendMax)); ofDisableAlphaBlending(); for (int i=0; i<_scopePlot.getNumVariables(); i++) { // Legend Text ofSetColor(_scopePlot.getVariableColor(i)); _legendFont.drawString(getVariableName(i), _min.x + _legendPadding, _min.y + _legendPadding + _textSpacer*(i+1)); } // Sets the zero line width when called before plot() ofSetLineWidth(_outlineWidth); // Plot the Data _scopePlot.plot(); ofSetColor(_outlineColor); ofSetLineWidth(_outlineWidth); ofEnableAlphaBlending(); // Legend outline ofLine(_min.x, _min.y, _min.x, _max.y); ofLine(_min.x, _max.y, _min.x + _legendWidth, _max.y); ofLine(_min.x + _legendWidth, _max.y, _min.x + _legendWidth, _min.y); ofLine(_min.x + _legendWidth, _min.y, _min.x, _min.y); // Scope outline //ofLine(_min.x, _min.y, _min.x, _max.y); ofLine(_min.x + _legendWidth, _max.y, _max.x, _max.y); ofLine(_max.x, _max.y, _max.x, _min.y); ofLine(_max.x, _min.y, _min.x + _legendWidth, _min.y); // Timescale _legendFont.drawString(ofToString(_scopePlot.getTimeWindow()) + " sec," + " yScale=" + ofToString(getYScale()) + ", yOffset=" + ofToString(getYOffset(), 1), _min.x + _legendWidth + _legendPadding, _max.y - _legendPadding); ofDisableAlphaBlending(); }
/* ** incrementYScale ** Increases the yScale to yScale*2 */ float ofxOscilloscope::incrementYScale() { setYScale(getYScale() * 2); return getYScale(); }