MCPcopy Create free account
hub / github.com/davisking/dlib / test_simple_linear_regression_with_mult_prev

Function test_simple_linear_regression_with_mult_prev

dlib/test/dnn.cpp:3965–4005  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3963// ----------------------------------------------------------------------------------------
3964
3965 void test_simple_linear_regression_with_mult_prev()
3966 {
3967 srand(1234);
3968 print_spinner();
3969 const int num_samples = 1000;
3970 ::std::vector<matrix<double>> x(num_samples);
3971 ::std::vector<float> y(num_samples);
3972 const float true_slope = 2.0;
3973 for ( int ii = 0; ii < num_samples; ++ii )
3974 {
3975 const double val = static_cast<double>(ii-500)/100;
3976 matrix<double> tmp(1,1);
3977 tmp = val;
3978 x[ii] = tmp;
3979 y[ii] = ( true_slope*static_cast<float>(val*val));
3980 }
3981
3982 randomize_samples(x,y);
3983
3984 using net_type = loss_mean_squared<fc<1, mult_prev1<fc<2,tag1<fc<2,input<matrix<double>>>>>>>>;
3985 net_type net;
3986 sgd defsolver(0,0.9);
3987 dnn_trainer<net_type> trainer(net, defsolver);
3988 trainer.set_learning_rate(1e-5);
3989 trainer.set_min_learning_rate(1e-11);
3990 trainer.set_mini_batch_size(50);
3991 trainer.set_max_num_epochs(2000);
3992 trainer.train(x, y);
3993
3994 running_stats<double> rs;
3995 for (size_t i = 0; i < x.size(); ++i)
3996 {
3997 double val = y[i];
3998 double out = net(x[i]);
3999 rs.add(std::abs(val-out));
4000 }
4001 dlog << LINFO << "rs.mean(): " << rs.mean();
4002 dlog << LINFO << "rs.stddev(): " << rs.stddev();
4003 dlog << LINFO << "rs.max(): " << rs.max();
4004 DLIB_TEST(rs.mean() < 0.1);
4005 }
4006
4007// ----------------------------------------------------------------------------------------
4008

Callers 1

run_testsMethod · 0.85

Calls 13

print_spinnerFunction · 0.85
randomize_samplesFunction · 0.85
absFunction · 0.85
set_learning_rateMethod · 0.80
set_min_learning_rateMethod · 0.80
set_mini_batch_sizeMethod · 0.80
set_max_num_epochsMethod · 0.80
trainMethod · 0.45
sizeMethod · 0.45
addMethod · 0.45
meanMethod · 0.45
stddevMethod · 0.45

Tested by

no test coverage detected