blib/lib/Math/Histo/KDE.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 50.0% 4 / 8 Conditioncond 52.3% 11 / 21 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 3 totaltotal 65.8% 56 / 85 CC 15 SCAR 20.6
CC
15
Cov
75%
new
11.1
from_histogram
8.3
pdf
2.0
CRAP 7.8
« blib/lib/Math/Histo.pm ↑ Summary blib/lib/Math/Histo/Fit.pm »
1 package Math::Histo::KDE;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Math::Histo ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Math::Histo::Constants ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.4.2';
9  
10 1 my %KERNEL_MAP = (
11 gaussian => Math::Histo::Constants::HISTO_KDE_KERNEL_GAUSSIAN,
12 epanechnikov => Math::Histo::Constants::HISTO_KDE_KERNEL_EPANECHNIKOV,
13 uniform => Math::Histo::Constants::HISTO_KDE_KERNEL_UNIFORM,
14 boxcar => Math::Histo::Constants::HISTO_KDE_KERNEL_UNIFORM,
15 triangular => Math::Histo::Constants::HISTO_KDE_KERNEL_TRIANGULAR,
16 biweight => Math::Histo::Constants::HISTO_KDE_KERNEL_BIWEIGHT,
17 quartic => Math::Histo::Constants::HISTO_KDE_KERNEL_BIWEIGHT,
18 cosine => Math::Histo::Constants::HISTO_KDE_KERNEL_COSINE,
19 );
20  
21 1 my %BW_MAP = (
22 silverman => Math::Histo::Constants::HISTO_KDE_BW_SILVERMAN,
23 scott => Math::Histo::Constants::HISTO_KDE_BW_SCOTT,
24 manual => Math::Histo::Constants::HISTO_KDE_BW_MANUAL,
25 );
26  
27 7 ▶sub new {
Subroutine new: called CC=9 SCAR=24.1
Pod undocumented
28 7 my ($class, %args) = @_;
29 7 ▶ my $samples = $args{samples} // $args{data} // croak("Math::Histo::KDE->new: 'samples' arrayref required");
Condition40%2/5
($args{"samples"} // $args{"data"}) // croak("Math::Histo::KDE->new: 'samples' arrayref required")
l!l
70
$args{"samples"} // $args{"data"}
l!l&&r!l&&!r
700
MC/DC0%0/2
($args{"samples"} // $args{"data"}) // croak("Math::Histo::KDE->new: 'samples' arrayref required")
$args{"samples"} $args{"data"}
Truth table33%1/3
A // B
A= $args{"samples"}B= $args{"data"}
ABresult
1X1
011
000
30 7 my $weights = $args{weights};
31 7 ▶ my $kernel = $args{kernel} // 'gaussian';
Condition50%1/2
$args{"kernel"} // "gaussian"
l!l
70
MC/DC0%0/1
$args{"kernel"} // "gaussian"
$args{"kernel"}
Truth table50%1/2
A
A= $args{"kernel"}
Aresult
11
00
32 7 ▶ my $bw_method = $args{bw_method} // 'silverman';
Condition50%1/2
$args{"bw_method"} // "silverman"
l!l
70
MC/DC0%0/1
$args{"bw_method"} // "silverman"
$args{"bw_method"}
Truth table50%1/2
A
A= $args{"bw_method"}
Aresult
11
00
33 7 ▶ my $bandwidth = $args{bandwidth} // 0.0;
Condition100%2/2
$args{"bandwidth"} // 0
l!l
61
MC/DC100%1/1
$args{"bandwidth"} // 0
$args{"bandwidth"}
Truth table100%2/2
A
A= $args{"bandwidth"}
Aresult
11
00
34 7 ▶ my $bw_adjust = $args{bw_adjust} // 1.0;
Condition50%1/2
$args{"bw_adjust"} // 1
l!l
07
MC/DC0%0/1
$args{"bw_adjust"} // 1
$args{"bw_adjust"}
Truth table50%1/2
A
A= $args{"bw_adjust"}
Aresult
11
00
35  
36 7 ▶ my $k_code = exists $KERNEL_MAP{lc($kernel)} ? $KERNEL_MAP{lc($kernel)} : int($kernel);
Branch: 1 branch
BranchTrueFalseTotal
exists $KERNEL_MAP{lc $kernel} ? : 7 0 7
37 7 ▶ my $bw_code = exists $BW_MAP{lc($bw_method)} ? $BW_MAP{lc($bw_method)} : int($bw_method);
Branch: 1 branch
BranchTrueFalseTotal
exists $BW_MAP{lc $bw_method} ? : 7 0 7
38  
39 7 return $class->_create($samples, $weights, $k_code, $bw_code, $bandwidth, $bw_adjust);
40 }
41  
42 1 ▶sub from_histogram {
Subroutine from_histogram: called CC=7 SCAR=21.2
Pod undocumented
43 1 my ($class, $h, %args) = @_;
44 1 ▶ my $kernel = $args{kernel} // 'gaussian';
Condition50%1/2
$args{"kernel"} // "gaussian"
l!l
01
MC/DC0%0/1
$args{"kernel"} // "gaussian"
$args{"kernel"}
Truth table50%1/2
A
A= $args{"kernel"}
Aresult
11
00
45 1 ▶ my $bw_method = $args{bw_method} // 'silverman';
Condition50%1/2
$args{"bw_method"} // "silverman"
l!l
01
MC/DC0%0/1
$args{"bw_method"} // "silverman"
$args{"bw_method"}
Truth table50%1/2
A
A= $args{"bw_method"}
Aresult
11
00
46 1 ▶ my $bandwidth = $args{bandwidth} // 0.0;
Condition50%1/2
$args{"bandwidth"} // 0
l!l
01
MC/DC0%0/1
$args{"bandwidth"} // 0
$args{"bandwidth"}
Truth table50%1/2
A
A= $args{"bandwidth"}
Aresult
11
00
47 1 ▶ my $bw_adjust = $args{bw_adjust} // 1.0;
Condition50%1/2
$args{"bw_adjust"} // 1
l!l
01
MC/DC0%0/1
$args{"bw_adjust"} // 1
$args{"bw_adjust"}
Truth table50%1/2
A
A= $args{"bw_adjust"}
Aresult
11
00
48  
49 1 ▶ my $k_code = exists $KERNEL_MAP{lc($kernel)} ? $KERNEL_MAP{lc($kernel)} : int($kernel);
Branch: 1 branch
BranchTrueFalseTotal
exists $KERNEL_MAP{lc $kernel} ? : 1 0 1
50 1 ▶ my $bw_code = exists $BW_MAP{lc($bw_method)} ? $BW_MAP{lc($bw_method)} : int($bw_method);
Branch: 1 branch
BranchTrueFalseTotal
exists $BW_MAP{lc $bw_method} ? : 1 0 1
51  
52 1 return $class->_create_from_histo($h, $k_code, $bw_code, $bandwidth, $bw_adjust);
53 }
54  
55 0 ▶sub pdf {
Subroutine pdf: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ($self, $x) = @_;
57 0 return $self->eval($x);
58 }
59  
60 1 1;
61  
62 __END__
« blib/lib/Math/Histo.pm ↑ Summary blib/lib/Math/Histo/Fit.pm »