in reply to algorithm for 'best subsets'
As for code to implement this measure, it is simple to use HoHs:
Update: Note that this isn't a full correlation calculation, but implements the OPs desired numbers for a 2-way measure. As tall_man pointed out, I blew it :) Here is the corrected code:my %items = ( z => [ qw/one six/ ], 'y' => [ qw/two three five/ ], x => [ qw/one two five/ ], ); my %corr; foreach my $item (keys %items) { my $max = scalar @{$items{$item}} - 1; for my $first (0..$max) { for my $second ($first+1..$max) { $corr{ $items{$item}[$first] }{ $items{$item}[$second] }++; } } } for my $first (keys %corr) { for my $second (keys %{$corr{$first}}) { print "$first $second: $corr{$first}{$second}\n"; } }
foreach my $item (keys %items) { my @set = sort @{$items{$item}}; for my $first (0..$#set) { for my $second ($first+1..$#set) { $corr{ $set[$first] }{ $set[$second] }++; } } } for my $first (sort keys %corr) { for my $second (sort keys %{$corr{$first}}) { print "$first $second: $corr{$first}{$second}\n"; } }
-Mark
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: algorithm for 'best subsets'
by tall_man (Parson) on Mar 03, 2005 at 01:19 UTC |