blib/lib/Math/Histo/Fit.pm

filter: Statementstmt 100% 40 / 40 Branchbran 66.6% 4 / 6 Conditioncond 25.0% 3 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 74.0% 57 / 77 CC 9 SCAR 12.4
CC
9
Cov
81%
eval
6.0
eval_grad
6.0
status_str
2.0
CRAP 3.4
« blib/lib/Math/Histo/KDE.pm ↑ Summary blib/lib/Math/Histo/Sketch.pm »
1 package Math::Histo::Fit;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Math::Histo ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Math::Histo::Constants qw(:fit);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 our $VERSION = '0.4.2';
9  
10 11 my %MODEL_STR_MAP = (
11 gaussian => HISTO_FIT_GAUSSIAN,
12 gauss => HISTO_FIT_GAUSSIAN,
13 exponential => HISTO_FIT_EXPONENTIAL,
14 exp => HISTO_FIT_EXPONENTIAL,
15 polynomial => HISTO_FIT_POLYNOMIAL,
16 poly => HISTO_FIT_POLYNOMIAL,
17 breit_wigner => HISTO_FIT_BREIT_WIGNER,
18 cauchy => HISTO_FIT_BREIT_WIGNER,
19 power_law => HISTO_FIT_POWER_LAW,
20 powerlaw => HISTO_FIT_POWER_LAW,
21 lognormal => HISTO_FIT_LOG_NORMAL,
22 log_normal => HISTO_FIT_LOG_NORMAL,
23 gauss_linear => HISTO_FIT_GAUSSIAN_PLUS_LINEAR,
24 gauss_poly1 => HISTO_FIT_GAUSSIAN_PLUS_LINEAR,
25 weibull => HISTO_FIT_WEIBULL,
26 gamma => HISTO_FIT_GAMMA,
27 erlang => HISTO_FIT_GAMMA,
28 poisson => HISTO_FIT_POISSON,
29 laplace => HISTO_FIT_LAPLACE,
30 );
31  
32 1 ▶sub eval {
Subroutine eval: called CC=4 SCAR=17.9
Pod undocumented
33 1 my ($class, $model, $params, $x) = @_;
34 1 ▶ my $m = (defined $model && exists $MODEL_STR_MAP{lc($model)}) ? $MODEL_STR_MAP{lc($model)} : int($model // 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $model && exists $MODEL_STR_MAP{lc $model} ? : 1 0 1
Condition20%1/5
defined $model and exists $MODEL_STR_MAP{lc $model}
!ll&&!rl&&r
001
$model // 0
l!l
00
MC/DC0%0/2
defined $model and exists $MODEL_STR_MAP{lc $model}
defined $model exists $MODEL_STR_MAP{lc $model}
MC/DC0%0/1
$model // 0
$model
Truth table33%1/3
A and B
A= defined $modelB= exists $MODEL_STR_MAP{lc $model}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $model
Aresult
11
00
35 1 return $class->eval_model($m, $params, $x);
36 }
37  
38 1 ▶sub eval_grad {
Subroutine eval_grad: called CC=4 SCAR=17.9
Pod undocumented
39 1 my ($class, $model, $params, $x) = @_;
40 1 ▶ my $m = (defined $model && exists $MODEL_STR_MAP{lc($model)}) ? $MODEL_STR_MAP{lc($model)} : int($model // 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $model && exists $MODEL_STR_MAP{lc $model} ? : 1 0 1
Condition20%1/5
defined $model and exists $MODEL_STR_MAP{lc $model}
!ll&&!rl&&r
001
$model // 0
l!l
00
MC/DC0%0/2
defined $model and exists $MODEL_STR_MAP{lc $model}
defined $model exists $MODEL_STR_MAP{lc $model}
MC/DC0%0/1
$model // 0
$model
Truth table33%1/3
A and B
A= defined $modelB= exists $MODEL_STR_MAP{lc $model}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $model
Aresult
11
00
41 1 return $class->eval_gradient($m, $params, $x);
42 }
43  
44 package Math::Histo::Fit::Result;
45  
46 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 11 our $VERSION = '0.4.2';
50  
51  
52 1 ▶sub status_str {
Subroutine status_str: called CC=2 SCAR=7.1
53 1 my ($self) = @_;
54 1 my %map = (
55 0 => 'CONVERGED_FTOL',
56 1 => 'CONVERGED_XTOL',
57 2 => 'CONVERGED_GTOL',
58 3 => 'CONVERGED_EXACT',
59 -1 => 'MAX_ITERATIONS',
60 -2 => 'INVALID_ARG',
61 -3 => 'SINGULAR_MATRIX',
62 -4 => 'DIVERGED',
63 -5 => 'NO_DATA',
64 -6 => 'NOMEM',
65 );
66 1 ▶ return $map{$self->status} // 'UNKNOWN';
Condition50%1/2
$map{$self->status} // "UNKNOWN"
l!l
10
MC/DC0%0/1
$map{$self->status} // "UNKNOWN"
$map{$self->status}
Truth table50%1/2
A
A= $map{$self->status}
Aresult
11
00
67 }
68  
69 1 ▶sub summary {
Subroutine summary: called CC=2 SCAR=6.9
70 1 my ($self) = @_;
71 1 my $p = $self->params;
72 1 my $e = $self->errors;
73 1 my $out = sprintf("Fit Status: %s (iter: %d)\n", $self->status_str, $self->iterations);
74 1 $out .= sprintf("Chi2 / NDF: %.4f / %d (reduced: %.4f, p-value: %.4g)\n",
75 $self->chi2, $self->ndf, $self->reduced_chi2, $self->p_value);
76 1 $out .= "Parameters:\n";
77 1 ▶ for (my $i = 0; $i < @$p; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$p) 3 1 4
78 3 $out .= sprintf(" p[%d] = %12.6f +/- %12.6f\n", $i, $p->[$i], $e->[$i]);
79 }
80 1 return $out;
81 }
82  
83 11 1;
84  
85 __END__
« blib/lib/Math/Histo/KDE.pm ↑ Summary blib/lib/Math/Histo/Sketch.pm »