-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.pl
More file actions
38 lines (22 loc) · 880 Bytes
/
example.pl
File metadata and controls
38 lines (22 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl
use FindBin qw/$Bin/;
use lib "$Bin/lib";
use Algorithm::LinearFit::Random;
##################################################
# Build up a matrix of data
my $matrix = new Algorithm::LinearFit::Random( INPUTS => 3 );
$matrix->add_row( [6, -4, 5] , 4.00 );
$matrix->add_row( [1, 4, 6] , 3.00 );
$matrix->add_row( [2, 8, 7] , 6.00 );
$matrix->add_row( [1, 3, 8] , 2.50 );
# Display the matrix to verify it was added correctly
$matrix->_dump();
# Optimize weights for smallest RMSE
my $generations = 1_000_000;
my $starting_weights = [0, 0, 0];
my ( $rmse, $ending_weights ) = $matrix->tune_parameters( $starting_weights, $generations );
# Display calculated weights after N generations
print "\n";
print "Generations: $generations\n";
print "RMSE: $rmse\n";
print "Weights: [ " . join(' ', map { sprintf("%.4f", $_) } @$ending_weights ) . " ]\n";