Categorizer/Learner/Rocchio.pm

filter: Statementstmt 100% 35 / 35 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 66.6% 2 / 3 totaltotal 97.8% 45 / 46 CC 2 SCAR 2.0
CC
2
Cov
100%
create_model
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Categorizer/ObjectSet.pm ↑ Summary Categorizer/Document/Text.pm »
1 package AI::Categorizer::Learner::Rocchio;
2 1 $VERSION = '0.01';
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Params::Validate qw(:types);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use AI::Categorizer::FeatureVector;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use AI::Categorizer::Learner::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base qw(AI::Categorizer::Learner::Boolean);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 __PACKAGE__->valid_params
11 (
12 positive_setting => {type => SCALAR, default => 16 },
13 negative_setting => {type => SCALAR, default => 4 },
14 threshold => {type => SCALAR, default => 0.1},
15 );
16  
17 1 ▶sub create_model {
Subroutine create_model: called CC=2 SCAR=6.9
Pod undocumented
18 1 my $self = shift;
19 1 foreach my $doc ($self->knowledge_set->documents) {
20 4 $doc->features->normalize;
21 }
22
23 1 $self->{model}{all_features} = $self->knowledge_set->features(undef);
24 1 $self->SUPER::create_model(@_);
25 1 delete $self->{knowledge_set};
26 }
27  
28 2 ▶sub create_boolean_model {
Subroutine create_boolean_model: called CC=1 SCAR=0.0
Pod documented
29 2 my ($self, $positives, $negatives, $cat) = @_;
30 2 my $posdocnum = @$positives;
31 2 my $negdocnum = @$negatives;
32
33 2 my $beta = $self->{positive_setting};
34 2 my $gamma = $self->{negative_setting};
35
36 2 my $profile = $self->{model}{all_features}->clone->scale(-$gamma/$negdocnum);
37 2 my $f = $cat->features(undef)->clone->scale( $beta/$posdocnum + $gamma/$negdocnum );
38 2 $profile->add($f);
39  
40 2 return $profile->normalize;
41 }
42  
43 16 ▶sub get_boolean_score {
Subroutine get_boolean_score: called CC=1 SCAR=0.0
Pod documented
44 16 my ($self, $newdoc, $profile) = @_;
45 16 return $newdoc->features->normalize->dot($profile);
46 }
47  
48 1 1;
49  
50  
51  
52  
53  
54  
55  
56  
« Categorizer/ObjectSet.pm ↑ Summary Categorizer/Document/Text.pm »