Esempio n. 1
0
int testioparams(PV_Init* initObj, int rank) {
   initObj->resetState();
   // Ignore -r and -c switches
   initObj->setRestartFlag(false);
   initObj->setCheckpointReadDir(NULL);
   HyPerCol * hc = build(initObj, NULL, 0);
   if (hc == NULL) {
      pvError().printf("testioparams error: unable to build HyPerCol.\n");
   }
   int status = hc->run(); // Needed to generate pv.params file
   if (status != PV_SUCCESS) {
      pvError().printf("testioparams error: run to generate pv.params file failed.\n");
   }
   const char * paramsfile = hc->getPrintParamsFilename();
   std::string paramsfileString = paramsfile;
   if (paramsfile[0]!='/') {
      const char * outputPath = hc->getOutputPath();
      paramsfileString.insert(0, "/");
      paramsfileString.insert(0, outputPath);
   }
   delete hc;

   initObj->setParams(paramsfileString.c_str());
   if (rank==0) {
      pvInfo().printf("Running --testioparams with effective command line\n");
      initObj->printState();
   }
   status = rebuildandrun(initObj, NULL, &assertAllZeroes, NULL, 0);
   return status;
}
Esempio n. 2
0
int testioparams(PV_Init* initObj, int rank) {
   PV_Arguments * arguments = initObj->getArguments();
   arguments->resetState();
   // Ignore -r and -c switches
   arguments->setRestartFlag(false);
   arguments->setCheckpointReadDir(NULL);
   initObj->initialize();
   HyPerCol * hc = build(initObj, NULL, 0);
   if (hc == NULL) {
      fprintf(stderr, "testioparams error: unable to build HyPerCol.\n");
      exit(EXIT_FAILURE);
   }
   int status = hc->run(); // Needed to generate pv.params file
   if (status != PV_SUCCESS) {
      fprintf(stderr, "testioparams error: run to generate pv.params file failed.\n");
      exit(EXIT_FAILURE);
   }
   const char * paramsfile = hc->getPrintParamsFilename();
   std::string paramsfileString = paramsfile;
   if (paramsfile[0]!='/') {
      const char * outputPath = hc->getOutputPath();
      paramsfileString.insert(0, "/");
      paramsfileString.insert(0, outputPath);
   }
   delete hc;

   arguments->setParamsFile(paramsfileString.c_str());
   if (rank==0) {
      printf("%s --testioparams running PetaVision with arguments\n", arguments->getProgramName());
      arguments->printState();
   }
   status = rebuildandrun(initObj, NULL, &assertAllZeroes, NULL, 0);
   return status;
}
int StochasticReleaseTestProbe::computePValues(long int step, int f) {
   int status = PV_SUCCESS;
   assert(step >=0 && step < INT_MAX);
   int nf = getTargetLayer()->getLayerLoc()->nf;
   assert(f >= 0 && f < nf);
   int idx = (step-1)*nf + f;
   pvwdata_t wgt = conn->get_wDataStart(0)[f*(nf+1)]; // weights should be one-to-one weights

   HyPerLayer * pre = conn->preSynapticLayer();
   const pvdata_t * preactPtr = pre->getLayerData();
   const PVLayerLoc * preLoc = pre->getLayerLoc();
   const int numPreNeurons = pre->getNumNeurons();
   bool found=false;
   pvdata_t preact = 0.0f;
   for (int n=f; n<numPreNeurons; n+=nf) {
      int nExt = kIndexExtended(n, preLoc->nx, preLoc->ny, preLoc->nf, preLoc->halo.lt, preLoc->halo.rt, preLoc->halo.dn, preLoc->halo.up);
      pvdata_t a = preactPtr[nExt];
      if (a!=0.0f) {
         if (found) {
            assert(preact==a);
         }
         else {
            found = true;
            preact = a;
         }
      }
   }
   preact *= getParent()->getDeltaTime();
   if (preact < 0.0f) preact = 0.0f;
   if (preact > 1.0f) preact = 1.0f;

   const PVLayerLoc * loc = getTargetLayer()->getLayerLoc();
   const pvdata_t * activity = getTargetLayer()->getLayerData();
   int nnzf = 0;
   const int numNeurons = getTargetLayer()->getNumNeurons();
   for (int n=f; n<numNeurons; n+=nf) {
      int nExt = kIndexExtended(n, loc->nx, loc->ny, loc->nf, loc->halo.lt, loc->halo.rt, loc->halo.dn, loc->halo.up);
      assert(activity[nExt]==0 || activity[nExt]==wgt);
      if (activity[nExt]!=0) nnzf++;
   }
   HyPerLayer * l = getTargetLayer();
   HyPerCol * hc = l->getParent();
   MPI_Allreduce(MPI_IN_PLACE, &nnzf, 1, MPI_INT, MPI_SUM, hc->icCommunicator()->communicator());
   if (hc->columnId()==0) {
      const int neuronsPerFeature = l->getNumGlobalNeurons()/nf;
      double mean = preact * neuronsPerFeature;
      double stddev = sqrt(neuronsPerFeature*preact*(1-preact));
      double numdevs = (nnzf-mean)/stddev;
      pvalues[idx] = erfc(fabs(numdevs)/sqrt(2));
      fprintf(outputstream->fp, "    Feature %d, nnz=%5d, expectation=%7.1f, std.dev.=%5.1f, discrepancy of %f deviations, p-value %f\n",
              f, nnzf, mean, stddev, numdevs, pvalues[idx]);
   }
   assert(status==PV_SUCCESS);
   return status;
}
int main(int argc, char * argv[])
{
   int status = 0;

   int rank=0;
   PV_Init* initObj = new PV_Init(&argc, &argv, false/*allowUnrecognizedArguments*/);

   PV_Arguments * arguments = initObj->getArguments();
   if (arguments->getParamsFile() != NULL) {
      if (rank==0) {
         fprintf(stderr, "%s does not take -p as an option.  Instead the necessary params file is hard-coded.\n", argv[0]);
      }
      MPI_Barrier(MPI_COMM_WORLD);
      exit(EXIT_FAILURE);
   }

   arguments->setParamsFile("input/test_border_activity.params");

   initObj->initialize();
   HyPerCol * hc = new HyPerCol("column", initObj);

   const char * imageLayerName = "test_border_activity image";
   const char * retinaLayerName = "test_border_activity retina";
   const char * l1LayerName = "test_border_activity layer";

   Image * image   = new Image(imageLayerName, hc); assert(image);
   Retina * retina = new Retina(retinaLayerName, hc);           assert(retina);
   ANNLayer * l1     = new ANNLayer(l1LayerName, hc);           assert(l1);

   HyPerConn * conn1 = new HyPerConn("test_border_activity connection 1", hc);
   assert(conn1);
   HyPerConn * conn2 = new HyPerConn("test_border_activity connection 2", hc);
   assert(conn2);
   
#ifdef DEBUG_OUTPUT
   PointProbe * p1 = new PointProbe( 0,  0,  0, "L1 (0,0,0):");
   PointProbe * p2 = new PointProbe(32, 32, 32, "L1 (32,32,0):");
   l1->insertProbe(p1);
   l1->insertProbe(p2);
#endif

   // run the simulation
   hc->run();

   status = check_activity(l1);

   delete hc;

   delete initObj;

   return status;
}
int main(int argc, char* argv[])
{
   int status = 0;

   PV_Init* initObj = new PV_Init(&argc, &argv);
   initObj->initialize(argc, argv);

   // create the managing hypercolumn
   //
   HyPerCol* hc = new HyPerCol("test_constant_input column", argc, argv, initObj);

   // create the image
   //
   TestImage * image = new TestImage("test_constant_input image", hc);

   // create the layers
   //
   HyPerLayer * retina = new Retina("test_constant_input retina", hc);

   // create the connections
   //
   HyPerConn * conn = new HyPerConn("test_constant_input connection", hc);
   const int nxp = conn->xPatchSize();
   const int nyp = conn->yPatchSize();
   const PVLayerLoc * imageLoc = image->getLayerLoc();
   const PVLayerLoc * retinaLoc = image->getLayerLoc();
   const int nfPre = imageLoc->nf;
    
   float sumOfWeights = (float) (nxp*nyp*nfPre);
   if (imageLoc->nx > retinaLoc->nx) { sumOfWeights *= imageLoc->nx/retinaLoc->nx;}
   if (imageLoc->ny > retinaLoc->ny) { sumOfWeights *= imageLoc->ny/retinaLoc->ny;}
   
   hc->run();

   const int rank = hc->columnId();
#ifdef DEBUG_OUTPUT
   printf("[%d]: column: ", rank);
   printLoc(hc->getImageLoc());
   printf("[%d]: image : ", rank);
   printLoc(image->getImageLoc());
   printf("[%d]: retina: ", rank);
   printLoc(*retina->getLayerLoc());
   printf("[%d]: l1    : ", rank);
   printLoc(*l1->getLayerLoc());
#endif

   status = checkLoc(hc, image->getLayerLoc());
   if (status != PV_SUCCESS) {
      fprintf(stderr, "[%d]: test_constant_input: ERROR in image loc\n", rank);
      exit(status);
   }

   status = checkLoc(hc, retina->getLayerLoc());
   if (status != PV_SUCCESS) {
      fprintf(stderr, "[%d]: test_constant_input: ERROR in retina loc\n", rank);
      exit(status);
   }

   status = checkInput(image->getLayerLoc(), image->getActivity(), image->getConstantVal(), true);
   if (status != PV_SUCCESS) {
      fprintf(stderr, "[%d]: test_constant_input: ERROR in image data\n", rank);
      exit(status);
   }

   float retinaVal = sumOfWeights * image->getConstantVal();

   status = checkInput(retina->getLayerLoc(), retina->getActivity(), retinaVal, false);
   if (status != 0) {
      fprintf(stderr, "[%d]: test_constant_input: ERROR in retina data\n", rank);
      exit(status);
   }

   status = checkInput(retina->getLayerLoc(), retina->getLayerData(), retinaVal, true);
   if (status != 0) {
      fprintf(stderr, "[%d]: test_constant_input: ERROR in retina data\n", rank);
      exit(status);
   }

   delete hc;
   delete initObj;

   return status;
}
int main(int argc, char * argv[]) {
   PV_Init* initObj = new PV_Init(&argc, &argv, false/*allowUnrecognizedArguments*/);
   InterColComm * icComm = new InterColComm(initObj->getArguments());

   PV_Arguments * arguments = initObj->getArguments();
   if (arguments->getParamsFile() != NULL) {
      int rank = icComm->globalCommRank();
      if (rank==0) {
         fprintf(stderr, "%s does not take -p as an option.  Instead the necessary params file is hard-coded.\n", arguments->getProgramName());
      }
      MPI_Barrier(MPI_COMM_WORLD);
      exit(EXIT_FAILURE);
   }

   arguments->setParamsFile("input/TransposeHyPerConnTest.params");

   initObj->initialize();

   // Don't call buildandrun because it will delete hc before returning. (I could use the customexit hook)
   HyPerCol * hc = build(initObj);
   hc->run(); // Weight values are initialized when run calls allocateDataStructures

   int status = PV_SUCCESS;

   HyPerConn * originalMap = NULL;
   TransposeConn * transpose = NULL;
   TransposeConn * transposeOfTranspose = NULL;

   BaseConnection * baseConn;
   baseConn = hc->getConnFromName("Original Map for One to One Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for One to One Test of TransposeConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for One to One Test of TransposeConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "One-to-one case, TransposeConn");

   baseConn = hc->getConnFromName("Original Map for Many to One Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for Many to One Test of TransposeConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for Many to One Test of TransposeConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "Many-to-one case, TransposeConn");

   baseConn = hc->getConnFromName("Original Map for One to Many Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for One to Many Test of TransposeConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for One to Many Test of TransposeConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "One-to-many case, TransposeConn");

   baseConn = hc->getConnFromName("Original Map for One to One Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for One to One Test of FeedbackConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for One to One Test of FeedbackConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "One-to-one case, FeedbackConn");

   baseConn = hc->getConnFromName("Original Map for Many to One Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for Many to One Test of FeedbackConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for Many to One Test of FeedbackConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "Many-to-one case, FeedbackConn");

   baseConn = hc->getConnFromName("Original Map for One to Many Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for One to Many Test of FeedbackConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for One to Many Test of FeedbackConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "One-to-many case, FeedbackConn");

   delete hc;
   delete initObj;
   return status;
}
int main(int argc, char * argv[]) {
   PV_Init* initObj = new PV_Init(&argc, &argv);

   InterColComm * icComm = new InterColComm(argc, argv);
   PVParams * params = new PVParams("input/TransposeHyPerConnTest.params", 2*(INITIAL_LAYER_ARRAY_SIZE+INITIAL_CONNECTION_ARRAY_SIZE), icComm);

   initObj->initialize(params, icComm);

   // Don't call buildandrun because it will delete hc before returning. (I could use the customexit hook)
   HyPerCol * hc = build(argc, argv, initObj);
   hc->run(); // Weight values are initialized when run calls allocateDataStructures

   int status = PV_SUCCESS;

   HyPerConn * originalMap = NULL;
   TransposeConn * transpose = NULL;
   TransposeConn * transposeOfTranspose = NULL;

   BaseConnection * baseConn;
   baseConn = hc->getConnFromName("Original Map for One to One Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for One to One Test of TransposeConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for One to One Test of TransposeConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "One-to-one case, TransposeConn");

   baseConn = hc->getConnFromName("Original Map for Many to One Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for Many to One Test of TransposeConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for Many to One Test of TransposeConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "Many-to-one case, TransposeConn");

   baseConn = hc->getConnFromName("Original Map for One to Many Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for One to Many Test of TransposeConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for One to Many Test of TransposeConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "One-to-many case, TransposeConn");

   baseConn = hc->getConnFromName("Original Map for One to One Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for One to One Test of FeedbackConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for One to One Test of FeedbackConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "One-to-one case, FeedbackConn");

   baseConn = hc->getConnFromName("Original Map for Many to One Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for Many to One Test of FeedbackConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for Many to One Test of FeedbackConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "Many-to-one case, FeedbackConn");

   baseConn = hc->getConnFromName("Original Map for One to Many Test");
   originalMap = dynamic_cast<HyPerConn *>(baseConn);
   //assert(originalMap->usingSharedWeights());
   transpose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose for One to Many Test of FeedbackConn"));
   transposeOfTranspose = dynamic_cast<TransposeConn *>(hc->getConnFromName("Transpose of Transpose for One to Many Test of FeedbackConn"));
   status = testTransposeOfTransposeWeights(originalMap, transpose, transposeOfTranspose, "One-to-many case, FeedbackConn");

   delete hc;
   delete initObj;
   return status;
}
int StochasticReleaseTestProbe::outputState(double timed) {
   // Set conn.  Can't do that in initStochasticReleaseTestProbe because we need to search for a conn with the given post, and connections' postLayerName is not necessarily set.
   if (conn==NULL) {
      HyPerCol * hc = getTargetLayer()->getParent();
      int numconns = hc->numberOfConnections();
      for (int c=0; c<numconns; c++) {
         if (!strcmp(hc->getConnection(c)->getPostLayerName(),getTargetLayer()->getName())) {
            assert(conn==NULL); // Only one connection can go to this layer for this probe to work
            BaseConnection * baseConn = hc->getConnection(c);
            conn = dynamic_cast<HyPerConn *>(baseConn);
         }
      }
      assert(conn!=NULL);
   }
   assert(conn->numberOfAxonalArborLists()==1);
   assert(conn->xPatchSize()==1);
   assert(conn->yPatchSize()==1);
   assert(conn->getNumDataPatches()==conn->fPatchSize());
   int status = StatsProbe::outputState(timed);
   assert(status==PV_SUCCESS);
   HyPerLayer * l = getTargetLayer();
   HyPerCol * hc = l->getParent();
   int nf = l->getLayerLoc()->nf;
   if (timed>0.0) {
      for (int f=0; f < nf; f++) {
         if (computePValues(hc->getCurrentStep(), f)!=PV_SUCCESS) status = PV_FAILURE;
      }
      assert(status == PV_SUCCESS);
      if (hc->columnId()==0 && hc->simulationTime()+hc->getDeltaTime()/2>=hc->getStopTime()) {
         // This is the last timestep
         // sort the p-values and apply Holm-Bonferroni method since there is one for each timestep and each feature.
         long int num_steps = hc->getFinalStep() - hc->getInitialStep();
         long int N = num_steps * nf;
         qsort(pvalues, (size_t) N, sizeof(*pvalues), compar);
         while(N>0 && isnan(pvalues[N-1])) {
            N--;
         }
         for (long int k=0; k<N; k++) {
            if (pvalues[k]*(N-k)<0.05) {
               fprintf(stderr, "layer \"%s\" FAILED: p-value %ld out of %ld (ordered by size) with Holm-Bonferroni correction = %f\n", getTargetLayer()->getName(), k, N, pvalues[k]*(N-k));
               status = PV_FAILURE;
            }
         }
      }

   }
   assert(status==PV_SUCCESS);
   return status;
}