本文整理汇总了C++中Prediction::getPrediction方法的典型用法代码示例。如果您正苦于以下问题:C++ Prediction::getPrediction方法的具体用法?C++ Prediction::getPrediction怎么用?C++ Prediction::getPrediction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Prediction
的用法示例。
在下文中一共展示了Prediction::getPrediction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
//~~~~~~~~~~~
offset_cad_learner = new MultiTaskLinearGPRLearner(6,6);
offset_cad_learner->setName("OffsetLearner");
if( set_noise_scaling ) {
offset_cad_learner->setNoiseStandardDeviation(ftStdDev);
}
size_t i;
//std::cout << "allRegr " << allRegr.rows() << " " << allRegr.cols() << std::endl;
//std::cout << "allRegr " << allRegr.toString() << std::endl;
for(i = 0; i < training_samples; i++ ) {
//~~~~~~~~~~
//std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
std::cout << "~~~~~~~~~~~~~~~~~I : " << i << std::endl;
//std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
Matrix regr, regr_no_offset;
Vector FT;
regr = allRegr.submatrix(6*i,6*i+6-1,0,allRegr.cols()-1);
FT = allFT.subVector(6*i,6*i+6-1);
regr_no_offset = regr.submatrix(0,regr.rows()-1,0,regr.cols()-1-6);
param_learner->feedSample(regr,FT);
std::cout << "regr 15 col" << regr.getCol(11).toString() << std::endl;
//std::cout << "Regr" << regr.toString() << std::endl;
//std::cout << "allRegr " << allRegr.rows() << " " << allRegr.cols() << std::endl;
//std::cout << "allRegr " << allRegr.getCol(0).toString() << std::endl;
/*
std::cout << "regr_no_offset" << regr_no_offset.rows() << " " << regr_no_offset.cols() << std::endl;
std::cout << "sip " << static_identifiable_parameters.rows() << " " << static_identifiable_parameters.cols() << std::endl;
std::cout << "cad_parameters " << cad_parameters.size() << std::endl;
std::cout.flush();
*/
//std::cout << "regr 1 col" << regr.getCol(0).toString() << std::endl;
Vector FTcad = regr_no_offset*static_identifiable_parameters.transposed()*cad_parameters;
Vector res = FT-FTcad;
offset_cad_learner->feedSample(eye(6,6),res);
}
Vector offset_cad;
offset_cad = offset_cad_learner->getParameters();
Vector learned_param = param_learner->getParameters();
Vector learned_param_oneshot;
learned_param_oneshot = pinv(allRegr,1e-7)*allFT;
std::cout << allRegr.getCol(16).toString() << std::endl;
std::cout << "Learned param offset " << learned_param.toString() << std::endl;
std::cout << "Cad parameters " << (static_identifiable_parameters.transposed()*cad_parameters).toString() << std::endl;
std::cout << "CAD learned offset " << offset_cad.toString() << std::endl;
std::cout << "Learned oneshot offset " << learned_param_oneshot.toString() << std::endl;
for( ; i < num_samples; i++ ) {
std::cout << "~~~~~~~~~~~~~~~~~I : " << i << std::endl;
Prediction pred;
Matrix regr, regr_no_offset;
Vector FT, predFT, predFTCAD;
regr = allRegr.submatrix(6*i,6*i+6-1,0,allRegr.cols()-1);
regr_no_offset = regr.submatrix(0,regr.rows()-1,0,regr.cols()-1-6);
FT = allFT.subVector(6*i,6*i+6-1);
pred = param_learner->predict(regr);
predFT = pred.getPrediction();
predFTCAD = regr_no_offset*static_identifiable_parameters.transposed()*cad_parameters + offset_cad;
std::cout << "regr 16 col" << regr.getCol(16).toString() << std::endl;
/*
std::cout << "FT " << FT.toString() << std::endl;
std::cout << "predFT " << predFT.toString() << std::endl;
std::cout << "predFTCAD " << predFTCAD.toString() << std::endl;
*/
errors.feedSample(abs(predFT-FT));
//std::cout << "Submitted learned error " << abs(predFT-FT).toString() << std::endl;
cad_errors.feedSample(abs(predFTCAD-FT));
//std::cout << "Submitted cad error " << abs(predFTCAD-FT).toString() << std::endl;
}
std::cout << "Errors for learned parameters " << errors.getMean().toString() << std::endl;
std::cout << "Errors for CAD parameters " << cad_errors.getMean().toString() << std::endl;
return 0;
}
示例2: main
int main(int argc, char** argv) {
int nrf = 250;
Vector trainMSE(2);
Vector testMSE(2);
Vector noise_min(2);
Vector noise_max(2);
// train + test time for transformer and machine
double tic;
double trtrtime = 0.0;
double trtetime = 0.0;
double mctrtime = 0.0;
double mctetime = 0.0;
if(argc > 1) sscanf(argv[1], "%d", &nrf);
// initialize catalogue of machine factory
registerMachines();
// initialize catalogue of transformers
registerTransformers();
std::cout << "LearningMachine library example (portable)" << std::endl;
// create Regularized Least Squares learner
std::string name("RLS");
MachinePortable mp = MachinePortable("RLS");
Property p;
p.put("dom", Value(nrf));
p.put("cod", Value(2));
p.put("lambda", Value(0.5));
mp.getWrapped().configure(p);
std::cout << "Learner:" << std::endl << mp.getWrapped().getInfo() << std::endl;
// create Random Feature transformer
TransformerPortable tp = TransformerPortable("RandomFeature");
p.clear();
p.put("dom", Value(2));
p.put("cod", Value(nrf));
p.put("gamma", Value(16.0));
tp.getWrapped().configure(p);
std::cout << "Transformer:" << std::endl << tp.getWrapped().getInfo() << std::endl;
// create and feed training samples
noise_min = NOISE_MIN;
noise_max = NOISE_MAX;
trainMSE = 0.0;
for(int i = 0; i < NO_TRAIN; i++) {
// create a new training sample
std::pair<Vector, Vector> sample = createSample();
// add some noise to output for training
Vector noisyOutput = sample.second + Rand::vector(noise_min, noise_max);
// transform input using RF
tic = yarp::os::Time::now();
Vector transInput = tp.getWrapped().transform(sample.first);
trtrtime += (yarp::os::Time::now() - tic);
// make prediction before feeding full sample
tic = yarp::os::Time::now();
Prediction prediction = mp.getWrapped().predict(transInput);
// train on complete sample with noisy output
mp.getWrapped().feedSample(transInput, noisyOutput);
mctrtime += (yarp::os::Time::now() - tic);
Vector diff = prediction.getPrediction() - sample.second;
elementProd(diff, diff);
trainMSE = trainMSE + diff;
}
trainMSE = elementDiv(trainMSE, NO_TRAIN);
std::cout << "Train MSE: " << trainMSE.toString() << std::endl;
std::cout << "Train Transformer Time per Sample: " << (trtrtime / NO_TRAIN) << std::endl;
std::cout << "Train Machine Time per Sample: " << (mctrtime / NO_TRAIN) << std::endl;
std::cout << "Combined Time per Sample: " << ((trtrtime + mctrtime) / NO_TRAIN) << std::endl;
std::cout << std::endl;
std::cout << "Saving machine portable to file 'mp.txt'...";
bool ok = mp.writeToFile("mp.txt");
std::cout << ((ok) ? "ok!" : "failed :(") << std::endl;
std::cout << "Saving transformer portable to file 'tp.txt'...";
ok = tp.writeToFile("tp.txt");
std::cout << ((ok) ? "ok!" : "failed :(") << std::endl;
std::cout << "Loading machine portable from file 'mp.txt'...";
ok = mp.readFromFile("mp.txt");
std::cout << ((ok) ? "ok!" : "failed :(") << std::endl;
std::cout << "Loading transformer portable from file 'tp.txt'...";
ok = tp.readFromFile("tp.txt");
std::cout << ((ok) ? "ok!" : "failed :(") << std::endl;
std::cout << std::endl;
// predict test samples
testMSE = 0.;
for(int i = 0; i < NO_TEST; i++) {
// create a new testing sample
//.........这里部分代码省略.........