| 1 | package ICC::Support::geo1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = 0.11; | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # revised 2016-05-17 | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Copyright © 2004-2018 by William B. Birkett | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # add development directory | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use lib 'lib'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # inherit from Shared | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use parent qw(ICC::Shared); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # create new object | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # hash keys are: | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # 'points' value is an array reference containing center coordinates | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # 'matrix' value is an optional weight matrix, sometimes the inverse covariance matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # the weight matrix must have the same dimension as the center coordinate | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # parameters: ([ref_to_parameter_hash]) | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # get object class | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # create empty geo1 object | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my $self = [ | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | {}, # object header | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | [], # points array | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | [] # weight matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # if one parameter, a hash reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | if (@_ == 1 && ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # create new object from parameter hash | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | _new_from_hash($self, @_); | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # bless object | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # return object reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # compute radius | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # parameters: (ref_to_input_array) | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # returns: (radius) | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | sub transform { | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my ($self, $in) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # if object has covariance matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if (defined($self->[2]) && (0 != @{$self->[2]})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->[2] and 0 != @{$self->[2];}
MC/DC0%0/2
defined $self->[2] and 0 != @{$self->[2];}
defined $self->[2]
0 != @{$self->[2];}
Truth table0%0/3
A and B
A= defined $self->[2]B= 0 != @{$self->[2];}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # return Mahalanobis distance | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return(ICC::Support::Lapack::mahal($in, $self->[1], $self->[2])); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # return Euclidean distance | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return(ICC::Support::Lapack::euclid($in, $self->[1])); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # compute Jacobian matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # parameters: (ref_to_input_array) | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # returns: (Jacobian_matrix, [radius]) | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | sub jacobian { | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my ($self, $in) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
jacobian: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # compute radial Jacobian | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($jac, $r) = _radjac($self, $in); | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # if array wanted | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # return Jacobian matrix and radius | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return(Math::Matrix->new($jac), $r); | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # return Jacobian matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return(Math::Matrix->new($jac)); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # get/set points array | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # parameters: ([ref_to_points_array]) | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # returns: (ref_to_points_array) | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub points { | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my ($self, $points) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
points: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # if parameter supplied | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if (defined($points)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # verify an array reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | (ref($points) eq 'ARRAY') or croak('\'points\' parameter not an array'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # verify point coordinates | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | (@{$points} == grep {Scalar::Util::looks_like_number($_)} @{$points}) or croak('\'points\' array contains invalid coordinates'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # copy points array | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $self->[1] = [@{$points}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # return end point array reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | return($self->[1]); | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # get/set weight matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # parameters: ([ref_to_weight_matrix]) | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # returns: (ref_to_weight_matrix) | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | sub matrix { | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my ($self, $matrix) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matrix: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # if parameter supplied | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if (defined($matrix)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # verify a 2-D array or Math::Matrix object | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | ((ref($matrix) eq 'ARRAY' && @{$matrix} == grep {ref() eq 'ARRAY'} @{$matrix}) || UNIVERSAL::isa($matrix, 'Math::Matrix')) or croak('\'matrix\' parameter not a 2-D array or Math::Matrix object'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $matrix eq "ARRAY" and @{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;}) or UNIVERSAL::isa($matrix, "Math::Matrix")
ref $matrix eq "ARRAY" and @{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;})
MC/DC0%0/3
ref $matrix eq "ARRAY" and @{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;}) or UNIVERSAL::isa($matrix, "Math::Matrix")
ref $matrix eq "ARRAY"
@{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;})
UNIVERSAL::isa($matrix, "Math::Matrix")
Truth table0%0/5
A and B or C
A= ref $matrix eq "ARRAY"B= @{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;})C= UNIVERSAL::isa($matrix, "Math::Matrix")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # verify first row contains only numeric values | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | (@{$matrix->[0]} == grep {Scalar::Util::looks_like_number($_)} @{$matrix->[0]}) or croak('\'matrix\' parameter contains non-numeric values'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # verify matrix is square | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | (@{$matrix} == @{$matrix->[0]}) or croak('\'matrix\' parameter not square matrix'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # copy weight matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $self->[2] = Storable::dclone($matrix); | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # return matrix reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return($self->[2]); | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # print object contents to string | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # format is an array structure | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # parameter: ([format]) | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # returns: (string) | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | sub sdump { | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my ($self, $p) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sdump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my ($s, $fmt); | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # resolve parameter to an array reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # get format string | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $p->[0] and not ref $p->[0]
MC/DC0%0/2
defined $p->[0] and not ref $p->[0]
defined $p->[0]
not ref $p->[0]
Truth table0%0/3
A and not(B)
A= defined $p->[0]B= not ref $p->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # set string to object ID | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # return | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return($s); | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # compute radial Jacobian | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # parameters: (ref_to_object, ref_to_input_vector) | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # returns: (Jacobian_vector, radius) | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | sub _radjac { | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my ($self, $in) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_radjac: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my ($jac, $r, $wwt); | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # for each dimension | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | for my $i (0 .. $#{$self->[1]}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # compute input vector element | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $jac->[$i] = ($in->[$i] - $self->[1][$i]); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # if object has weight matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if (defined($self->[2]) && @{$self->[2]}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->[2] and @{$self->[2];}
MC/DC0%0/2
defined $self->[2] and @{$self->[2];}
defined $self->[2]
@{$self->[2];}
Truth table0%0/3
A and B
A= defined $self->[2]B= @{$self->[2];}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # radius is Mahalanobis distance | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $r = ICC::Support::Lapack::mahal($in, $self->[1], $self->[2]); | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # for each row | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | for my $i (0 .. $#{$self->[2]}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # for each column | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | for my $j (0 .. $#{$self->[2][0]}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # set matrix element (W + Wᵀ)/2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $wwt->[$i][$j] = ($self->[2][$i][$j] + $self->[2][$j][$i])/2; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # multiply Jacobian by (W + Wᵀ)/2 matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $jac = ICC::Support::Lapack::vec_xplus($wwt, $jac, {'trans' => 'T'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # radius is Euclidean distance | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $r = ICC::Support::Lapack::euclid($in, $self->[1]); | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # if radius is zero | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if ($r == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # set Jacobian to all ones | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $jac = [(1) x @{$self->[1]}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # for each dimension | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | for my $i (0 .. $#{$self->[1]}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # divide by radius | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $jac->[$i] /= $r; | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # return | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | return($jac, $r); | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # populate object from parameter hash | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # parameters: (object_reference, ref_to_parameter_hash) | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | sub _new_from_hash { | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # get parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | my ($self, $hash) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_from_hash: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # local variables | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my ($points, $matrix, $info); | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # get points array | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ($points = $hash->{'points'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # verify an array reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | (ref($points) eq 'ARRAY') or croak('\'points\' parameter not an array'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # verify point coordinates | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | (@{$points} == grep {Scalar::Util::looks_like_number($_)} @{$points}) or croak('\'points\' array contains invalid coordinates'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # copy points array | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $self->[1] = [@{$points}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # get weight matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if ($matrix = $hash->{'matrix'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # verify a 2-D array or Math::Matrix object | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | ((ref($matrix) eq 'ARRAY' && @{$matrix} == grep {ref() eq 'ARRAY'} @{$matrix}) || UNIVERSAL::isa($matrix, 'Math::Matrix')) or croak('\'matrix\' parameter not a 2-D array or Math::Matrix object'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $matrix eq "ARRAY" and @{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;}) or UNIVERSAL::isa($matrix, "Math::Matrix")
ref $matrix eq "ARRAY" and @{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;})
MC/DC0%0/3
ref $matrix eq "ARRAY" and @{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;}) or UNIVERSAL::isa($matrix, "Math::Matrix")
ref $matrix eq "ARRAY"
@{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;})
UNIVERSAL::isa($matrix, "Math::Matrix")
Truth table0%0/5
A and B or C
A= ref $matrix eq "ARRAY"B= @{$matrix;} == grep({ref $_ eq "ARRAY";} @{$matrix;})C= UNIVERSAL::isa($matrix, "Math::Matrix")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # verify first row contains only numeric values | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | (@{$matrix->[0]} == grep {Scalar::Util::looks_like_number($_)} @{$matrix->[0]}) or croak('\'matrix\' parameter contains non-numeric values'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # verify matrix is square | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | (@{$matrix} == @{$matrix->[0]}) or croak('\'matrix\' parameter not square matrix'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # verify matrix and center have same dimensions | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | (@{$matrix} == @{$self->[1]}) or croak('\'matrix\' and \'center\' have different dimensions'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # copy weight matrix | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $self->[2] = Storable::dclone($matrix); | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||