|
AI::Categorize::VectorBased - Base class for other algorithms |
AI::Categorize::VectorBased - Base class for other algorithms
package Some::Other::Categorizer; use AI::Categorize::VectorBased; @ISA = qw(AI::Categorize::VectorBased); ...
This class implements a few things that vector-based approaches to
document categorization may need. It's not a complete categorization
class in itself, but it can function as the parent for classes like
AI::Categorize::kNN and AI::Categorize::SVM.
The rest of this document describes some of the implementation details of this class. Again, this is not useful in itself for categorization, but rather describes the shared interface between the parent and child classes.
The following methods are provided.
%hash1 and %hash2 as vectors, where the keys represent
the vector coordinates and the values represent the coordinate values,
and returns the dot product of the two vectors.
For instance, if %hash1 contains (x=>4, y=>5) and %hash2
contains (x=>2, y=>7), then dot_product(\%hash1, \%hash2)
will return 4*2+5*7, i.e. 43. If any keys are present in one
hash but not the other, they will be treated as if they have the value
zero in the hash where they are nonexistant. So if %hash1 contains
(x=>4, y=>5) and %hash2 contains (y=>1, z=>6), then
dot_product(\%hash1, \%hash2) will return 5*1, i.e. 5.
Perl is actually pretty good at doing dot products, because the intersection of the set of keys of two hashes can be found very quickly.
norm(\%hash)%hash, i.e.
sqrt(sum(values %hash).
normalize(\%hash)%hash by norm(\%hash).
trim_features($target)
Ken Williams, ken@forum.swarthmore.edu
Copyright 2000-2001 Ken Williams. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AI::Categorize(3)
|
AI::Categorize::VectorBased - Base class for other algorithms |