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; }
void compute(const QUESO::FullEnvironment& env) { struct timeval timevalNow; gettimeofday(&timevalNow, NULL); std::cout << std::endl << "Beginning run of 'Hysteretic' example at " << ctime(&timevalNow.tv_sec); //------------------------------------------------------ // Step 1 of 5: Instantiate the parameter space //------------------------------------------------------ QUESO::VectorSpace<> paramSpaceA(env, "paramA_", 1, NULL); QUESO::VectorSpace<> paramSpaceB(env, "paramB_", 14, NULL); QUESO::VectorSpace<> paramSpace (env, "param_", 15, NULL); //------------------------------------------------------ // Step 2 of 5: Instantiate the parameter domain //------------------------------------------------------ QUESO::GslVector paramMinsA(paramSpaceA.zeroVector()); paramMinsA.cwSet(0); QUESO::GslVector paramMaxsA(paramSpaceA.zeroVector()); paramMaxsA.cwSet(5); QUESO::BoxSubset<> paramDomainA("paramA_",paramSpaceA,paramMinsA,paramMaxsA); QUESO::GslVector paramMinsB(paramSpaceB.zeroVector()); paramMinsB.cwSet(-INFINITY); QUESO::GslVector paramMaxsB(paramSpaceB.zeroVector()); paramMaxsB.cwSet( INFINITY); QUESO::BoxSubset<> paramDomainB("paramB_",paramSpaceB,paramMinsB,paramMaxsB); QUESO::ConcatenationSubset<> paramDomain("",paramSpace,paramDomainA,paramDomainB); //------------------------------------------------------ // Step 3 of 5: Instantiate the likelihood function object //------------------------------------------------------ std::cout << "\tInstantiating the Likelihood; calling internally the hysteretic model" << std::endl; Likelihood<> likelihood("like_", paramDomain); likelihood.floor.resize(4,NULL); unsigned int numTimeSteps = 401; for (unsigned int i = 0; i < 4; ++i) { likelihood.floor[i] = new std::vector<double>(numTimeSteps,0.); } likelihood.accel.resize(numTimeSteps,0.); FILE *inp; inp = fopen("an.txt","r"); unsigned int numObservations = 0; double tmpA; while (fscanf(inp,"%lf",&tmpA) != EOF) { likelihood.accel[numObservations] = tmpA; numObservations++; } numObservations=1; FILE *inp1_1; inp1_1=fopen("measured_data1_1.txt","r"); while (fscanf(inp1_1,"%lf",&tmpA) != EOF) { (*likelihood.floor[0])[numObservations]=tmpA; numObservations++; } numObservations=0; FILE *inp1_2; inp1_2=fopen("measured_data1_2.txt","r"); while (fscanf(inp1_2,"%lf",&tmpA) != EOF) { (*likelihood.floor[1])[numObservations]=tmpA; numObservations++; } numObservations=0; FILE *inp1_3; inp1_3=fopen("measured_data1_3.txt","r"); while (fscanf(inp1_3,"%lf",&tmpA) != EOF) { (*likelihood.floor[2])[numObservations]=tmpA; numObservations++; } numObservations=0; FILE *inp1_4; inp1_4=fopen("measured_data1_4.txt","r"); while (fscanf(inp1_4,"%lf",&tmpA) != EOF) { (*likelihood.floor[3])[numObservations]=tmpA; numObservations++; } //------------------------------------------------------ // Step 4 of 5: Instantiate the inverse problem //------------------------------------------------------ std::cout << "\tInstantiating the SIP" << std::endl; QUESO::UniformVectorRV<> priorRvA("priorA_", paramDomainA); QUESO::GslVector meanVec(paramSpaceB.zeroVector()); QUESO::GslVector diagVec(paramSpaceB.zeroVector()); diagVec.cwSet(0.6*0.6); QUESO::GslMatrix covMatrix(diagVec); QUESO::GaussianVectorRV<> priorRvB("priorB_", paramDomainB,meanVec,covMatrix); QUESO::ConcatenatedVectorRV<> priorRv("prior_", priorRvA, priorRvB, paramDomain); QUESO::GenericVectorRV<> postRv("post_", paramSpace); QUESO::StatisticalInverseProblem<> ip("", NULL, priorRv, likelihood, postRv); //------------------------------------------------------ // Step 5 of 5: Solve the inverse problem //------------------------------------------------------ std::cout << "\tSolving the SIP with Multilevel method" << std::endl; ip.solveWithBayesMLSampling(); gettimeofday(&timevalNow, NULL); std::cout << "Ending run of 'Hysteretic' example at " << ctime(&timevalNow.tv_sec) << std::endl; return; }