line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::AdaBoost::Classifier; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
24
|
use 5.014; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
83
|
|
4
|
2
|
|
|
2
|
|
3930
|
use overload '&{}' => \&as_closure; |
|
2
|
|
|
|
|
3628
|
|
|
2
|
|
|
|
|
25
|
|
5
|
2
|
|
|
2
|
|
163
|
use List::Util; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
200
|
|
6
|
2
|
|
|
2
|
|
14
|
use Scalar::Util; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
144
|
|
7
|
2
|
|
|
2
|
|
2008
|
use Smart::Args; |
|
2
|
|
|
|
|
95317
|
|
|
2
|
|
|
|
|
464
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
0
|
4
|
args |
11
|
|
|
|
|
|
|
my $class => 'ClassName', |
12
|
|
|
|
|
|
|
my $weak_classifiers => 'ArrayRef[HashRef]'; |
13
|
1
|
|
|
|
|
261
|
bless +{ |
14
|
|
|
|
|
|
|
weak_classifiers => $weak_classifiers, |
15
|
|
|
|
|
|
|
} => $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub as_closure { |
19
|
0
|
|
|
0
|
1
|
0
|
args my $self; |
20
|
0
|
|
|
0
|
|
0
|
return sub { $self->classify(@_) }; |
|
0
|
|
|
|
|
0
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub classify { |
24
|
100
|
|
|
100
|
1
|
20928
|
args_pos |
25
|
|
|
|
|
|
|
my $self, |
26
|
|
|
|
|
|
|
my $feature => 'Any'; |
27
|
100000
|
|
|
|
|
6142044
|
List::Util::sum( |
28
|
|
|
|
|
|
|
map { |
29
|
100
|
|
|
|
|
1138
|
$_->{weight} * $_->{classifier}->($feature); |
30
|
100
|
|
|
|
|
5170
|
} @{ $self->{weak_classifiers} } |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Algorithm::AdaBoost::Classifier |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This class should be instanciated via C<< Algorithm::AdaBoost->train >>. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 METHODS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 as_closure |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Returns a CodeRef which delegates given arguments to C<classify>. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Altough you can use the object itself like a CodeRef because C<&{}> operator is overloaded with this method, it constructs a closure for each call. |
52
|
|
|
|
|
|
|
So if you classify many inputs, you should hold a closure explicitly or use C<classify> directly. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 classify |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Executes binary classification. Takes 1 argument as a feature and return a real number. If the number is positive, given feature is considered to belong to one class. Similary, If the number is negative, given feature is considered to belong to another one class. If zero is returned, it means that the feature cannot be classified (very rare case). |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 AUTHOR |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Koichi SATOH E<lt>sekia@cpan.orgE<gt> |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |