/*This method does the three steps involved in initializing weights. Subclasses usually don't need to override this method. * Instead they should override calcWeights to do their own type of weight initialization. * * For KernelConns (i.e., sharedWeights=true), patches should be NULL. * */ int InitWeights::initializeWeights(PVPatch *** patches, pvwdata_t ** dataStart, double * timef /*default NULL*/) { PVParams * inputParams = callingConn->getParent()->parameters(); int numPatches = callingConn->getNumDataPatches(); if (inputParams->present(callingConn->getName(), "initFromLastFlag")) { if (callingConn->getParent()->columnId()==0) { fprintf(stderr, "Connection \"%s\": initFromLastFlag is obsolete.\n", callingConn->getName()); } if (inputParams->value(callingConn->getName(), "initFromLastFlag")) { if (callingConn->getParent()->columnId()==0) { fprintf(stderr, "Instead, use weightInitType=\"FileWeight\" or set HyPerCol initializeFromCheckpointDir and set initializeFromCheckpointFlag to true\n"); } MPI_Barrier(callingConn->getParent()->icCommunicator()->communicator()); exit(EXIT_FAILURE); } } if (weightParams->getFilename() != NULL && weightParams->getFilename()[0]) { readWeights(patches, dataStart, numPatches, weightParams->getFilename(), timef); } else { initRNGs(patches==NULL); calcWeights(); } // filename != null int successFlag = zeroWeightsOutsideShrunkenPatch(patches); if (successFlag != PV_SUCCESS) { fprintf(stderr, "Failed to zero annulus around shrunken patch for %s! Exiting...\n", callingConn->getName()); exit(PV_FAILURE); } return PV_SUCCESS; }
matrix *mi(matrix *m, int n, int k, int g) { //printf("before mi\n"); matrix *mi; double r[g*((m->rows)-g)]; //AM: // mi = new_matrix(m->rows, m->rows); mi = new_matrix(g, ((m->rows)-g)); //AM: this is the returned matrix mi: //mi[i][j] is the mi between response vec m[i][] i=0,...,g-1 //and predictor vec m[j][] where j=g,...,m->rows int *knots; knots = (int *)malloc((n + k + 1) * sizeof(int)); calcKnot(knots, n, k); /*int l; for (l = 0; l < n + k + 1; ++l) printf("%d\n", knots[l]); */ //printf("before p\n"); matrix *w; w = calcWeights(m, n, k, knots); // print_matrix(w); // printf("w1: %d, %d\n", w->rows, w->cols); //printf("p1: %d, %d\n", p->rows, p->cols); //printf("before e\n"); //here matrix *e; e = entropy(w, m->cols, n); // print_matrix(e); //printf("before e2\n"); matrix *e2; e2 = entropy2(w, m->cols, n, g); // print_matrix(e2); int i,j; //AM: //for (i = 0; i < mi->rows; ++i) { for (i = 0; i < g; ++i) { for (j = g; j < (m->rows) ; ++j) { mi->m[i][j-g] = e->m[i][0] + e->m[j][0] - e2->m[i][j]; // Rprintf("[i,j,mi] = %d %d %lf\n", i, j, mi->m[i][j]); } } //} // print_matrix(mi); free(knots); free_matrix(w); free_matrix(e); free_matrix(e2); return mi; }
// Override this function to calculate weights over all patches. // The default loops over arbors and data patches, and calls calcWeights(dataStart, dataPatchIndex, arborId) int InitWeights::calcWeights() { int numArbors = callingConn->numberOfAxonalArborLists(); int numPatches = callingConn->getNumDataPatches(); for (int arbor = 0; arbor < numArbors; arbor++) { for (int dataPatchIndex = 0; dataPatchIndex < numPatches; dataPatchIndex++) { int successFlag = calcWeights( callingConn->get_wDataHead(arbor, dataPatchIndex), dataPatchIndex, arbor); if (successFlag != PV_SUCCESS) { pvError().printf("Failed to create weights for %s! Exiting...\n", callingConn->getName()); } } } return PV_SUCCESS; }
void StressMinimization::call( GraphAttributes& GA, NodeArray<NodeArray<double> >& shortestPathMatrix, NodeArray<NodeArray<double> >& weightMatrix) { // compute the initial layout if necessary if (!m_hasInitialLayout) { computeInitialLayout(GA); } const Graph& G = GA.constGraph(); // replace infinity distances by sqrt(n) and compute weights. // Note isConnected is only true during calls triggered by the // ComponentSplitterLayout. if (!m_componentLayout && !isConnected(G)) { replaceInfinityDistances(shortestPathMatrix, m_avgEdgeCosts * sqrt((double)(G.numberOfNodes()))); } // calculate the weights calcWeights(G, G.numberOfNodes() - 1, shortestPathMatrix, weightMatrix); // minimize the stress minimizeStress(GA, shortestPathMatrix, weightMatrix); }