Branch Coverage

blib/lib/Algorithm/Classifier/IsolationForest.pm
Criterion Covered Total %
branch 368 436 84.4


line true false branch
2740 1 212 unless $mode eq "axis" or $mode eq "extended"
2753 1 211 unless $missing =~ /\A(?:die|zero|impute|nan)\z/
2757 1 210 unless $impute_with =~ /\A(?:mean|median)\z/
2769 1 209 unless $voting =~ /\A(?:mean|majority)\z/
2772 166 43 if (defined $args{'seed'})
2784 62 57 $args{'use_c'} && $HAS_C ? :
119 90 defined $args{'use_c'} ? :
2788 2 3 $args{'use_openmp'} && $HAS_OPENMP ? :
5 204 defined $args{'use_openmp'} ? :
2790 59 150 unless $use_c
2795 9 200 $args{'use_openmp_fit'} && $HAS_OPENMP && $use_c ? :
2829 1 416 if defined $self->{$doc} and ref $self->{$doc}
2832 6 202 if defined $self->{'feature_descriptions'}
2839 9 196 if (defined $args{'mungers'})
2841 1 8 unless ref $args{'mungers'} eq "HASH"
2843 1 7 unless ref $self->{'feature_names'} eq "ARRAY" and @{$self->{'feature_names'};}
2849 1 200 unless $self->{'n_trees'} >= 1
2850 1 199 unless $self->{'sample_size'} >= 1
2852 1 198 if defined $self->{'extension_level'} and $self->{'extension_level'} < 0
2855 3 195 if defined $self->{'contamination'} and not $self->{'contamination'} > 0 && $self->{'contamination'} <= 0.5
2858 2 9 if defined $self->{'parallel_fit'} and !($self->{'parallel_fit'} =~ /^\d+$/) || $self->{'parallel_fit'} < 1
2901 1 8 unless defined $voting and $voting =~ /\A(?:mean|majority)\z/
2904 1 7 if $self->{'voting'} eq $voting
2913 4 3 if ($recalibrate)
2914 1 3 unless ref $data eq "ARRAY" and @$data
2921 3 3 if $recalibrate
3026 6 166 unless ref $data eq "ARRAY" and @$data
3029 4 162 unless ref $data->[0] eq "ARRAY" and @{$data->[0];}
3049 32 124 if ($self->{'mode'} eq 'extended') { }
3054 4 28 defined $self->{'extension_level'} ? :
3055 0 32 if $ext < 0
3056 2 30 if $ext > $max_ext
3067 0 156 defined $self->{'max_depth'} ? :
3068 0 156 if $limit < 1
3071 154 2 if defined $self->{'seed'}
3074 8 148 if (defined $workers and $workers > 1 and $self->{'n_trees'} > 1 and _fork_supported()) { }
7 141 elsif ($self->{'_use_c'} and $self->{'_use_openmp_fit'}) { }
92 49 elsif ($self->{'_use_c'}) { }
3116 14 142 if defined $self->{'contamination'}
3118 107 49 if $self->{'_use_c'}
3144 0 4 unless ref $data eq "ARRAY" and @$data
3200 109 0 if ($self->{'_use_c'} and $self->{'_c_nodes'})
3214 0 1 $self->{'missing'} eq 'nan' ? :
3257 8 41 defined $self->{'threshold'} ? :
240 49 defined $threshold ? :
3264 18 269 if ($self->{'voting'} eq "majority")
3270 16 0 if ($self->{'_use_c'} and $self->{'_c_nodes'})
3281 0 2 $self->{'missing'} eq 'nan' ? :
3287 1003 2394 if (_path_length($x, $trees->[$ti], 0, $nan) <= $cut)
3289 9 994 if ($votes >= $maj)
3291 117 3271 if $votes + ($t - 1 - $ti) < $maj
3303 252 3 if ($self->{'_use_c'} and $self->{'_c_nodes'} and $self->{'c_psi'} > 0 and $threshold > 0 and $threshold < 1)
3327 414 871 $_ >= $threshold ? :
3380 5 1008 unless ref $row eq "HASH"
3388 945 62 if (my $plan = _plan($self))
3390 1 944 if $@
3397 0 57 unless defined $self->{'feature_names'} and ref $self->{'feature_names'} eq "ARRAY" and @{$self->{'feature_names'};}
3405 5 52 if @unknown
3409 7 45 if @missing
3439 0 6 unless ref $rows eq "ARRAY"
3442 0 6 unless $plan
3446 1 325 if $@
3491 9 388 if ($self->{'voting'} eq "majority")
3492 0 9 defined $self->{'threshold'} ? :
3495 7 0 if ($self->{'_use_c'} and $self->{'_c_nodes'})
3516 326 7 if ($self->{'_use_c'} and $self->{'_c_nodes'})
3524 325 0 if ($c > 0)
3534 3 59 $self->{'missing'} eq 'nan' ? :
3547 62 0 if ($c > 0)
3606 2 18 defined $self->{'threshold'} ? :
122 20 defined $threshold ? :
3612 3 139 if ($self->{'voting'} eq "majority")
3618 3 0 if ($self->{'_use_c'} and $self->{'_c_nodes'})
3629 0 0 $_ >= $maj ? :
3633 0 0 $_ >= $maj ? :
3640 137 0 if ($self->{'_use_c'} and $self->{'_c_nodes'} and $self->{'c_psi'} > 0 and $threshold > 0 and $threshold < 1)
3668 4 8 if ($score >= $threshold) { }
3730 0 10 defined $self->{'threshold'} ? :
225 10 defined $threshold ? :
3735 6 229 if ($self->{'voting'} eq "majority")
3741 4 0 if ($self->{'_use_c'} and $self->{'_c_nodes'})
3759 9 117 $_ >= $maj ? :
3766 227 0 if ($self->{'_use_c'} and $self->{'_c_nodes'} and $self->{'c_psi'} > 0 and $threshold > 0 and $threshold < 1)
3792 4 8 $_ >= $threshold ? :
3916 2 53 unless ref $payload eq "HASH" and defined $payload->{'format'}
3921 14 39 if ($payload->{'format'} eq "Algorithm::Classifier::IsolationForest::Online")
3927 0 39 unless $payload->{'format'} eq "Algorithm::Classifier::IsolationForest"
3934 1 38 if (($payload->{'version'} // 0) < 1)
3976 1 38 unless @{$self->{'trees'};}
3981 38 0 if defined $self->{'psi_used'}
3984 38 0 if $self->{'_use_c'}
4126 16 37 unless (ref $proto)
4128 1 15 if $@
4131 1 51 unless ref $proto eq "HASH"
4136 1 50 unless defined $proto->{'format'} and not ref $proto->{'format'} and $proto->{'format'} eq "Algorithm::Classifier::IsolationForest::Prototype"
4139 1 49 if not ref $version and $version =~ /^\d+$/ and $version > 1
4143 1 318 unless $k =~ /\A(?:format|version|class|schema_version|schema_description|schema|params)\z/
4148 1 46 unless defined $which and not ref $which and $which =~ /\A(?:batch|online)\z/
4153 1 85 unless defined $proto->{$req} and not ref $proto->{$req} and length $proto->{$req}
4157 1 41 unless ref $schema eq "HASH"
4161 2 88 unless $PROTO_SCHEMA_KEYS{$which}{$k}
4164 2 37 unless ref $tags eq "ARRAY" and @$tags
4167 1 79 unless defined $t and not ref $t and length $t
4171 22 14 if defined $schema->{'feature_descriptions'}
4173 1 34 if defined $schema->{'mungers'} and ref $schema->{'mungers'} ne "HASH"
4176 0 68 if defined $schema->{$str} and ref $schema->{$str}
4180 1 33 if defined $params and ref $params ne "HASH"
4182 0 33 unless $params
4186 3 96 unless $PROTO_PARAM_KEYS{$which}{$k}
4222 1 14 if $k =~ /\A(?:feature_names|feature_descriptions|mungers|missing|impute_with|schema_version|schema_description)\z/
4228 1 13 unless $PROTO_PARAM_KEYS{$which}{$k}
4232 0 15 unless $proto->{'params'}
4239 17 43 if defined $schema->{$k}
4242 7 8 if ($which eq "online")
4288 1 3 unless ref $self->{'feature_names'} eq "ARRAY" and @{$self->{'feature_names'};}
4295 1 2 if ref $self->{'feature_descriptions'} eq "HASH" and %{$self->{'feature_descriptions'};}
4297 0 3 if ref $self->{'mungers'} eq "HASH" and %{$self->{'mungers'};}
4299 0 3 if defined $self->{'missing'} and $self->{'missing'} eq "impute"
4307 0 3 if defined $self->{'max_depth'}
4309 0 3 if defined($self->{'extension_level_used'} // $self->{'extension_level'})
4310 1 2 if defined $self->{'contamination'}
4366 304063 430532 if $n <= 1
4367 73096 357436 if $n == 2
4391 0 0 $theta <= 0.5 ? :
0 36 if $c <= 0
4392 0 36 if $theta <= 0
4421 0 23 if $k >= $n
4424 17 6 if $desc->[$k] < $v
4432 4 2 if ($i > 0 and $k - $i < $j - $k)
4437 2 0 $j < $n ? :
4449 0 4 $self->{'missing'} eq 'nan' ? :
4453 2854 7226 if _path_length($data->[$i], $tree, 0, $nan) <= $cut
4490 9 8 $self->{'voting'} eq 'majority' ? :
4496 0 17 if $k < 1
4497 0 17 if $k > $n_pts
4509 0 9 $self->{'missing'} eq 'nan' ? :
4513 0 9 unless $c > 0
4572 145963 149304 if $depth >= $limit or $size <= 1
4585 23338 125966 if ($nan) { }
4589 72249 698528 unless defined $v
4590 87444 611084 if not defined $lo[$f] or $v < $lo[$f]
4591 86526 612002 if not defined $hi[$f] or $v > $hi[$f]
4598 615137 6443277 if not defined $lo[$f] or $v < $lo[$f]
4599 612680 6445734 if not defined $hi[$f] or $v > $hi[$f]
4607 333681 55 if defined $lo[$_]
4610 2795 146509 unless @varying
4613 22782 123727 $self->{'mode'} eq 'extended' ? :
4621 123727 22782 $node->[0] == 1 ? :
4651 15096 108631 if ($nan) { }
4654 111298 128069 if (defined $v and $v < $split) { }
4659 1096061 1099946 if ($row->[$attr] < $split) { }
4676 3606 19176 if $active > scalar @$varying
4711 6947 15835 if ($nan) { }
4717 26240 236042 unless (defined $v)
4720 57761 81925 if (not $missing and $dot <= $b) { }
4727 197051 203302 if ($dot <= $b) { }
4754 2757920 229682 if ($node->[0] == 1) { }
4755 4852 2753068 if ($nan) { }
4757 963 3889 defined $v && $v < $node->[2] ? :
4759 1381598 1371470 ($$x[$node->[1]] // 0) < $node->[2] ? :
4763 3034 226648 if ($nan) { }
4768 1920 2807 unless (defined $v)
4771 552 2482 !$missing && $dot <= $b ? :
4775 111563 115085 $dot <= $b ? :
4787 0 0 if ($node->{'leaf'}) { }
0 0 elsif (exists $node->{'attr'}) { }
4831 305678 298861 if ($node->[0] == 0) { }
269152 29709 elsif ($node->[0] == 1) { }
4862 25903 3806 if (defined $n_features and $num == $n_features) { }
4885 795 6022 @coef_idx ? :
4886 795 6022 @coef_val ? :
4911 9 1207 unless ref $self->{'trees'} eq "ARRAY" and @{$self->{'trees'};}
4929 0 35 unless ref $fd eq "HASH"
4931 1 34 unless ref $tags eq "ARRAY" and @$tags
4936 3 31 unless $known{$k}
4938 1 30 if ref $fd->{$k}
4948 0 15 unless ref $tags eq "ARRAY" and @$tags
4951 0 15 unless eval { do { require Algorithm::ToNumberMunger; 1 } }
4967 62 952 unless $self->{'mungers'}
4978 6 2 if defined $cached
4981 2 0 ($Config::Config{'d_fork'} || '') eq 'define' ? :
5004 1 7 if $workers > $n_trees
5012 3 23 $w < $extras ? :
5019 0 26 unless $share > 0
5021 0 26 unless pipe my $rh, my $wh
5023 0 26 unless defined $pid
5025 0 26 if ($pid == 0)
5029 0 0 if (defined $self->{'seed'})
5046 0 0 if ($self->{'_use_c'}) { }
5079 0 26 if $exit != 0
5082 0 26 if $@ or ref $trees ne "ARRAY"
5108 14 78 $self->{'mode'} eq 'extended' ? :
5149 5 2 $self->{'mode'} eq 'extended' ? :
5173 6582 6262 if ($type == 0) { }
1604 4658 elsif ($type == 1) { }
5229 1 5 unless $self->{'_use_c'}
5230 2 3 unless ref $data eq "ARRAY"
5250 344 737 if (ref $data eq "Algorithm::Classifier::IsolationForest::PackedData")
5252 1 343 unless $data->{'n_feats'} == $self->{'n_features'}
5269 99 0 if ref $data eq "ARRAY"
5270 0 0 if (ref $data eq "Algorithm::Classifier::IsolationForest::PackedData")
5308 136 26 if ($m eq "die")
5312 50077 2 if defined $row->[$f]
5322 8 18 if $m eq "nan"
5342 12 6 $m eq 'impute' ? :
5346 8 6 if $m eq "impute"
5349 7 7 if $self->{'_use_c'}
5365 6 6 if ($self->{'_use_c'})
5367 2 4 $how eq 'median' ? :
5376 2 10 unless @vals
5378 4 6 if ($how eq 'median') { }
5381 2 2 $k % 2 ? :
5413 3855 223 if (defined $r->[$_]) { }
5424 9 830 if $m eq "nan"
5425 9 821 if ($m eq "impute")
5428 0 9 unless ref $fill eq "ARRAY" and @$fill == $self->{'n_features'}
5442 3 75 if ($self->{'missing'} eq "impute")
5444 0 3 unless ref $self->{'missing_fill'} eq "ARRAY"