本文整理汇总了C++中Array1D::XSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Array1D::XSize方法的具体用法?C++ Array1D::XSize怎么用?C++ Array1D::XSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Array1D
的用法示例。
在下文中一共展示了Array1D::XSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/// Main program: MCMC inference of the ODE model parameters given data
int main(int argc, char *argv[])
{
// Pointer to posterior information
postAux* pinfo=new postAux;
// Read the xml tree
RefPtr<XMLElement> xmlTree=readXMLTree("lorenz.in.xml");
// Read the model specification and send them to the posterior information structure
readXMLModelInput(xmlTree,pinfo->modelparams, pinfo->modelparamnames, pinfo->modelauxparams);
// Read specific information needed by inference, e.g. data and the parameters to be inferred
readXMLDataInput(xmlTree,pinfo->data, pinfo->postparams,&(pinfo->noisetype));
// Number of MCMC steps
int nsteps;
// Array to hold the starting values of the chain
Array1D<double> chstart;
// Define the MCMC object
MCMC mchain(LogPosterior,(void*) pinfo);
// Read the xml file for MCMC-specific information
readXMLChainInput(xmlTree,&mchain, chstart, &nsteps,pinfo->chainParamInd,pinfo->priortype,pinfo->priorparam1,pinfo->priorparam2);
// Prepend the parameter names to the output file
FILE* f_out;
string filename=mchain.getFilename();
int chdim=chstart.XSize();
f_out = fopen(filename.c_str(),"w");
fprintf(f_out, "%s ","Step");
for(int i=0;i<chdim;i++)
fprintf(f_out, "%21s ",pinfo->modelparamnames(pinfo->chainParamInd(i)).c_str());
fprintf(f_out, "%24s %24s \n","Accept_prob","Log_posterior");
fclose(f_out);
// Set the flag
mchain.namesPrepended();
// Run the chain
mchain.runChain(nsteps, chstart);
return 0;
}
示例2: main
/// Main program of uncertainty propagation of the ODE model parameters via intrusive spectral projection (ISP)
int main()
{
// Model parameters
Array1D<double> modelparams;
// Model parameter names
Array1D<string> modelparamnames;
// Auxiliary parameters: final time and time step of integration
Array1D<double> modelauxparams;
// Read the xml tree
RefPtr<XMLElement> xmlTree=readXMLTree("lorenz.in.xml");
// Read the model-specific input
readXMLModelInput(xmlTree,modelparams, modelparamnames, modelauxparams);
// Total nuber of input parameters
int fulldim=modelparams.XSize();
// Read the output preferences
dumpInfo* outPrint=new dumpInfo;
readXMLDumpInfo( xmlTree, &(outPrint->dumpInt), &(outPrint->fdumpInt), &(outPrint->dumpfile) );
// Output PC order
int order;
// PC type
string pcType;
// A 2d array (each row is an array of coefficients for the corresponding uncertain input parameter)
Array2D<double> allPCcoefs;
// The indices of the uncertain model parameters in the list of model parameters
Array1D<int> uncParamInd;
// Read the UQ-specific information from the xml tree
readXMLUncInput(xmlTree,allPCcoefs,uncParamInd , &order, &pcType);
// Stochastic dimensionality
int dim=uncParamInd.XSize();
// Instantiate a PC object for ISP computations
PCSet myPCSet("ISP",order,dim,pcType,0.0,1.0);
// The number of PC terms
const int nPCTerms = myPCSet.GetNumberPCTerms();
cout << "The number of PC terms in an expansion is " << nPCTerms << endl;
// Print the multiindices on screen
myPCSet.PrintMultiIndex();
// Initial time
double t0 = 0.0;
// Final time
double tf = modelauxparams(0);
// Time step
double dTym = modelauxparams(1);
// Number of steps
int nStep=(int) tf / dTym;
// Initial conditions of zero coverage (based on Makeev:2002)
Array1D<double> u(nPCTerms,0.e0);
Array1D<double> v(nPCTerms,0.e0);
Array1D<double> w(nPCTerms,0.e0);
Array1D<double> z(nPCTerms,0.e0);
// Array to hold the PC representation of the number 1
Array1D<double> one(nPCTerms,0.e0);
one(0)=1.0;
// The z-species is described as z=1-u-v-w
z=one;
myPCSet.SubtractInPlace(z,u);
myPCSet.SubtractInPlace(z,v);
myPCSet.SubtractInPlace(z,w);
// Right-hand sides
Array1D<double> dudt(nPCTerms,0.e0);
Array1D<double> dvdt(nPCTerms,0.e0);
Array1D<double> dwdt(nPCTerms,0.e0);
// Array of arrays to hold the input parameter PC representations in the output PC
// Each element is an array of coefficients for the corresponding input parameter, whether deterministic or uncertain
// The size of the array is the total number input parameters
Array1D< Array1D<double> > modelparamPCs(fulldim);
printf("\nInput parameter PC coefficients are given below\n");
for (int i=0; i<fulldim; i++){
printf("%s: ",modelparamnames(i).c_str());
modelparamPCs(i).Resize(nPCTerms,0.e0);
for (int j=0; j<nPCTerms; j++){
modelparamPCs(i)(j)=allPCcoefs(j,i);
printf(" %lg ",modelparamPCs(i)(j));
}
printf("\n");
}
printf("\n");
// Initial time and time step counter
int step=0;
double tym=t0;
// Work arrays for integration
//.........这里部分代码省略.........