File Coverage

blib/lib/App/RecordStream/Aggregator/Correlation.pm
Criterion Covered Total %
statement 21 23 91.3
branch n/a
condition n/a
subroutine 7 9 77.7
pod 0 3 0.0
total 28 35 80.0


line stmt bran cond sub pod time code
1             package App::RecordStream::Aggregator::Correlation;
2              
3             our $VERSION = "4.0.24";
4              
5 6     6   61172 use strict;
  6         13  
  6         148  
6 6     6   27 use warnings;
  6         11  
  6         135  
7              
8 6     6   317 use App::RecordStream::Aggregator::Ord2Bivariate;
  6         10  
  6         114  
9 6     6   28 use App::RecordStream::Aggregator;
  6         12  
  6         90  
10 6     6   317 use App::RecordStream::DomainLanguage::Registry;
  6         13  
  6         115  
11              
12 6     6   46 use base 'App::RecordStream::Aggregator::Ord2Bivariate';
  6         13  
  6         1212  
13              
14             #sub new -- passed through
15              
16             #sub new_from_valuation -- passed through
17              
18             sub squish
19             {
20 2     2 0 15 my ($this, $cookie) = @_;
21              
22 2         6 my ($sum1, $sumx, $sumy, $sumxy, $sumx2, $sumy2) = @$cookie;
23              
24 2         13 return ($sumxy * $sum1 - $sumx * $sumy) / sqrt(($sumx2 * $sum1 - $sumx ** 2) * ($sumy2 * $sum1 - $sumy ** 2));
25             }
26              
27             sub long_usage
28             {
29             return <
30             Usage: corr,,
31             Correlation of specified fields.
32              
33             This is Cov(X, Y) / sqrt(Var(X) * Var(Y)). See help on aggregators cov and var
34             for how Cov(...) and Var(...) are computed. Ultimately this value is in [-1,
35             1] where larger negative values indicate larger inverse correlation and larger
36             positive values indicate larger positive correlation.
37             EOF
38 0     0 0   }
39              
40             sub short_usage
41             {
42 0     0 0   return "find correlation of provided fields";
43             }
44              
45             App::RecordStream::Aggregator->register_implementation('corr', __PACKAGE__);
46             App::RecordStream::Aggregator->register_implementation('correl', __PACKAGE__);
47             App::RecordStream::Aggregator->register_implementation('correlation', __PACKAGE__);
48              
49             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'corr', 'VALUATION', 'VALUATION');
50             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'correl', 'VALUATION', 'VALUATION');
51             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'correlation', 'VALUATION', 'VALUATION');
52              
53             1;