Algorithm-CurveFit-Simple
view release on metacpan or search on metacpan
bin/curvefit view on Meta::CPAN
return undef;
}
sub logger {
return if (opt('no-log') || opt('log',1) == 0);
my $log_ar = [localtime(), Time::HiRes::time(), $$, @_];
my $log_rec = JSON::to_json($log_ar, {ascii => 1, space_after => 1, canonical => 1})."\n";
print STDERR $log_rec if (opt('show-log'));
print STDOUT $log_rec if (opt('show-log-to-stdout'));
File::Valet::ap_f(opt('logfile',"/home/ttk/$PROJECT_NAME.log"), $log_rec) unless(opt('no-logfile'));
return;
}
sub usage {
print <<USAGE;
Usage: $0 [options] < data
Input must be x,y data pairs, one pair per line, separated by a comma or tab.
Options and their defaults, if any:
--time-limit=3 Maximum number of seconds to spend calculating best fit
--iterations=# Maximum number of iterations to spend calculating best fit (default is to use a time limit)
--terms=3 Number of terms in polynomial, max 10
--inv Invert the sense of the fit to f(y) = x
--impl-lang=perl Language used for output implementation: perl, C
--impl-name=x2y Name of function in output implementation
--bounds-check Implementation will check for out-of-bounds input
--round-result Implementation will round output to nearest integer
--suppress-includes (C only) Do not put #include directives in output implementation
--quiet Do not write supplementary information to stderr
--profile Dump %STATS_H to stderr as json
See also: Algorithm::CurveFit::Simple
USAGE
exit(0);
}
=head1 NAME
curvefit - Fit a polynomial to data points
=head1 SYNOPSIS
Usage: curvefit [options] < data
Expects x,y data pairs on STDIN, one pair per line, separated by a comma or tab.
--time-limit=3 Maximum number of seconds to spend calculating best fit
--iterations=# Maximum number of iterations to spend calculating best fit (default is to use a time limit)
--terms=3 Number of terms in polynomial, max 10
--inv Invert the sense of the fit to f(y) = x
--impl-lang=perl Language used for output implementation: perl, C
--impl-name=x2y Name of function in output implementation
--bounds-check Implementation will check for out-of-bounds input
--round-result Implementation will round output to nearest integer
--suppress-includes (C only) Do not put #include directives in output implementation
--quiet Do not write supplementary information to stderr
--profile Dump %STATS_H to STDERR as json
=head1 DESCRIPTION
This is a thin wrapper around L<Algorithm::CurveFit::Simple>, which is in turn a convenience wrapper around L<Algorithm::CurveFit>.
Given a set of x,y data pairs on STDIN, it will generate a polynomial formula f(x) = y which fits that data, and write a source code implementation of that formula to STDOUT.
Additionally it will write a maximum deviation and average deviation to STDERR. Closer to 1.0 is better. Play with --terms=# until these deviations are as close to 1.0 as possible, and beware overfitting. Use --quiet to suppress this information.
=head1 SEE ALSO
L<Algorithm::CurveFit::Simple>
=cut
( run in 0.365 second using v1.01-cache-2.11-cpan-ecdf5575e8d )