本文整理汇总了C++中Observations::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Observations::clear方法的具体用法?C++ Observations::clear怎么用?C++ Observations::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Observations
的用法示例。
在下文中一共展示了Observations::clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Observation
TEST(SFM_DATA_FILTERS, LargestViewTrackCC)
{
// Init a scene with 5 Views & poses
SfM_Data sfm_data;
init_scene(sfm_data, 5);
// Fill with some tracks
//
//- View 0,1,2 are sharing 3 tracks
// TrackId 0 -> 0-1-2
// TrackId 1 -> 0-1-2
// TrackId 2 -> 0-1-2
//
// While view 3-4 are sharing 1 track
// TrackId 3 -> 3-4
Observations obs;
obs[0] = Observation( Vec2(10,20), 0);
obs[1] = Observation( Vec2(30,10), 1);
obs[2] = Observation( Vec2(30,10), 1);
sfm_data.structure[0].obs = obs;
sfm_data.structure[0].X = Vec3::Random();
sfm_data.structure[1].obs = obs;
sfm_data.structure[1].X = Vec3::Random();
sfm_data.structure[2].obs = obs;
sfm_data.structure[2].X = Vec3::Random();
obs.clear();
obs[3] = Observation( Vec2(10,20), 0);
obs[4] = Observation( Vec2(10,20), 0);
sfm_data.structure[3].obs = obs;
sfm_data.structure[3].X = Vec3::Random();
// Track of the SfM_Data scene contains two connected component
// One for view (0,1,2)
// One for the view (3,4)
// Test that function to keep the largest one is working
EXPECT_EQ (4, sfm_data.GetLandmarks().size());
EXPECT_FALSE (IsTracksOneCC(sfm_data));
KeepLargestViewCCTracks(sfm_data);
EXPECT_EQ (3, sfm_data.GetLandmarks().size());
}
示例2: run_model
int YAMRSlave::run_model(Parameters &pars, Observations &obs)
{
int success = 1;
//bool isDouble = true;
//bool forceRadix = true;
//TemplateFiles tpl_files(isDouble,forceRadix,tplfile_vec,inpfile_vec,par_name_vec);
//InstructionFiles ins_files(insfile_vec,outfile_vec,obs_name_vec);
std::vector<double> obs_vec;
try
{
// message.str("");
int ifail;
int ntpl = tplfile_vec.size();
int npar = pars.size();
vector<string> par_name_vec;
vector<double> par_values;
for(auto &i : pars)
{
par_name_vec.push_back(i.first);
par_values.push_back(i.second);
}
wrttpl_(&ntpl, StringvecFortranCharArray(tplfile_vec, 50).get_prt(),
StringvecFortranCharArray(inpfile_vec, 50).get_prt(),
&npar, StringvecFortranCharArray(par_name_vec, 50, pest_utils::TO_LOWER).get_prt(),
par_values.data(), &ifail);
if(ifail != 0)
{
throw PestError("Error processing template file:" + tpl_err_msg(ifail));
}
//tpl_files.writtpl(par_values);
// update parameter values
pars.clear();
for (int i=0; i<npar; ++i)
{
pars[par_name_vec[i]] = par_values[i];
}
// run model
for (auto &i : comline_vec)
{
ifail = system(i.c_str());
if(ifail != 0)
{
cerr << "Error executing command line: " << i << endl;
throw PestError("Error executing command line: " + i);
}
}
// process instructio files
int nins = insfile_vec.size();
int nobs = obs_name_vec.size();
std::vector<double> obs_vec;
obs_vec.resize(nobs, -9999.00);
readins_(&nins, StringvecFortranCharArray(insfile_vec, 50).get_prt(),
StringvecFortranCharArray(outfile_vec, 50).get_prt(),
&nobs, StringvecFortranCharArray(obs_name_vec, 50, pest_utils::TO_LOWER).get_prt(),
obs_vec.data(), &ifail);
if(ifail != 0)
{
throw PestError("Error processing template file");
}
//obs_vec = ins_files.readins();
// check parameters and observations for inf and nan
if (std::any_of(par_values.begin(), par_values.end(), OperSys::double_is_invalid))
{
throw PestError("Error running model: invalid parameter value returned");
}
if (std::any_of(obs_vec.begin(), obs_vec.end(), OperSys::double_is_invalid))
{
throw PestError("Error running model: invalid observation value returned");
}
// update observation values
obs.clear();
for (int i=0; i<nobs; ++i)
{
obs[obs_name_vec[i]] = obs_vec[i];
}
}
catch(const std::exception& ex)
{
cerr << endl;
cerr << " " << ex.what() << endl;
cerr << " Aborting model run" << endl << endl;
success = 0;
}
catch(...)
{
cerr << " Error running model" << endl;
cerr << " Aborting model run" << endl;
success = 0;
}
return success;
}
示例3: run
void RunManagerGenie::run()
{
int nexec = comline_vec.size();
const vector<string> &par_name_vec = file_stor.get_par_name_vec();
const vector<string> &obs_name_vec = file_stor.get_obs_name_vec();
int npar = par_name_vec.size();
int nobs = obs_name_vec.size();
int ntpl = tplfile_vec.size();
int nins = insfile_vec.size();
stringstream apar;
stringstream aobs;
stringstream execnames;
stringstream tplfle;
stringstream infle;
stringstream insfle;
stringstream outfle;
vector<double> par_val;
vector<double> obs_val;
vector<int> ifail;
// This is necessary to support restart as some run many already be complete
vector<int> run_id_vec = get_outstanding_run_ids();
int nruns = run_id_vec.size();
par_val.clear();
obs_val.resize(nruns*nobs);
ifail.resize(nruns);
for (int i_run : run_id_vec)
{
Parameters tmp_pars;
file_stor.get_parameters(i_run, tmp_pars);
vector<double> tmp_vec = tmp_pars.get_data_vec(par_name_vec);
par_val.insert(par_val.end(), tmp_vec.begin(), tmp_vec.end());
}
vector<string> par_name_vec_lwr = par_name_vec;
for (auto &ipar : par_name_vec_lwr)
{
lower_ip(ipar);
}
vector<string> obs_name_vec_lwr = obs_name_vec;
for (auto &iobs : obs_name_vec_lwr)
{
lower_ip(iobs);
}
std::copy(par_name_vec_lwr.begin(), par_name_vec_lwr.end(),std::ostream_iterator<std::string>(apar,"\n"));
std::copy(obs_name_vec_lwr.begin(), obs_name_vec_lwr.end(),std::ostream_iterator<std::string>(aobs,"\n"));
std::copy(comline_vec.begin(), comline_vec.end(),std::ostream_iterator<std::string>(execnames,"\n"));
std::copy(tplfile_vec.begin(), tplfile_vec.end(),std::ostream_iterator<std::string>(tplfle,"\n"));
std::copy(inpfile_vec.begin(), inpfile_vec.end(),std::ostream_iterator<std::string>(infle,"\n"));
std::copy(insfile_vec.begin(), insfile_vec.end(),std::ostream_iterator<std::string>(insfle,"\n"));
std::copy(outfile_vec.begin(), outfile_vec.end(),std::ostream_iterator<std::string>(outfle,"\n"));
#ifdef OS_WIN
GENIE_INTERFACE(&nruns, &nexec, String2CharPtr(execnames.str()).get_char_ptr(), &npar, &nobs,
String2CharPtr(apar.str()).get_char_ptr(), String2CharPtr(aobs.str()).get_char_ptr(),
&par_val[0], &obs_val[0], &ntpl, &nins, String2CharPtr(tplfle.str()).get_char_ptr(),
String2CharPtr(infle.str()).get_char_ptr(), String2CharPtr(insfle.str()).get_char_ptr(),
String2CharPtr(outfle.str()).get_char_ptr(),
String2CharPtr(host).get_char_ptr(), String2CharPtr(id).get_char_ptr(), &ifail[0]);
#endif
#ifdef OS_LINUX
throw(PestError("Error: Genie run manager is not supported under linux"));
#endif
total_runs += nruns;
Parameters pars;
Observations obs;
for (int i=0; i<nruns; ++i)
{
if (ifail[i] == 0)
{
int run_id = run_id_vec[i];
pars.clear();
vector<double> i_par_vec(par_val.begin() + i*npar, par_val.begin() + (i + 1)*npar);
pars.insert(par_name_vec, i_par_vec);
obs.clear();
vector<double> i_obs_vec(obs_val.begin() + i*nobs, obs_val.begin() + (i + 1)*nobs);
obs.insert(obs_name_vec, i_obs_vec);
file_stor.update_run(run_id, pars, obs);
}
else
{
file_stor.set_run_nfailed(i, max_n_failure);
}
}
}