本文整理汇总了C++中Simplex::neldermead方法的典型用法代码示例。如果您正苦于以下问题:C++ Simplex::neldermead方法的具体用法?C++ Simplex::neldermead怎么用?C++ Simplex::neldermead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simplex
的用法示例。
在下文中一共展示了Simplex::neldermead方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: optimise_single
double Handler::optimise_single(vector<double> ¶meters, vector<vector<double> > &results, vector<vector<vector<double> > > &allResults, int& itr){
double SSE = 99999999999999.9;
double tempSSE;
vector<double> tempPar, seedParams;
Simplex simplex;
parameters.clear();
allResults.clear();
parameters = generate_seed_parameters();
for(int index = 0;index<20;index++){
seedParams.clear();
seedParams = generate_seed_parameters();
//printcon(seedParams);
if(this->useMLE == false) tempPar = simplex.neldermead(&Handler::fitEpidemicsMLE, *this, seedParams, itr);
else tempPar = simplex.neldermead(&Handler::fitEpidemics, *this, seedParams, itr);
// Store the SSE value for this
tempSSE = fitEpidemics(tempPar);
if(tempSSE < SSE){
SSE = tempSSE;
parameters=tempPar;
}
cout << "." << flush;
}
results = ode_solve(parameters);
allResults = ode_solve_separate(parameters);
//allResults.clear();
cout << endl;
return SSE;
}
示例2: optimiseEpidemics
/* Optimisation procedure. Takes a reference to parameters, combined results, component results and number of iterations taken. The function updates these
arguments with the results of the Nelder-Mead optimisation procedure. */
double Handler::optimiseEpidemics(vector<double> ¶meters, vector<vector<double> > &results, vector<vector<vector<double> > > &allResults, int& itr){
double SSE = 99999999999999999.9;
double tempSSE;
vector<double> tempPar, seedParams;
Simplex simplex;
int iterations = 10001;
// If no epidemics have yet been detected, use the mean of the current data as the
// current model and return the corresponding SSE.
if(epidemics.size() == 0){
//baseModel = base_model(temp_data);
results = base_model(temp_data);
SSE = calculate_SSE(results, temp_data);
parameters.clear();
allResults.clear();
allResults.push_back(baseModel);
return(SSE);
}
srand(time(NULL));
parameters = generate_seed_parameters();
// If there are epidemics to be fitted, perform X random fits and keep best fitting model
for(int index=0;index<10;index++){
// Create random seed parameters
seedParams.clear();
seedParams = generate_seed_parameters();
while(fitEpidemics(seedParams) != fitEpidemics(seedParams)){
seedParams.clear();
seedParams = generate_seed_parameters();
}
// Get the optimised parameters from nelder mead algorithm
tempPar = simplex.neldermead(&Handler::fitEpidemics, *this, seedParams, iterations);
// Store the SSE value for this
tempSSE = fitEpidemics(tempPar);
//if(tempSSE == tempSSE) cout << "Temp RSquare: " << (1-tempSSE/(SStot(temp_data,1))) << endl;
// If this SSE value is better than the previous, store it and the corresponding parameters
if(tempSSE < SSE){
itr = iterations;
SSE = tempSSE;
parameters=tempPar;
}
cout << "." << flush;
}
// Get the combined values from these parameters, as well as a vector of
// each sub-epidemic
results = ode_solve(parameters);
allResults.clear();
allResults = ode_solve_separate(parameters);
cout << endl;
return(SSE);
}
示例3: optimiseEpidemics
double Handler::optimiseEpidemics(vector<double> ¶meters, vector<vector<double> > &results, vector<vector<vector<double> > > &allResults, int& itr){
double SSE = 99999999999.9;
double tempSSE;
vector<double> tempPar, seedParams;
vector<vector<vector<double> > > tempAll;
Simplex simplex;
int iterations = 10001;
// If no epidemics have yet been detected, use the mean of the current data as the
// current model and return the corresponding SSE.
if(epidemics.size() == 0){
results = this->baseModel;
SSE = calculate_SSE(results, temp_data);
parameters.clear();
allResults.clear();
allResults.push_back(results);
return(SSE);
}
parameters = generate_seed_parameters();
// If there are epidemics to be fitted, perform 40 random fits and keep best fitting model
for(int index=0;index<40;index++){
// Clear the temporary seed parameters and seed rand
// Create a list of random seed parameters
seedParams.clear();
seedParams = generate_seed_parameters();
// Get the optimised parameters from nelder mead algorithm
if(this->useMLE == false) tempPar = simplex.neldermead(&Handler::fitEpidemicsMLE, *this, seedParams, iterations);
else tempPar = simplex.neldermead(&Handler::fitEpidemics, *this, seedParams, iterations);
// Store the SSE value for this
tempSSE = fitEpidemics(tempPar);
// If this SSE value is better than the previous, store it and the
// corresponding parameters
if(tempSSE < SSE){
itr = iterations;
SSE = tempSSE;
parameters=tempPar;
}
cout << "." << flush;
}
// Get the combined values from these parameters, as well as a vector of
// each sub-epidemic
results = ode_solve(parameters);
tempAll = ode_solve_separate(parameters);
allResults.clear();
allResults.push_back(this->baseModel);
for(unsigned int x = 0;x<tempAll.size();++x){
allResults.push_back(tempAll[x]);
}
cout << endl;
return(SSE);
}