I am working on calculating the probability value of two elements in a group with the same value (similar situation with the birthday problem, http://en.wikipedia.org/wiki/Birthday_problem ).
For this, I have 24 sets of three values. Each element in the group will have one value out of 3 from each of 24 sets.
The calculation I need to do is get the sum of the square for all possible iterations of these values.
Such an iteration is obviously very intense, given the necessarily iterative nature.
When entering from SE, I already have:
use List::Util qw(reduce);
use Set::CrossProduct;
my @array = (
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33],
[0.33, 0.33, 0.33]
);
$val = 0;
my $iterator = Set::CrossProduct->new(\@array);
while (my $tuple = $iterator->get) {
$freq = reduce { $a * $b } @$tuple;
$val += ($freq*$freq);
}
$toprint=sprintf("%.50e", $val);
print $toprint;
13 , , , 45 , 24 . - , . , , ...
Perl, , .
.
EDIT: R, , , , .