Exemplo n.º 1
0
unsigned int
SimulationModel<S_V,S_M,P_V,P_M,Q_V,Q_M>::computePEta(const Q_V& svdS_vec)
{
  unsigned int result = 0;
  if (m_optionsObj->m_ov.m_cdfThresholdForPEta <= 0.) {
    result = m_optionsObj->m_ov.m_p_eta;
  }
  else if (m_optionsObj->m_ov.m_cdfThresholdForPEta >= 1.) {
    for (unsigned int i = 0; i < svdS_vec.sizeLocal(); ++i) {
      if ((svdS_vec[i]/svdS_vec[0]) > m_optionsObj->m_ov.m_zeroRelativeSingularValue) {
        result++;
      }
    }
  }
  else {
    Q_V auxVec(svdS_vec);
    double auxSum = 0.;
    for (unsigned int i = 0; i < auxVec.sizeLocal(); ++i) {
      double auxTerm = auxVec[i];
      auxVec[i] = auxTerm * auxTerm;
      auxSum += auxVec[i];
    }
    for (unsigned int i = 0; i < auxVec.sizeLocal(); ++i) {
      auxVec[i] /= auxSum;
    }
    Q_V auxCumSum(m_m_space.zeroVector());
    auxCumSum[0] = auxVec[0];
    for (unsigned int i = 1; i < auxVec.sizeLocal(); ++i) {
      auxCumSum[i] = auxCumSum[i-1] + auxVec[i];
    }
    for (unsigned int i = 0; i < auxVec.sizeLocal(); ++i) {
      if (auxCumSum[i] < m_optionsObj->m_ov.m_cdfThresholdForPEta) {
        result++;
      }
    }
    result += 1;
  }

  return result;
}
Exemplo n.º 2
0
void compute(const QUESO::FullEnvironment& env, unsigned int numModes) {
  ////////////////////////////////////////////////////////
  // Step 1 of 5: Instantiate the parameter space
  ////////////////////////////////////////////////////////


#ifdef APPLS_MODAL_USES_CONCATENATION
  QUESO::VectorSpace<QUESO::GslVector, QUESO::GslMatrix>
    paramSpaceA(env, "paramA_", 2, NULL);
  QUESO::VectorSpace<QUESO::GslVector, QUESO::GslMatrix>
    paramSpaceB(env, "paramB_", 1, NULL);
#endif
  QUESO::VectorSpace<QUESO::GslVector, QUESO::GslMatrix>
    paramSpace(env, "param_", 3, NULL);

  ////////////////////////////////////////////////////////
  // Step 2 of 5: Instantiate the parameter domain
  ////////////////////////////////////////////////////////
#ifdef APPLS_MODAL_USES_CONCATENATION
  QUESO::GslVector paramMinsA(paramSpaceA.zeroVector());
  paramMinsA[0] = 0.;
  paramMinsA[1] = 0.;
  QUESO::GslVector paramMaxsA(paramSpaceA.zeroVector());
  paramMaxsA[0] = 3.;
  paramMaxsA[1] = 3.;
  QUESO::BoxSubset<QUESO::GslVector,QUESO::GslMatrix>
  
  paramDomainA("paramA_",paramSpaceA,paramMinsA,paramMaxsA);

  QUESO::GslVector paramMinsB(paramSpaceB.zeroVector());
  paramMinsB[0] = 0.;
  QUESO::GslVector paramMaxsB(paramSpaceB.zeroVector());
  paramMaxsB[0] = INFINITY;
  QUESO::BoxSubset<QUESO::GslVector,QUESO::GslMatrix>
    paramDomainB("paramB_",paramSpaceB,paramMinsB,paramMaxsB);

  QUESO::ConcatenationSubset<QUESO::GslVector,QUESO::GslMatrix>
    paramDomain("",paramSpace,paramDomainA,paramDomainB);
#else
  QUESO::GslVector paramMins(paramSpace.zeroVector());
  paramMins[0] = 0.;
  paramMins[1] = 0.;
  paramMins[2] = 0.;
  QUESO::GslVector paramMaxs(paramSpace.zeroVector());
  paramMaxs[0] = 3.;
  paramMaxs[1] = 3.;
  paramMaxs[2] = .3;
  QUESO::BoxSubset<QUESO::GslVector,QUESO::GslMatrix>
    paramDomain("param_",paramSpace,paramMins,paramMaxs);
#endif

  ////////////////////////////////////////////////////////
  // Step 3 of 5: Instantiate the likelihood function object
  ////////////////////////////////////////////////////////
  likelihoodRoutine_DataType likelihoodRoutine_Data;
 
  likelihoodRoutine_Data.numModes = numModes;
  QUESO::GenericScalarFunction<QUESO::GslVector,QUESO::GslMatrix>
    likelihoodFunctionObj("like_",
                          paramDomain,
                          likelihoodRoutine,
                          (void *) &likelihoodRoutine_Data,
                          true); // routine computes [-2.*ln(function)]
  
    ////////////////////////////////////////////////////////
  // Step 4 of 5: Instantiate the inverse problem
  ////////////////////////////////////////////////////////
#ifdef APPLS_MODAL_USES_CONCATENATION
  QUESO::UniformVectorRV<QUESO::GslVector,QUESO::GslMatrix>
    priorRvA("priorA_", paramDomainA);
 
  QUESO::GslVector alpha(paramSpaceB.zeroVector());
  alpha[0] = 3.;
  QUESO::GslVector beta(paramSpaceB.zeroVector());
  if (numModes == 1) {
    beta[0] = 0.09709133373799;
  }
  else {
    beta[0] = 0.08335837191688;
  }
  QUESO::InverseGammaVectorRV<QUESO::GslVector,QUESO::GslMatrix>
    priorRvB("priorB_", paramDomainB,alpha,beta);

  QUESO::ConcatenatedVectorRV<QUESO::GslVector,QUESO::GslMatrix>
    priorRv("prior_", priorRvA, priorRvB, paramDomain);
#else
  QUESO::UniformVectorRV<QUESO::GslVector,QUESO::GslMatrix>
    priorRv("prior_", paramDomain);
#endif

  QUESO::GenericVectorRV<QUESO::GslVector,QUESO::GslMatrix>
    postRv("post_", paramSpace);

  QUESO::StatisticalInverseProblem<QUESO::GslVector,QUESO::GslMatrix>
    ip("", NULL, priorRv, likelihoodFunctionObj, postRv);

  ////////////////////////////////////////////////////////
  // Step 5 of 5: Solve the inverse problem
  ////////////////////////////////////////////////////////
  ip.solveWithBayesMLSampling();

  ////////////////////////////////////////////////////////
  // Print some statistics
  ////////////////////////////////////////////////////////
  unsigned int numPosTotal = postRv.realizer().subPeriod();
  if (env.subDisplayFile()) {
    *env.subDisplayFile() << "numPosTotal = " << numPosTotal
                          << std::endl;
  }

  QUESO::GslVector auxVec(paramSpace.zeroVector());
  unsigned int numPosTheta1SmallerThan1dot5 = 0;
  for (unsigned int i = 0; i < numPosTotal; ++i) {
    postRv.realizer().realization(auxVec);
    if (auxVec[0] < 1.5) numPosTheta1SmallerThan1dot5++;
  }

  if (env.subDisplayFile()) {
    *env.subDisplayFile() << "numPosTheta1SmallerThan1dot5 = " << numPosTheta1SmallerThan1dot5
                          << ", ratio = " << ((double) numPosTheta1SmallerThan1dot5)/((double) numPosTotal)
                          << std::endl;
  }

  return;
}
Exemplo n.º 3
0
//------------------------------------------------------
//------------------------------------------------------
//------------------------------------------------------
void debug_hyst(const QUESO::FullEnvironment& env) {
  unsigned int numFloors = 4;
  unsigned int numTimeSteps = 401;

  std::vector<double> accel(numTimeSteps,0.);
  FILE *inp;
  inp = fopen("an.txt","r");
  unsigned int numObservations = 0;
  double tmpA;
  while (fscanf(inp,"%lf",&tmpA) != EOF) {
    UQ_FATAL_TEST_MACRO((numObservations >= accel.size()),
                        env.fullRank(),
                        "debug_hyst()",
                        "input file has too many lines");
    accel[numObservations] = tmpA;
    numObservations++;
  }
  UQ_FATAL_TEST_MACRO((numObservations != accel.size()),
                      env.fullRank(),
                      "debug_hyst()",
                      "input file has a smaller number of observations than expected");

  QUESO::VectorSpace<> floorSpace(env, "floor_", numFloors, NULL);

  QUESO::GslVector kVec(floorSpace.zeroVector());
  kVec[0] = 2.20e+7;
  kVec[1] = 2.00e+7;
  kVec[2] = 1.70e+7;
  kVec[3] = 1.45e+7;

  QUESO::GslVector rVec(floorSpace.zeroVector());
  rVec[0] = 0.1;
  rVec[1] = 0.1;
  rVec[2] = 0.1;
  rVec[3] = 0.1;

  QUESO::GslVector uVec(floorSpace.zeroVector());
  uVec[0] = 0.008;
  uVec[1] = 0.008;
  uVec[2] = 0.007;
  uVec[3] = 0.007;

  double rho   = 7.959e-1 ;//0.1976;
  double gamma = 2.500e-3 ; //0.0038;

  std::vector<double> t(numTimeSteps,0.);
  QUESO::SequenceOfVectors<> u     (floorSpace,numTimeSteps,""); // absolute displacement
  QUESO::SequenceOfVectors<> ud    (floorSpace,numTimeSteps,""); // velocity
  QUESO::SequenceOfVectors<> udd   (floorSpace,numTimeSteps,""); // acceleration
  QUESO::SequenceOfVectors<> resfor(floorSpace,numTimeSteps,""); // restoring force
  QUESO::SequenceOfVectors<> ru    (floorSpace,numTimeSteps,""); // relative displacement

  u.setPositionValues     (0,floorSpace.zeroVector());
  ud.setPositionValues    (0,floorSpace.zeroVector());
  udd.setPositionValues   (0,floorSpace.zeroVector());
  resfor.setPositionValues(0,floorSpace.zeroVector());
  ru.setPositionValues    (0,floorSpace.zeroVector());

  QUESO::GslVector massVec(floorSpace.zeroVector());
  massVec.cwSet(2.0e+4);

  hystereticModel(env,
                  massVec,
                  kVec,
                  rVec,
                  uVec,
                  rho,
                  gamma,
                  accel,
                  t, // output
                  u,
                  ud,
                  udd,
                  resfor,
                  ru);

  std::set<unsigned int> auxSet;
  auxSet.insert(0);

  // Writing some data to the file 'outputData/cpp_output.m'
  std::ofstream myFile;
  myFile.open ("outputData/cpp_output.m");

  // Write 't_cpp'
  myFile << "t_cpp = zeros(" << 1 << "," << numTimeSteps << ");\n"
          << "t_cpp = [";
  for (unsigned int j = 0; j < numTimeSteps; ++j) {
    myFile << t[j] << " ";
  }
  myFile << "];" << std::endl;

  // Write 'a_cpp'
  myFile << "a_cpp = zeros(" << 1 << "," << numTimeSteps << ");\n"
          << "a_cpp = [";
  for (unsigned int j = 0; j < numTimeSteps; ++j) {
    myFile << accel[j] << " ";
  }
  myFile << "];" << std::endl;

  QUESO::GslVector auxVec(floorSpace.zeroVector());

  // Write 'u_cpp'
  myFile << "u_cpp = zeros(" << numFloors << "," << numTimeSteps << ");\n"
          << "u_cpp = [";
  for (unsigned int i = 0; i < numFloors; ++i) {
    for (unsigned int j = 0; j < numTimeSteps; ++j) {
      u.getPositionValues(j,auxVec);
      myFile << auxVec[i] << " ";
    }
    myFile << std::endl;
  }
  myFile << "];" << std::endl;

  // Write 'ud_cpp'
  myFile << "ud_cpp = zeros(" << numFloors << "," << numTimeSteps << ");\n"
          << "ud_cpp = [";
  for (unsigned int i = 0; i < numFloors; ++i) {
    for (unsigned int j = 0; j < numTimeSteps; ++j) {
      ud.getPositionValues(j,auxVec);
      myFile << auxVec[i] << " ";
    }
    myFile << std::endl;
  }
  myFile << "];" << std::endl;

  // Write 'udd_cpp'
  myFile << "udd_cpp = zeros(" << numFloors << "," << numTimeSteps << ");\n"
          << "udd_cpp = [";
  for (unsigned int i = 0; i < numFloors; ++i) {
    for (unsigned int j = 0; j < numTimeSteps; ++j) {
      udd.getPositionValues(j,auxVec);
      myFile << auxVec[i] << " ";
    }
    myFile << std::endl;
  }
  myFile << "];" << std::endl;

  // Write 'resfor_cpp'
  myFile << "resfor_cpp = zeros(" << numFloors << "," << numTimeSteps << ");\n"
          << "resfor_cpp = [";
  for (unsigned int i = 0; i < numFloors; ++i) {
    for (unsigned int j = 0; j < numTimeSteps; ++j) {
      resfor.getPositionValues(j,auxVec);
      myFile << auxVec[i] << " ";
    }
    myFile << std::endl;
  }
  myFile << "];" << std::endl;

  // Write 'ru_cpp'
  myFile << "ru_cpp = zeros(" << numFloors << "," << numTimeSteps << ");\n"
          << "ru_cpp = [";
  for (unsigned int i = 0; i < numFloors; ++i) {
    for (unsigned int j = 0; j < numTimeSteps; ++j) {
      ru.getPositionValues(j,auxVec);
      myFile << auxVec[i] << " ";
    }
    myFile << std::endl;
  }
  myFile << "];" << std::endl;

  myFile.close();

  return;
}