Commit 11ed2630 authored by Davis King's avatar Davis King

Added more docs and tests.

parent 62cd23ce
......@@ -46,6 +46,7 @@ namespace dlib
std::vector<feature>& feats
) const
{
DLIB_ASSERT(max_num_feats() != 0);
num = std::min(num, num_feats);
feats.clear();
......@@ -66,6 +67,7 @@ namespace dlib
const feature& f
) const
{
DLIB_ASSERT(max_num_feats() != 0);
return item(f);
}
......@@ -290,6 +292,7 @@ namespace dlib
size_t num
)
{
DLIB_CASSERT(num > 0);
num_trees = num;
}
......@@ -297,6 +300,7 @@ namespace dlib
double frac
)
{
DLIB_CASSERT(0 < frac && frac <= 1);
feature_subsampling_frac = frac;
}
......@@ -344,7 +348,7 @@ namespace dlib
trained_function_type train (
const std::vector<sample_type>& x,
const std::vector<double>& y,
std::vector<double>& oob_values // predicted y, basically like LOO-CV
std::vector<double>& oob_values
) const
{
return do_train(x,y,oob_values,true);
......@@ -355,7 +359,7 @@ namespace dlib
trained_function_type do_train (
const std::vector<sample_type>& x,
const std::vector<double>& y,
std::vector<double>& oob_values, // predicted y, basically like LOO-CV
std::vector<double>& oob_values,
bool compute_oob_values
) const
{
......
......@@ -41,6 +41,8 @@ namespace
{
istringstream sin(get_decoded_string());
print_spinner();
typedef matrix<double,0,1> sample_type;
std::vector<double> labels;
std::vector<sample_type> samples;
......@@ -61,7 +63,7 @@ namespace
auto result = test_regression_function(df, samples, labels);
// train: 2.239 0.987173 0.970669 1.1399
dlog << LINFO << "train: " << trans(result);
dlog << LINFO << "train: " << result;
DLIB_TEST_MSG(result(0) < 2.3, result(0));
running_stats<double> rs;
......@@ -69,6 +71,18 @@ namespace
rs.add(std::pow(oobs[i]-labels[i],2.0));
dlog << LINFO << "OOB MSE: "<< rs.mean();
DLIB_TEST_MSG(rs.mean() < 10.2, rs.mean());
print_spinner();
stringstream ss;
serialize(df, ss);
decltype(df) df2;
deserialize(df2, ss);
DLIB_TEST(df2.get_num_trees() == 1000);
result = test_regression_function(df2, samples, labels);
// train: 2.239 0.987173 0.970669 1.1399
dlog << LINFO << "serialized train results: " << result;
DLIB_TEST_MSG(result(0) < 2.3, result(0));
}
} a;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment