예제 #1
0
bool
read_files (struct file_data filevec[], bool pretend_binary)
{
  int i;
  bool skip_test = text | pretend_binary;
  bool appears_binary = pretend_binary | sip (&filevec[0], skip_test);

  if (filevec[0].desc != filevec[1].desc)
    appears_binary |= sip (&filevec[1], skip_test | appears_binary);
  else
    {
      filevec[1].buffer = filevec[0].buffer;
      filevec[1].bufsize = filevec[0].bufsize;
      filevec[1].buffered = filevec[0].buffered;
    }
  if (appears_binary)
    {
      set_binary_mode (filevec[0].desc, true);
      set_binary_mode (filevec[1].desc, true);
      return true;
    }

  find_identical_ends (filevec);

  equivs_alloc = filevec[0].alloc_lines + filevec[1].alloc_lines + 1;
  if (PTRDIFF_MAX / sizeof *equivs <= equivs_alloc)
    xalloc_die ();
  equivs = xmalloc (equivs_alloc * sizeof *equivs);
  /* Equivalence class 0 is permanently safe for lines that were not
     hashed.  Real equivalence classes start at 1.  */
  equivs_index = 1;

  /* Allocate (one plus) a prime number of hash buckets.  Use a prime
     number between 1/3 and 2/3 of the value of equiv_allocs,
     approximately.  */
  for (i = 9; (size_t) 1 << i < equivs_alloc / 3; i++)
    continue;
  nbuckets = ((size_t) 1 << i) - prime_offset[i];
  if (PTRDIFF_MAX / sizeof *buckets <= nbuckets)
    xalloc_die ();
  buckets = zalloc ((nbuckets + 1) * sizeof *buckets);
  buckets++;

  for (i = 0; i < 2; i++)
    find_and_hash_each_line (&filevec[i]);

  filevec[0].equiv_max = filevec[1].equiv_max = equivs_index;

  free (equivs);
  free (buckets - 1);

  return false;
}
예제 #2
0
/*	REFERENCE: Keogh et al., Derivative Dynamic Time Warping.
	ADAPTATION: derivative of the 1st and last point calculated from 2 adj. points (instead of 3)
	EXAMPLE: seq = [s0,s1,s2], der = [d0,d1,d2]
		d0 = s1-s0
		d1 = ((s1-s0)+((s2-s0)/2))/2
		d2 = s2-s1
*/
void TExamplesDistance_DTW::getDerivatives(vector<float> &seq, vector<float> &der) const
{
  vector<float>::const_iterator sbegin(seq.begin()), send(seq.end()), sip(sbegin), si(sbegin), sin(sbegin+1);
  der.clear();
  if ( send - sbegin > 2 ) {
	  // d0 = s1-s0
	  der.push_back( (*sin)-(*si) );
	  si++;
	  sin++;
	  // d1, ...
	  for(; sin != send; sip++, si++, sin++) {
		der.push_back( ((*si)-(*sip)+((*sin)-(*sip))/2)/2 );
			
	  }
	  sip++;
	  si++;
	  // d2
	  der.push_back( (*si)-(*sip) );
  }
  else {
	  // 2 time points
	  if ( sin < send ) {
		  int diff = (*sin)-(*si);
		  der.push_back(diff);
		  der.push_back(diff);
	  }
	  // single time point -> NaN
	  else {
		  der.push_back(numeric_limits<float>::signaling_NaN());
	  }
  }
}
예제 #3
0
int
Locator_Repository::link_peers (Server_Info_Ptr base,
                                const CORBA::StringSeq p)
{
  sync_load ();
  CORBA::ULong len = base->peers.length();
  base->peers.length (len + p.length());
  for (CORBA::ULong i = 0; i < p.length(); i++)
    {
      base->peers[len + i] =  p[i];
      Server_Info *si;
      ACE_CString peer(p[i]);
      ACE_NEW_RETURN (si,
                      Server_Info (base->server_id, peer, base->is_jacorb, base),
                      -1);
      Server_Info_Ptr sip(si);
      servers ().bind (si->key_name_, sip);
      this->persistent_update (sip, true);
    }

  this->persistent_update (base, true);

  return 0;

}
예제 #4
0
파일: verif2_gsl.C 프로젝트: RhysU/queso
void solveSip(const uqFullEnvironmentClass& env)
{
  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Entering solveSip()..."
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 1 of 5: Instantiate the parameter space
  ////////////////////////////////////////////////////////
  unsigned int p = 2;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> paramSpace(env, "param_", p, NULL);
  uqGslVectorClass aVec(paramSpace.zeroVector());
  aVec[0] = 2.;
  aVec[1] = 5.;
  uqGslVectorClass xGiven(paramSpace.zeroVector());
  xGiven[0] = -1.;
  xGiven[1] =  7.;

  ////////////////////////////////////////////////////////
  // Step 2 of 5: Instantiate the parameter domain
  ////////////////////////////////////////////////////////
  //uqGslVectorClass paramMins    (paramSpace.zeroVector());
  //uqGslVectorClass paramMaxs    (paramSpace.zeroVector());
  //paramMins    [0] = -1.e+16;
  //paramMaxs    [0] =  1.e+16;
  //paramMins    [1] = -1.e+16;
  //paramMaxs    [1] =  1.e+16;
  //uqBoxSubsetClass<uqGslVectorClass,uqGslMatrixClass> paramDomain("param_",paramSpace,paramMins,paramMaxs);
  uqVectorSetClass<uqGslVectorClass,uqGslMatrixClass>* paramDomain = &paramSpace;

  ////////////////////////////////////////////////////////
  // Step 3 of 5: Instantiate the likelihood function object
  ////////////////////////////////////////////////////////
  unsigned int n = 5;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> dataSpace(env, "data_", n, NULL);
  
  uqGslVectorClass yMeanVec(dataSpace.zeroVector());
  double tmp = scalarProduct(aVec,xGiven);
  for (unsigned int i = 0; i < n; ++i) {
    yMeanVec[i] = tmp;
  }

  double sigmaEps = 2.1;
  uqGslMatrixClass yCovMat(dataSpace.zeroVector());
  tmp = sigmaEps*sigmaEps;
  for (unsigned int i = 0; i < n; ++i) {
    yCovMat(i,i) = tmp;
  }

  uqGslVectorClass ySamples(dataSpace.zeroVector());
  uqGaussianVectorRVClass<uqGslVectorClass,uqGslMatrixClass> yRv("y_", dataSpace, yMeanVec, yCovMat);
  yRv.realizer().realization(ySamples);

  double ySampleMean = 0.;
  for (unsigned int i = 0; i < n; ++i) {
    ySampleMean += ySamples[i];
  }
  ySampleMean /= ((double) n);

  struct likelihoodDataStruct likelihoodData;
  likelihoodData.aVec     = &aVec;
  likelihoodData.sigmaEps = sigmaEps;
  likelihoodData.ySamples = &ySamples;

  uqGenericScalarFunctionClass<uqGslVectorClass,uqGslMatrixClass>
    likelihoodFunctionObj("like_",
                          *paramDomain,
                          likelihoodRoutine,
                          (void *) &likelihoodData,
                          true); // routine computes [ln(function)]

  ////////////////////////////////////////////////////////
  // Step 4 of 5: Instantiate the inverse problem
  ////////////////////////////////////////////////////////
  uqGslVectorClass xPriorMeanVec(paramSpace.zeroVector());
  xPriorMeanVec[0] = 0.;
  xPriorMeanVec[1] = 0.;
  uqGslMatrixClass sigma0Mat(paramSpace.zeroVector());
  sigma0Mat(0,0) = 1.e-3;
  sigma0Mat(0,1) = 0.;
  sigma0Mat(1,0) = 0.;
  sigma0Mat(1,1) = 1.e-3;
  uqGslMatrixClass sigma0MatInverse(paramSpace.zeroVector());
  sigma0MatInverse = sigma0Mat.inverse();
  uqGaussianVectorRVClass<uqGslVectorClass,uqGslMatrixClass> priorRv("prior_", *paramDomain, xPriorMeanVec, sigma0MatInverse);

  uqGenericVectorRVClass <uqGslVectorClass,uqGslMatrixClass> postRv ("post_", paramSpace);

  uqStatisticalInverseProblemClass<uqGslVectorClass,uqGslMatrixClass> sip("sip_", NULL, priorRv, likelihoodFunctionObj, postRv);

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "In solveSip():"
                          << "\n  p                = " << p
                          << "\n  xGiven           = " << xGiven
                          << "\n  sigma0Mat        = " << sigma0Mat
                          << "\n  sigma0MatInverse = " << sigma0MatInverse
                          << "\n  aVec             = " << aVec
                          << "\n  n                = " << n
                          << "\n  sigmaEps         = " << sigmaEps
                          << "\n  yMeanVec         = " << yMeanVec
                          << "\n  yCovMat          = " << yCovMat
                          << "\n  ySamples         = " << ySamples
                          << "\n  ySampleMean      = " << ySampleMean
                          << std::endl;
  }

  uqGslMatrixClass sigmaMatInverse(paramSpace.zeroVector());
  sigmaMatInverse = matrixProduct(aVec,aVec);
  sigmaMatInverse *= (((double) n)/sigmaEps/sigmaEps);
  sigmaMatInverse += sigma0Mat;
  uqGslMatrixClass sigmaMat(paramSpace.zeroVector());
  sigmaMat = sigmaMatInverse.inverse();

  uqGslVectorClass muVec(paramSpace.zeroVector());
  muVec = sigmaMat * aVec;
  muVec *= (((double) n) * ySampleMean)/sigmaEps/sigmaEps;

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "In solveSip():"
                          << "\n  muVec            = " << muVec
                          << "\n  sigmaMat         = " << sigmaMat
                          << "\n  sigmaMatInverse  = " << sigmaMatInverse
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 5 of 5: Solve the inverse problem
  ////////////////////////////////////////////////////////
  uqGslVectorClass initialValues(paramSpace.zeroVector());
  initialValues[0] = 25.;
  initialValues[1] = 25.;

  uqGslMatrixClass proposalCovMat(paramSpace.zeroVector());
  proposalCovMat(0,0) = 10.;
  proposalCovMat(0,1) = 0.;
  proposalCovMat(1,0) = 0.;
  proposalCovMat(1,1) = 10.;

  sip.solveWithBayesMetropolisHastings(NULL,initialValues,&proposalCovMat);

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Leaving solveSip()"
                          << std::endl;
  }

  return;
}
예제 #5
0
파일: verif5_gsl.C 프로젝트: EricDoug/queso
void solveSip(const uqFullEnvironmentClass& env, bool useML)
{
  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Entering solveSip()..."
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 1 of 5: Instantiate the parameter space
  ////////////////////////////////////////////////////////
  unsigned int p = 1;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> paramSpace(env, "param_", p, NULL);
  uqGslVectorClass bVec(paramSpace.zeroVector());
  bVec[0] = 0.045213;

  ////////////////////////////////////////////////////////
  // Step 2 of 5: Instantiate the parameter domain
  ////////////////////////////////////////////////////////
  //uqGslVectorClass paramMins    (paramSpace.zeroVector());
  //uqGslVectorClass paramMaxs    (paramSpace.zeroVector());
  //paramMins    [0] = -1.e+16;
  //paramMaxs    [0] =  1.e+16;
  //paramMins    [1] = -1.e+16;
  //paramMaxs    [1] =  1.e+16;
  //uqBoxSubsetClass<uqGslVectorClass,uqGslMatrixClass> paramDomain("param_",paramSpace,paramMins,paramMaxs);
  uqVectorSetClass<uqGslVectorClass,uqGslMatrixClass>* paramDomain = &paramSpace;

  ////////////////////////////////////////////////////////
  // Step 3 of 5: Instantiate the likelihood function object
  ////////////////////////////////////////////////////////
  unsigned int nAll = 100000;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> dataSpaceAll(env, "data_", nAll, NULL);

  double sigmaTotal = bVec[0]/2.;

  std::set<unsigned int> tmpSet;
  tmpSet.insert(env.subId());

  uqGslVectorClass ySamplesAll(dataSpaceAll.zeroVector());
  ySamplesAll.subReadContents("input/dataPoints",
                              "m",
                              tmpSet);

  unsigned int numCases = 5;
  std::vector<unsigned int> ns(numCases,0);
  ns[0] = 1;
  ns[1] = 10;
  ns[2] = 100;
  ns[3] = 500;
  ns[4] = 1000;

  for (unsigned int caseId = 0; caseId < numCases; ++caseId) {
    uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> dataSpace(env, "data_", ns[caseId], NULL);
    uqGslVectorClass ySamples(dataSpace.zeroVector());
    for (unsigned int i = 0; i < ns[caseId]; ++i) {
      ySamples[i] = ySamplesAll[i];
    }

    struct likelihoodDataStruct likelihoodData;
    likelihoodData.bVec       = &bVec;
    likelihoodData.sigmaTotal = sigmaTotal;
    likelihoodData.ySamples   = &ySamples;

    uqGenericScalarFunctionClass<uqGslVectorClass,uqGslMatrixClass>
      likelihoodFunctionObj("like_",
                            *paramDomain,
                            likelihoodRoutine,
                            (void *) &likelihoodData,
                            true); // routine computes [ln(function)]

    ////////////////////////////////////////////////////////
    // Step 4 of 5: Instantiate the inverse problem
    ////////////////////////////////////////////////////////
    uqUniformVectorRVClass<uqGslVectorClass,uqGslMatrixClass> priorRv("prior_", *paramDomain);

    uqGenericVectorRVClass<uqGslVectorClass,uqGslMatrixClass> postRv ("post_", paramSpace);

    char prefixStr[16+1];
    sprintf(prefixStr,"sip%d_",caseId+1);
    uqStatisticalInverseProblemClass<uqGslVectorClass,uqGslMatrixClass> sip(prefixStr, NULL, priorRv, likelihoodFunctionObj, postRv);
    if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
      *env.subDisplayFile() << "In solveSip():"
                            << "\n  caseId     = " << caseId
                            << "\n  prefixStr  = " << prefixStr
                            << "\n  p          = " << p
                            << "\n  bVec       = " << bVec
                            << "\n  ns[caseId] = " << ns[caseId]
                            << "\n  sigmaTotal = " << sigmaTotal
                            << "\n  ySamples   = " << ySamples
                            << "\n  useML      = " << useML
                            << std::endl;
    }

    ////////////////////////////////////////////////////////
    // Step 5 of 5: Solve the inverse problem
    ////////////////////////////////////////////////////////
    uqGslVectorClass initialValues(paramSpace.zeroVector());
    initialValues[0] = 0.;

    uqGslMatrixClass proposalCovMat(paramSpace.zeroVector());
    proposalCovMat(0,0) = 1.;

    if (useML) {
      sip.solveWithBayesMLSampling();
    }
    else {
      sip.solveWithBayesMetropolisHastings(NULL,initialValues,&proposalCovMat);
    }
  } // for caseId

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Leaving solveSip()"
                          << std::endl;
  }

  return;
}
예제 #6
0
파일: verif1_gsl.C 프로젝트: EricDoug/queso
void solveSip(const uqFullEnvironmentClass& env, bool useML)
{
  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Entering solveSip()..."
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 1 of 5: Instantiate the parameter space
  ////////////////////////////////////////////////////////
  unsigned int p = 1;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> paramSpace(env, "param_", p, NULL);
  uqGslVectorClass aVec(paramSpace.zeroVector());
  aVec[0] = 126831.7;
  uqGslVectorClass bVec(paramSpace.zeroVector());
  bVec[0] = 112136.1;

  ////////////////////////////////////////////////////////
  // Step 2 of 5: Instantiate the parameter domain
  ////////////////////////////////////////////////////////
  //uqGslVectorClass paramMins    (paramSpace.zeroVector());
  //uqGslVectorClass paramMaxs    (paramSpace.zeroVector());
  //paramMins    [0] = -1.e+16;
  //paramMaxs    [0] =  1.e+16;
  //paramMins    [1] = -1.e+16;
  //paramMaxs    [1] =  1.e+16;
  //uqBoxSubsetClass<uqGslVectorClass,uqGslMatrixClass> paramDomain("param_",paramSpace,paramMins,paramMaxs);
  uqVectorSetClass<uqGslVectorClass,uqGslMatrixClass>* paramDomain = &paramSpace;

  ////////////////////////////////////////////////////////
  // Step 3 of 5: Instantiate the likelihood function object
  ////////////////////////////////////////////////////////
  unsigned int n = 400;
  uqVectorSpaceClass<uqGslVectorClass,uqGslMatrixClass> dataSpace(env, "data_", n, NULL);

  double sigmaTotal = 4229.55;

  std::set<unsigned int> tmpSet;
  tmpSet.insert(env.subId());

  uqGslVectorClass ySamples(dataSpace.zeroVector());
  ySamples.subReadContents("input/dataPoints",
                           "m",
                            tmpSet);

  struct likelihoodDataStruct likelihoodData;
  likelihoodData.aVec       = &aVec;
  likelihoodData.bVec       = &bVec;
  likelihoodData.sigmaTotal = sigmaTotal;
  likelihoodData.ySamples   = &ySamples;

  uqGenericScalarFunctionClass<uqGslVectorClass,uqGslMatrixClass>
    likelihoodFunctionObj("like_",
                          *paramDomain,
                          likelihoodRoutine,
                          (void *) &likelihoodData,
                          true); // routine computes [ln(function)]

  ////////////////////////////////////////////////////////
  // Step 4 of 5: Instantiate the inverse problem
  ////////////////////////////////////////////////////////
  uqUniformVectorRVClass<uqGslVectorClass,uqGslMatrixClass> priorRv("prior_", *paramDomain);

  uqGenericVectorRVClass<uqGslVectorClass,uqGslMatrixClass> postRv ("post_", paramSpace);

  uqStatisticalInverseProblemClass<uqGslVectorClass,uqGslMatrixClass> sip("sip_", NULL, priorRv, likelihoodFunctionObj, postRv);

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "In solveSip():"
                          << "\n  p          = " << p
                          << "\n  aVec       = " << aVec
                          << "\n  bVec       = " << bVec
                          << "\n  n          = " << n
                          << "\n  sigmaTotal = " << sigmaTotal
                          << "\n  ySamples   = " << ySamples
                          << "\n  useML      = " << useML
                          << std::endl;
  }

  ////////////////////////////////////////////////////////
  // Step 5 of 5: Solve the inverse problem
  ////////////////////////////////////////////////////////
  uqGslVectorClass initialValues(paramSpace.zeroVector());
  initialValues[0] = 0.;

  uqGslMatrixClass proposalCovMat(paramSpace.zeroVector());
  proposalCovMat(0,0) = 1.;

  if (useML) {
    sip.solveWithBayesMLSampling();
  }
  else {
    sip.solveWithBayesMetropolisHastings(NULL,initialValues,&proposalCovMat);
  }

  if ((env.subDisplayFile()) && (env.displayVerbosity() >= 2)) {
    *env.subDisplayFile() << "Leaving solveSip()"
                          << std::endl;
  }

  return;
}