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:3392–3432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3390// ----------------------------------------------------------------------------------------
3391
3392 void test_simple_linear_regression_with_mult_prev()
3393 {
3394 srand(1234);
3395 print_spinner();
3396 const int num_samples = 1000;
3397 ::std::vector<matrix<double>> x(num_samples);
3398 ::std::vector<float> y(num_samples);
3399 const float true_slope = 2.0;
3400 for ( int ii = 0; ii < num_samples; ++ii )
3401 {
3402 const double val = static_cast<double>(ii-500)/100;
3403 matrix<double> tmp(1,1);
3404 tmp = val;
3405 x[ii] = tmp;
3406 y[ii] = ( true_slope*static_cast<float>(val*val));
3407 }
3408
3409 randomize_samples(x,y);
3410
3411 using net_type = loss_mean_squared<fc<1, mult_prev1<fc<2,tag1<fc<2,input<matrix<double>>>>>>>>;
3412 net_type net;
3413 sgd defsolver(0,0.9);
3414 dnn_trainer<net_type> trainer(net, defsolver);
3415 trainer.set_learning_rate(1e-5);
3416 trainer.set_min_learning_rate(1e-11);
3417 trainer.set_mini_batch_size(50);
3418 trainer.set_max_num_epochs(2000);
3419 trainer.train(x, y);
3420
3421 running_stats<double> rs;
3422 for (size_t i = 0; i < x.size(); ++i)
3423 {
3424 double val = y[i];
3425 double out = net(x[i]);
3426 rs.add(std::abs(val-out));
3427 }
3428 dlog << LINFO << "rs.mean(): " << rs.mean();
3429 dlog << LINFO << "rs.stddev(): " << rs.stddev();
3430 dlog << LINFO << "rs.max(): " << rs.max();
3431 DLIB_TEST(rs.mean() < 0.1);
3432 }
3433
3434// ----------------------------------------------------------------------------------------
3435

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