| 1 | package Math::Histo; | ||||||||||||||||||||||||||||
| 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 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 11 | our $VERSION = '0.4.2'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use XSLoader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 11 | XSLoader::load('Math::Histo', $VERSION); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Math::Histo::2D; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Math::Histo::Fit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Math::Histo::Sketch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Math::Histo::Constants qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | use overload | ||||||||||||||||||||||||||||
| 19 | 11 | ▶ | '+' => \&_op_add, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 20 | '-' => \&_op_sub, | ||||||||||||||||||||||||||||
| 21 | '*' => \&_op_mul, | ||||||||||||||||||||||||||||
| 22 | '/' => \&_op_div, | ||||||||||||||||||||||||||||
| 23 | '""' => \&_op_stringify, | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | bool => sub { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 25 | 11 | fallback => 1; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1024 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 1024 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 29 | 1024 | ▶ | my $flags = $args{flags} // HISTO_FLAG_NONE; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"flags"} // 0
MC/DC0%0/1
$args{"flags"} // 0
$args{"flags"}
Truth table50%1/2
A
A= $args{"flags"}
| |||||||||||||||||||||||||||||
| 30 | 1024 | ▶ | $flags |= HISTO_FLAG_TRACK_SUMW2 if $args{sumw2} || $args{track_sumw2}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"sumw2"} or $args{"track_sumw2"}
MC/DC50%1/2
$args{"sumw2"} or $args{"track_sumw2"}
$args{"sumw2"}
$args{"track_sumw2"}
Truth table66%2/3
A or B
A= $args{"sumw2"}B= $args{"track_sumw2"}
| |||||||||||||||||||||||||||||
| 31 | 1024 | ▶ | $flags |= HISTO_FLAG_EXACT_MOMENTS if $args{exact_moments}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1024 | ▶ | if (exists $args{edges}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 34 | 1 | return $class->_create_variable($args{edges}, $flags); | |||||||||||||||||||||||||||
| 35 | ▶ | } elsif (exists $args{bins} || exists $args{nbins}) { | |||||||||||||||||||||||||||
|
Condition33%1/3
exists $args{"bins"} or exists $args{"nbins"}
MC/DC0%0/2
exists $args{"bins"} or exists $args{"nbins"}
exists $args{"bins"}
exists $args{"nbins"}
Truth table33%1/3
A or B
A= exists $args{"bins"}B= exists $args{"nbins"}
| |||||||||||||||||||||||||||||
| 36 | 1023 | ▶ | my $nbins = $args{bins} // $args{nbins}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"bins"} // $args{"nbins"}
MC/DC0%0/2
$args{"bins"} // $args{"nbins"}
$args{"bins"}
$args{"nbins"}
Truth table33%1/3
A // B
A= $args{"bins"}B= $args{"nbins"}
| |||||||||||||||||||||||||||||
| 37 | 1023 | ▶ | my $min = $args{min} // 0.0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"min"} // 0
MC/DC0%0/1
$args{"min"} // 0
$args{"min"}
Truth table50%1/2
A
A= $args{"min"}
| |||||||||||||||||||||||||||||
| 38 | 1023 | ▶ | my $max = $args{max} // 100.0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"max"} // 100
MC/DC0%0/1
$args{"max"} // 100
$args{"max"}
Truth table50%1/2
A
A= $args{"max"}
| |||||||||||||||||||||||||||||
| 39 | 1023 | return $class->_create_uniform($nbins, $min, $max, $flags); | |||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||
| 41 | 0 | die "Math::Histo->new: specify 'bins', 'min', 'max' for uniform binning, or 'edges' => [...] for variable binning"; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 11 | my %RULE_MAP = ( | |||||||||||||||||||||||||||
| 46 | auto => 0, | ||||||||||||||||||||||||||||
| 47 | fd => 1, | ||||||||||||||||||||||||||||
| 48 | scott => 2, | ||||||||||||||||||||||||||||
| 49 | sturges => 3, | ||||||||||||||||||||||||||||
| 50 | doane => 4, | ||||||||||||||||||||||||||||
| 51 | knuth => 5, | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 6 | ▶ | sub create_auto { | ||||||||||||||||||||||||||
|
Subroutine
create_auto: called CC=7 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 6 | my ($class, $samples, %args) = @_; | |||||||||||||||||||||||||||
| 56 | 6 | ▶ | my $rule_str = lc($args{rule} // 'auto'); | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"rule"} // "auto"
MC/DC0%0/1
$args{"rule"} // "auto"
$args{"rule"}
Truth table50%1/2
A
A= $args{"rule"}
| |||||||||||||||||||||||||||||
| 57 | 6 | ▶ | my $rule = exists $RULE_MAP{$rule_str} ? $RULE_MAP{$rule_str} : int($rule_str); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 6 | ▶ | my $flags = $args{flags} // 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"flags"} // 0
MC/DC0%0/1
$args{"flags"} // 0
$args{"flags"}
Truth table50%1/2
A
A= $args{"flags"}
| |||||||||||||||||||||||||||||
| 59 | 6 | ▶ | $flags |= 1 if $args{sumw2} || $args{track_sumw2}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"sumw2"} or $args{"track_sumw2"}
MC/DC0%0/2
$args{"sumw2"} or $args{"track_sumw2"}
$args{"sumw2"}
$args{"track_sumw2"}
Truth table33%1/3
A or B
A= $args{"sumw2"}B= $args{"track_sumw2"}
| |||||||||||||||||||||||||||||
| 60 | 6 | ▶ | $flags |= 2 if $args{exact_moments}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 6 | return $class->_create_auto($samples, $rule, $flags); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub estimate_bins { | ||||||||||||||||||||||||||
|
Subroutine
estimate_bins: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 1 | my ($class, $samples, $rule_arg) = @_; | |||||||||||||||||||||||||||
| 66 | 1 | ▶ | my $rule_str = lc($rule_arg // 'auto'); | ||||||||||||||||||||||||||
|
Condition50%1/2
$rule_arg // "auto"
MC/DC0%0/1
$rule_arg // "auto"
$rule_arg
Truth table50%1/2
A
A= $rule_arg
| |||||||||||||||||||||||||||||
| 67 | 1 | ▶ | my $rule = exists $RULE_MAP{$rule_str} ? $RULE_MAP{$rule_str} : int($rule_str); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 1 | return $class->_estimate_bins($samples, $rule); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 5 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||
| 73 | 5 | return $self->_clone; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1002 | ▶ | sub from_binary { | ||||||||||||||||||||||||||
|
Subroutine
from_binary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 1002 | my ($class, $blob) = @_; | |||||||||||||||||||||||||||
| 78 | 1002 | return $class->_deserialize_binary($blob); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub from_json { | ||||||||||||||||||||||||||
|
Subroutine
from_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 1 | my ($class, $json_str) = @_; | |||||||||||||||||||||||||||
| 83 | 1 | return $class->_deserialize_json($json_str); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | sub from_file { | ||||||||||||||||||||||||||
|
Subroutine
from_file: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 1 | my ($class, $path) = @_; | |||||||||||||||||||||||||||
| 88 | 1 | ▶ | open my $fh, '<:raw', $path or die "Math::Histo::from_file: cannot open '$path': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 1 | my $data = do { local $/; <$fh> }; | |||||||||||||||||||||||||||
| 90 | 1 | close $fh; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # If first 6 bytes match binary magic ("\x89LHIST" or "\x89LH2D"), deserialize binary, else JSON | ||||||||||||||||||||||||||||
| 93 | 1 | ▶ | if (substr($data, 0, 6) eq "\x89LHIST" || substr($data, 0, 6) eq "\x89LH2D") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
substr($data, 0, 6) eq "\211LHIST" or substr($data, 0, 6) eq "\211LH2D"
MC/DC0%0/2
substr($data, 0, 6) eq "\211LHIST" or substr($data, 0, 6) eq "\211LH2D"
substr($data, 0, 6) eq "\211LHIST"
substr($data, 0, 6) eq "\211LH2D"
Truth table33%1/3
A or B
A= substr($data, 0, 6) eq "\211LHIST"B= substr($data, 0, 6) eq "\211LH2D"
| |||||||||||||||||||||||||||||
| 94 | 1 | return $class->from_binary($data); | |||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||
| 96 | 0 | return $class->from_json($data); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | ▶ | sub write_file { | ||||||||||||||||||||||||||
|
Subroutine
write_file: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 2 | my ($self, $path, %opts) = @_; | |||||||||||||||||||||||||||
| 102 | 2 | ▶ | my $format = lc($opts{format} // 'binary'); | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"format"} // "binary"
MC/DC100%1/1
$opts{"format"} // "binary"
$opts{"format"}
Truth table100%2/2
A
A= $opts{"format"}
| |||||||||||||||||||||||||||||
| 103 | 2 | ▶ | my $data = ($format eq 'json') ? $self->serialize_json($opts{pretty} // 1) : $self->serialize_binary; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$opts{"pretty"} // 1
MC/DC0%0/1
$opts{"pretty"} // 1
$opts{"pretty"}
Truth table0%0/2
A
A= $opts{"pretty"}
| |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | open my $fh, '>:raw', $path or die "Math::Histo::write_file: cannot open '$path' for writing: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 2 | print $fh $data; | |||||||||||||||||||||||||||
| 106 | 2 | close $fh; | |||||||||||||||||||||||||||
| 107 | 2 | return 1; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | ▶ | sub plot { | ||||||||||||||||||||||||||
|
Subroutine
plot: called CC=17 SCAR=30.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | 2 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||
| 112 | 2 | require Math::Histo::CLI; | |||||||||||||||||||||||||||
| 113 | 2 | require File::Temp; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 2 | my @cmd = ('plot'); | |||||||||||||||||||||||||||
| 116 | 2 | ▶ | push @cmd, "--style=$opts{style}" if defined $opts{style}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 2 | ▶ | if (exists $opts{color}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 1 | ▶ | push @cmd, $opts{color} ? '--color=always' : '--color=never'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 2 | ▶ | push @cmd, "--palette=$opts{palette}" if defined $opts{palette}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 2 | ▶ | push @cmd, '-S' if $opts{sparkline}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 2 | ▶ | push @cmd, "-w=$opts{width}" if defined $opts{width}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 2 | ▶ | push @cmd, "-H=$opts{height}" if defined $opts{height}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 2 | ▶ | push @cmd, '-l' if $opts{log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 2 | ▶ | push @cmd, '-e' if $opts{errors}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 2 | ▶ | push @cmd, "--fit=$opts{fit}" if defined $opts{fit}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 2 | ▶ | push @cmd, '--kde' if $opts{kde}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 2 | ▶ | push @cmd, '--cdf' if $opts{cdf}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 2 | my $tf = File::Temp->new(SUFFIX => '.json', UNLINK => 1); | |||||||||||||||||||||||||||
| 131 | 2 | print $tf $self->serialize_json; | |||||||||||||||||||||||||||
| 132 | 2 | close $tf; | |||||||||||||||||||||||||||
| 133 | 2 | push @cmd, $tf->filename; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 2 | my ($code, $out, $err) = Math::Histo::CLI->capture(@cmd); | |||||||||||||||||||||||||||
| 136 | 2 | ▶ | die "Math::Histo::plot failed: $err" if $code != 0 && $err; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$code != 0 and $err
MC/DC0%0/2
$code != 0 and $err
$code != 0
$err
Truth table33%1/3
A and B
A= $code != 0B= $err
| |||||||||||||||||||||||||||||
| 137 | 2 | ▶ | print $out if !defined $opts{show} || $opts{show}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $opts{"show"} or $opts{"show"}
MC/DC0%0/2
not defined $opts{"show"} or $opts{"show"}
not defined $opts{"show"}
$opts{"show"}
Truth table33%1/3
not(A) or B
A= not defined $opts{"show"}B= $opts{"show"}
| |||||||||||||||||||||||||||||
| 138 | 2 | return $out; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | ▶ | sub sparkline { | ||||||||||||||||||||||||||
|
Subroutine
sparkline: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 1 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||
| 143 | 1 | return $self->plot(%opts, sparkline => 1); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub top { | ||||||||||||||||||||||||||
|
Subroutine
top: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 147 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 148 | 0 | require Math::Histo::CLI; | |||||||||||||||||||||||||||
| 149 | 0 | return Math::Histo::CLI->run('top', @args); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 5 | ▶ | sub fit { | ||||||||||||||||||||||||||
|
Subroutine
fit: called CC=11 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 5 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 154 | 5 | ▶ | my $model_str = lc($args{model} // 'gaussian'); | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"model"} // "gaussian"
MC/DC0%0/1
$args{"model"} // "gaussian"
$args{"model"}
Truth table50%1/2
A
A= $args{"model"}
| |||||||||||||||||||||||||||||
| 155 | 5 | my %model_map = ( | |||||||||||||||||||||||||||
| 156 | gaussian => HISTO_FIT_GAUSSIAN, | ||||||||||||||||||||||||||||
| 157 | gauss => HISTO_FIT_GAUSSIAN, | ||||||||||||||||||||||||||||
| 158 | exponential => HISTO_FIT_EXPONENTIAL, | ||||||||||||||||||||||||||||
| 159 | exp => HISTO_FIT_EXPONENTIAL, | ||||||||||||||||||||||||||||
| 160 | polynomial => HISTO_FIT_POLYNOMIAL, | ||||||||||||||||||||||||||||
| 161 | poly => HISTO_FIT_POLYNOMIAL, | ||||||||||||||||||||||||||||
| 162 | breit_wigner => HISTO_FIT_BREIT_WIGNER, | ||||||||||||||||||||||||||||
| 163 | cauchy => HISTO_FIT_BREIT_WIGNER, | ||||||||||||||||||||||||||||
| 164 | power_law => HISTO_FIT_POWER_LAW, | ||||||||||||||||||||||||||||
| 165 | powerlaw => HISTO_FIT_POWER_LAW, | ||||||||||||||||||||||||||||
| 166 | lognormal => HISTO_FIT_LOG_NORMAL, | ||||||||||||||||||||||||||||
| 167 | log_normal => HISTO_FIT_LOG_NORMAL, | ||||||||||||||||||||||||||||
| 168 | gauss_linear => HISTO_FIT_GAUSSIAN_PLUS_LINEAR, | ||||||||||||||||||||||||||||
| 169 | gauss_poly1 => HISTO_FIT_GAUSSIAN_PLUS_LINEAR, | ||||||||||||||||||||||||||||
| 170 | weibull => HISTO_FIT_WEIBULL, | ||||||||||||||||||||||||||||
| 171 | gamma => HISTO_FIT_GAMMA, | ||||||||||||||||||||||||||||
| 172 | erlang => HISTO_FIT_GAMMA, | ||||||||||||||||||||||||||||
| 173 | poisson => HISTO_FIT_POISSON, | ||||||||||||||||||||||||||||
| 174 | laplace => HISTO_FIT_LAPLACE, | ||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 5 | ▶ | die "Math::Histo::fit: unknown model '$model_str'" unless exists $model_map{$model_str}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 5 | my $model_type = $model_map{$model_str}; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 5 | ▶ | my $initial = $args{initial} // $args{initial_params}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"initial"} // $args{"initial_params"}
MC/DC50%1/2
$args{"initial"} // $args{"initial_params"}
$args{"initial"}
$args{"initial_params"}
Truth table66%2/3
A // B
A= $args{"initial"}B= $args{"initial_params"}
| |||||||||||||||||||||||||||||
| 181 | 5 | ▶ | my $lower = $args{lower_bounds} // $args{lower}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"lower_bounds"} // $args{"lower"}
MC/DC0%0/2
$args{"lower_bounds"} // $args{"lower"}
$args{"lower_bounds"}
$args{"lower"}
Truth table33%1/3
A // B
A= $args{"lower_bounds"}B= $args{"lower"}
| |||||||||||||||||||||||||||||
| 182 | 5 | ▶ | my $upper = $args{upper_bounds} // $args{upper}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"upper_bounds"} // $args{"upper"}
MC/DC0%0/2
$args{"upper_bounds"} // $args{"upper"}
$args{"upper_bounds"}
$args{"upper"}
Truth table33%1/3
A // B
A= $args{"upper_bounds"}B= $args{"upper"}
| |||||||||||||||||||||||||||||
| 183 | 5 | ▶ | my $fixed = $args{fixed} // $args{fixed_mask}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"fixed"} // $args{"fixed_mask"}
MC/DC0%0/2
$args{"fixed"} // $args{"fixed_mask"}
$args{"fixed"}
$args{"fixed_mask"}
Truth table33%1/3
A // B
A= $args{"fixed"}B= $args{"fixed_mask"}
| |||||||||||||||||||||||||||||
| 184 | 5 | ▶ | my $max_iter = $args{max_iter} // $args{max_iterations} // 200; | ||||||||||||||||||||||||||
|
Condition40%2/5
($args{"max_iter"} // $args{"max_iterations"}) // 200
$args{"max_iter"} // $args{"max_iterations"}
MC/DC0%0/2
($args{"max_iter"} // $args{"max_iterations"}) // 200
$args{"max_iter"}
$args{"max_iterations"}
Truth table33%1/3
A // B
A= $args{"max_iter"}B= $args{"max_iterations"}
| |||||||||||||||||||||||||||||
| 185 | 5 | ▶ | my $tol = $args{tol} // 1e-8; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"tol"} // "1e-08"
MC/DC0%0/1
$args{"tol"} // "1e-08"
$args{"tol"}
Truth table50%1/2
A
A= $args{"tol"}
| |||||||||||||||||||||||||||||
| 186 | 5 | ▶ | my $loss = $args{mle} ? HISTO_FIT_LOSS_POISSON_MLE : HISTO_FIT_LOSS_CHI2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 5 | return Math::Histo::Fit->_fit_builtin( | |||||||||||||||||||||||||||
| 189 | $self, $model_type, $initial, $lower, $upper, $fixed, $max_iter, $tol, $loss | ||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 1 | ▶ | sub _op_add { | ||||||||||||||||||||||||||
|
Subroutine
_op_add: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 194 | 1 | my ($a, $b, $swap) = @_; | |||||||||||||||||||||||||||
| 195 | 1 | my $res = $a->clone; | |||||||||||||||||||||||||||
| 196 | 1 | ▶ | $res->add($b) or die "Math::Histo: addition failed (incompatible binning)"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 1 | return $res; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 1 | ▶ | sub _op_sub { | ||||||||||||||||||||||||||
|
Subroutine
_op_sub: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||
| 201 | 1 | my ($a, $b, $swap) = @_; | |||||||||||||||||||||||||||
| 202 | 1 | ▶ | if ($swap) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | my $res = $b->clone; | |||||||||||||||||||||||||||
| 204 | 0 | ▶ | $res->subtract($a) or die "Math::Histo: subtraction failed"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 0 | return $res; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | 1 | my $res = $a->clone; | |||||||||||||||||||||||||||
| 208 | 1 | ▶ | $res->subtract($b) or die "Math::Histo: subtraction failed"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 1 | return $res; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 1 | ▶ | sub _op_mul { | ||||||||||||||||||||||||||
|
Subroutine
_op_mul: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||
| 213 | 1 | my ($a, $b, $swap) = @_; | |||||||||||||||||||||||||||
| 214 | 1 | ▶ | if (!ref($b)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 1 | my $res = $a->clone; | |||||||||||||||||||||||||||
| 216 | 1 | ▶ | $res->scale($b) or die "Math::Histo: scalar multiplication failed"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 1 | return $res; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 0 | my $res = $a->clone; | |||||||||||||||||||||||||||
| 220 | 0 | ▶ | $res->multiply($b) or die "Math::Histo: histogram multiplication failed"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | return $res; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 1 | ▶ | sub _op_div { | ||||||||||||||||||||||||||
|
Subroutine
_op_div: called CC=5 SCAR=20.3
| |||||||||||||||||||||||||||||
| 225 | 1 | my ($a, $b, $swap) = @_; | |||||||||||||||||||||||||||
| 226 | 1 | ▶ | if (!ref($b)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 1 | ▶ | die "Math::Histo: division by zero" if $b == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 1 | my $res = $a->clone; | |||||||||||||||||||||||||||
| 229 | 1 | ▶ | $res->scale(1.0 / $b) or die "Math::Histo: scalar division failed"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 1 | return $res; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | 0 | my $res = $a->clone; | |||||||||||||||||||||||||||
| 233 | 0 | ▶ | $res->divide($b) or die "Math::Histo: histogram division failed"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 0 | return $res; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 1 | ▶ | sub _op_stringify { | ||||||||||||||||||||||||||
|
Subroutine
_op_stringify: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 238 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 239 | 1 | return sprintf("Math::Histo[bins=%d, range=[%.4g, %.4g], entries=%d, mean=%.4g, sd=%.4g]", | |||||||||||||||||||||||||||
| 240 | $self->nbins, $self->min, $self->max, $self->num_entries, $self->mean, $self->std_dev); | ||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 11 | *fill_packed = \&fill_packed_f64; | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 11 | 1; | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | __END__ | ||||||||||||||||||||||||||||