本文整理汇总了C++中DVector::saveToFile方法的典型用法代码示例。如果您正苦于以下问题:C++ DVector::saveToFile方法的具体用法?C++ DVector::saveToFile怎么用?C++ DVector::saveToFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DVector
的用法示例。
在下文中一共展示了DVector::saveToFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
((fm_learn_mcmc*)fml)->w_lambda.init(fm.regw);
((fm_learn_mcmc*)fml)->v_lambda.init(fm.regv);
} else {
fm.reg0 = reg[0];
fm.regw = 0.0;
fm.regv = 0.0;
int j = 1;
for (uint g = 0; g < meta.num_attr_groups; g++) {
((fm_learn_mcmc*)fml)->w_lambda(g) = reg[j];
j++;
}
for (uint g = 0; g < meta.num_attr_groups; g++) {
for (int f = 0; f < fm.num_factor; f++) {
((fm_learn_mcmc*)fml)->v_lambda(g,f) = reg[j];
}
j++;
}
}
}
} else {
// set the regularization; for standard SGD, groups are not supported
{
vector<double> reg = cmdline.getDblValues(param_regular);
assert((reg.size() == 0) || (reg.size() == 1) || (reg.size() == 3));
if (reg.size() == 0) {
fm.reg0 = 0.0;
fm.regw = 0.0;
fm.regv = 0.0;
} else if (reg.size() == 1) {
fm.reg0 = reg[0];
fm.regw = reg[0];
fm.regv = reg[0];
} else {
fm.reg0 = reg[0];
fm.regw = reg[1];
fm.regv = reg[2];
}
}
}
{
fm_learn_sgd* fmlsgd= dynamic_cast<fm_learn_sgd*>(fml);
if (fmlsgd) {
// set the learning rates (individual per layer)
{
vector<double> lr = cmdline.getDblValues(param_learn_rate);
assert((lr.size() == 1) || (lr.size() == 3));
if (lr.size() == 1) {
fmlsgd->learn_rate = lr[0];
fmlsgd->learn_rates.init(lr[0]);
} else {
fmlsgd->learn_rate = 0;
fmlsgd->learn_rates(0) = lr[0];
fmlsgd->learn_rates(1) = lr[1];
fmlsgd->learn_rates(2) = lr[2];
}
}
}
}
if (rlog != NULL) {
rlog->init();
}
if (cmdline.getValue(param_verbosity, 0) > 0) {
fm.debug();
fml->debug();
}
// () learn
fml->learn(train);
// () Prediction at the end (not for mcmc and als)
if (cmdline.getValue(param_method).compare("mcmc")) {
std::cout << "Final\t" << "Train=" << fml->evaluate(train);
if (test != NULL)
std::cout << "\tTest=" << fml->evaluate(*test);
std::cout << std::endl;
}
if (!cmdline.hasParameter(param_train_file)) {
fml->fm->out(&std::cout);
}
// () Save prediction
if (cmdline.hasParameter(param_out)) {
DVector<double> pred;
pred.setSize(test->num_cases);
fml->predict(*test, pred);
pred.saveToFile(cmdline.getValue(param_out));
}
} catch (std::string &e) {
std::cerr << std::endl << "ERROR: " << e << std::endl;
} catch (char const* &e) {
std::cerr << std::endl << "ERROR: " << e << std::endl;
}
}