line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::Statistic; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
925
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
54
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
44
|
|
5
|
2
|
|
|
2
|
|
14
|
use XSLoader; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
38
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
5
|
use Exporter 5.57 'import'; |
|
2
|
|
|
|
|
41
|
|
|
2
|
|
|
|
|
173
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [qw] ); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
XSLoader::load('Algorithm::Statistic', $VERSION); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
1; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Algorithm::Statistic - different statistical algorithms library |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Version 0.04 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Algorithm::Statistic qw/:all/; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module provides several math and statistical algorithms implementations in C++ XS for perl. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 Functions |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 C<< kth_order_statistic(array_ref, k [, \&compare]) >> |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This function allows to find k-th order statistic for certain array of elements. |
38
|
|
|
|
|
|
|
Note that this function changes input array (like std::nth_element im STL C++) according to the next rule: |
39
|
|
|
|
|
|
|
element at k-th position will become k-th order atatistic. Each element from the left of k will be less then k-th |
40
|
|
|
|
|
|
|
and each from the right will be greater. This algorithm works with linear complexity O(n). By default you don't have to specify comparator |
41
|
|
|
|
|
|
|
for integers and float numbers. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $statistic = kth_order_statistic($array_ref, $k); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
But in more complex cases it's posible to specify comparator. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $statistic_cmp = kth_order_statistic($array_ref, $k, \&compare); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
For example C function could be simple comparison for strings: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub compare { |
52
|
|
|
|
|
|
|
$_[0] cmp $_[1] |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 C<< median(array_ref, \&compare) >> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This function allows to find median for certain array of elements. This method is the same as n/2 kth order statistc. |
58
|
|
|
|
|
|
|
Like C this function changes input array according to the same rule. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $median = median($array_ref [, \&compare]); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 BUGS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
If you find a bug please contact me via email. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AUTHOR |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Igor Karbachinsky |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Copyright (c) 2015, Igor Karbachinsky. All rights reserved. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |