本文整理汇总了C++中Forest::run方法的典型用法代码示例。如果您正苦于以下问题:C++ Forest::run方法的具体用法?C++ Forest::run怎么用?C++ Forest::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Forest
的用法示例。
在下文中一共展示了Forest::run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rangerCpp
//.........这里部分代码省略.........
// Load forest object if in prediction mode
if (prediction_mode) {
size_t dependent_varID = loaded_forest["dependent.varID"];
//size_t num_trees = loaded_forest["num.trees"];
std::vector<std::vector<std::vector<size_t>> > child_nodeIDs = loaded_forest["child.nodeIDs"];
std::vector<std::vector<size_t>> split_varIDs = loaded_forest["split.varIDs"];
std::vector<std::vector<double>> split_values = loaded_forest["split.values"];
std::vector<bool> is_ordered = loaded_forest["is.ordered"];
if (treetype == TREE_CLASSIFICATION) {
std::vector<double> class_values = loaded_forest["class.values"];
((ForestClassification*) forest)->loadForest(dependent_varID, num_trees, child_nodeIDs, split_varIDs,
split_values, class_values, is_ordered);
} else if (treetype == TREE_REGRESSION) {
((ForestRegression*) forest)->loadForest(dependent_varID, num_trees, child_nodeIDs, split_varIDs, split_values,
is_ordered);
} else if (treetype == TREE_SURVIVAL) {
size_t status_varID = loaded_forest["status.varID"];
std::vector<std::vector<std::vector<double>> > chf = loaded_forest["chf"];
std::vector<double> unique_timepoints = loaded_forest["unique.death.times"];
((ForestSurvival*) forest)->loadForest(dependent_varID, num_trees, child_nodeIDs, split_varIDs, split_values,
status_varID, chf, unique_timepoints, is_ordered);
} else if (treetype == TREE_PROBABILITY) {
std::vector<double> class_values = loaded_forest["class.values"];
std::vector<std::vector<std::vector<double>>>terminal_class_counts =
loaded_forest["terminal.class.counts"];
((ForestProbability*) forest)->loadForest(dependent_varID, num_trees, child_nodeIDs, split_varIDs, split_values,
class_values, terminal_class_counts, is_ordered);
}
}
// Run Ranger
forest->run(false);
if (use_split_select_weights && importance_mode != IMP_NONE) {
*verbose_out
<< "Warning: Split select weights used. Variable importance measures are only comparable for variables with equal weights."
<< std::endl;
}
// Use first non-empty dimension of predictions
const std::vector<std::vector<std::vector<double>>>& predictions = forest->getPredictions();
if (predictions.size() == 1) {
if (predictions[0].size() == 1) {
result.push_back(forest->getPredictions()[0][0], "predictions");
} else {
result.push_back(forest->getPredictions()[0], "predictions");
}
} else {
result.push_back(forest->getPredictions(), "predictions");
}
// Return output
result.push_back(forest->getNumTrees(), "num.trees");
result.push_back(forest->getNumIndependentVariables(), "num.independent.variables");
if (treetype == TREE_SURVIVAL) {
ForestSurvival* temp = (ForestSurvival*) forest;
result.push_back(temp->getUniqueTimepoints(), "unique.death.times");
}
if (!verbose) {
std::stringstream temp;
temp << verbose_out->rdbuf();
result.push_back(temp.str(), "log");
}
if (!prediction_mode) {
示例2: main
int main(int argc, char **argv) {
ArgumentHandler arg_handler(argc, argv);
Forest* forest = 0;
try {
// Handle command line arguments
if (arg_handler.processArguments() != 0) {
return 0;
}
arg_handler.checkArguments();
// Create forest object
switch (arg_handler.treetype) {
case TREE_CLASSIFICATION:
if (arg_handler.probability) {
forest = new ForestProbability;
} else {
forest = new ForestClassification;
}
break;
case TREE_REGRESSION:
forest = new ForestRegression;
break;
case TREE_SURVIVAL:
forest = new ForestSurvival;
break;
case TREE_PROBABILITY:
forest = new ForestProbability;
break;
}
// Verbose output to logfile if non-verbose mode
std::ostream* verbose_out;
if (arg_handler.verbose) {
verbose_out = &std::cout;
} else {
std::ofstream* logfile = new std::ofstream();
logfile->open(arg_handler.outprefix + ".log");
if (!logfile->good()) {
throw std::runtime_error("Could not write to logfile.");
}
verbose_out = logfile;
}
// Call Ranger
*verbose_out << "Starting Ranger." << std::endl;
forest->initCpp(arg_handler.depvarname, arg_handler.memmode, arg_handler.file, arg_handler.mtry,
arg_handler.outprefix, arg_handler.ntree, verbose_out, arg_handler.seed, arg_handler.nthreads,
arg_handler.predict, arg_handler.impmeasure, arg_handler.targetpartitionsize, arg_handler.splitweights,
arg_handler.alwayssplitvars, arg_handler.statusvarname, arg_handler.replace, arg_handler.catvars,
arg_handler.savemem, arg_handler.splitrule);
forest->run(true);
if (arg_handler.write) {
forest->saveToFile();
}
forest->writeOutput();
*verbose_out << "Finished Ranger." << std::endl;
delete forest;
} catch (std::exception& e) {
std::cerr << "Error: " << e.what() << " Ranger will EXIT now." << std::endl;
delete forest;
return -1;
}
return 0;
}