Normalize - normalize scores between 0 and 1.
Version 0.31
use Normalize; my %iq_rate = ('Professor' => 125.12, 'Bender' => 64, 'Dr. Zoidberg' => 28.6, 'Fray' => 13); my %weight_rate = ('Professor' => 70.2, 'Bender' => 600, 'Dr. Zoidberg' => 200, 'Fray' => 120); my $norm = Normalize->new('round_to' => 0.001); #larger score is better: $norm->normalize_to_max(\%iq_rate); print "\n#iq rate: larger iq is better:\n"; foreach my $key (keys %iq_rate) { print "$key = $iq_rate{$key}\n"; } #iq rate: larger iq is better: #1.000 Professor #0.512 Bender #0.229 Dr. Zoidberg #0.104 Fray #smaller score is better $norm->normalize_to_min(\%weight_rate, {min_default => 0.001}); print "\n#skinny rate: smaller weight is better:\n"; foreach my $key (sort {$weight_rate{$b} <=> $weight_rate{$a}} keys %weight_rate) { print "#$weight_rate{$key}\t$key\n"; } ##skinny rate: smaller weight is better: #1.000 Professor #0.585 Fray #0.351 Dr. Zoidberg #0.117 Bender #SUMMARY RATE my %summary_score = map { $_ => $weight_rate{$_} + $iq_rate{$_} } keys %iq_rate; $norm->normalize_to_max( \%summary_score ); print "\n#summary score:\n"; foreach my $key (sort {$summary_score{$b} <=> $summary_score{$a}} keys %summary_score) { print "#$summary_score{$key}\t$key\n"; } #summary score: #1.000 Professor #0.344 Fray #0.315 Bender #0.290 Dr. Zoidberg #Dr. Zoidberg - looser lobster! Quod erat demonstrandum
This module gives you the ability to normalize score result sets. Sometimes a larger score is better and sometimes a smaller score is better. In order to compare the results from different methods? You need a way to normalize them: that is, to get them all within the same range and direction.
The normalization functions will take a hash ref {key => score} or array ref [score 1, score 2, ...scaore 3] and return the same ref, but whith scores between 0 and 1. Each score is scaled according to how close it to the best result, wich will always have a score of 1.
Normalize->new(%opts) - constructor
round_to - default value 0.01. Rounding precision. For more info see Math::Round::Var
min_default - by default eq round_to value. Need for prevent delete on zero in normalize_to_min()
set object params
get object param
Each score is scaled according to how close it to the smaller result, wich will always have a score of 1. $score_set_data - hashref {key1 => score1, key2 => score2,..} or arrayref [score1, score2, ...] options:
%opts = ( min_default => 0.01#by default = round_to value. Need for prevent delete on zero in normalize_to_min() )
return same data structure (hashref or arrayref)
Each score is scaled according to how close it to the larger result, wich will always have a score of 1. $score_set_data - hashref {key1 => score1, key2 => score2,..} or arrayref [score1, score2, ...]
Math::Round::Var - Variations on rounding.
Idea for this module and normalization Algoritm from book "Programming Collective Intelligence: Building Smart Web 2.0 Applications By Toby Segaran)" http://books.google.com/books?id=fEsZ3Ey-Hq4C
Konstantin Kapitanov aka Green Kakadu, perlovik at gmail dot com
perlovik at gmail dot com
http://wiki-linki.ru
Please report any bugs or feature requests to bug-normalize at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Normalize. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-normalize at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Normalize
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Normalize
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Normalize
CPAN Ratings
http://cpanratings.perl.org/d/Normalize
Search CPAN
http://search.cpan.org/dist/Normalize/
Copyright 2009 Konstantin Kapitanov, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Normalize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Normalize
CPAN shell
perl -MCPAN -e shell install Normalize
For more information on module installation, please visit the detailed CPAN module installation guide.