Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I started blogging sports recently and while doing so I've been running into algorithms and procedures in the area of sports analytics (what used to be known as sabermetrics). Sports analytics received a huge shot in the arm with the publication of Michael Lewis's book "Moneyball", and these days, according to Mark Cuban, perhaps 2/3 of all US basketball teams have an analytics team. That said, some of us like to do this on an amateur basis. One important algorithm is Doug Drinen's simple rankings system. I've implemented this one 5 different ways now. A particularly clean version can be written in PDL.
sub srs_full_matrix { my $mov = shift; my $played = shift; my $opt = shift || (); my $epsilon = 0.001; my $maxiter = 1000000; my $debug = 0; $epsilon = $opt->{epsilon} if ( $opt->{epsilon} ); $maxiter = $opt->{maxiter} if ( $opt->{maxiter} ); $debug = $opt->{debug} if ( $opt->{debug} ); my $srs = $mov->copy(); my $oldsrs = $srs->copy(); my $delta = 10.0; my $iter = 0; while ( $delta > $epsilon and $iter < $maxiter ) { my $wt = 1.0 / sumover $played; my $prod = $srs x $played; my $sos = $wt * $prod; $srs = $mov + $sos; $delta = max abs ( $srs - $oldsrs ); $oldsrs = $srs->copy(); $iter++; } print "iter = $iter\n" if $debug; print "epsilon = $epsilon\n" if $debug; printf "delta = %7.4f\n", $delta if $debug; my $offset = sum $srs; $srs -= ( $offset / $mov->nelem ); return $srs->slice(":,(0)"); }
I have this function wrapped in Module::Starter with a working test harness now, and getting something like this into CPAN is the reason I just asked for a PAUSE account. Just, I don't see this code as CPAN ready.
1. There needs to be a non-pdl version.
2. The non-PDL version needs to accept very simple input and give a simple answer; input as an array of games, output as a hash of team named mapped to SRS values.
3. error checking on input.
4. helper functions? yes or no? Is something like this okay packaged with the PDL version?
sub load_srs_data { my $games = shift; my %team; for ( @$games ) { my ( $visitor, $visit_score, $home_team, $home_score ) = split + "\,", $_; my $diff = $home_score - $visit_score; $team{$visitor}{games_played}++; $team{$home_team}{games_played}++; $team{$visitor}{points} -= $diff; $team{$home_team}{points} += $diff; push @{$team{$visitor}{played}}, $home_team; push @{$team{$home_team}{played}}, $visitor; } my $total_team = scalar keys %team; my $played = zeroes $total_team, $total_team; my $mov = zeroes $total_team; my %team_map; my $ii = 0; for ( sort keys %team ) { my $team_diff = $team{$_}{points} / $team{$_}{games_played}; $team_map{$_} = $ii; $mov->set( $ii, $team_diff ); $ii++; } for ( keys %team ) { my $i = $team_map{$_}; for my $opp (@{$team{$_}{played}}) { my $j = $team_map{$opp}; my $a = $played->at ( $i, $j ); $a++; $played->set( $i, $j, $a ); } } return \%team, \%team_map, $mov, $played; }
What I'm trying to do is some "design on paper" before I upload..
and yes..
5. Name space. I was using Sports::Analytics::SRS but a simple ranking function isn't the "System". SimpleRanking spelled out with Analytics or SportsAnalytics as a predecessor seems more appropriate.
Sports isn't an initial name anywhere in CPAN that I can see.

Algorithm::SportsAnalytics::SimpleRanking, perhaps, with Algorithm::SportsAnalytics::SimpleRanking::PDL for a PDL implementation?

In reply to From test harness to CPAN by dwm042

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [Discipulus]: good morning folks!

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (6)
    As of 2017-09-25 06:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      During the recent solar eclipse, I:









      Results (276 votes). Check out past polls.

      Notices?