Skip to content

Instantly share code, notes, and snippets.

@JJ
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJ/9788502 to your computer and use it in GitHub Desktop.
Save JJ/9788502 to your computer and use it in GitHub Desktop.
Applying Wilcoxon-comparison based partial order to an evolutionary algorithm
for my $p ( @pop ) {
push(@{$p->{'_fitness_memory'}}, $noisy->apply( $p ));
$p->Fitness($comparisons);
}
for my $i (1..$comparisons) {
my @copy_of_population = @pop;
while( @copy_of_population ) {
my $first = splice( @copy_of_population, rand( @copy_of_population ), 1 );
my $second = splice( @copy_of_population, rand( @copy_of_population ), 1 );
my $aov = Statistics::ANOVA->new();
$aov->load_data( { 1 => $first->{'_fitness_memory'}, 2 => $second->{'_fitness_memory'} });
my $test_value = $aov->compare(independent => 1, parametric => 0, flag => 1, alpha => .05, dump => 0); # Wilcoxon (between-groups) sum-of-ranks (Dwass Procedure)
if ( $test_value->{'1,2'}{'p_value'} < 0.05 ) {
if ( $test_value->{'1,2'}{'z_value'} < 0 ) {
$first->Fitness( $first->Fitness( ) + 1);
$second->Fitness( $second->Fitness( ) - 1);
} else {
$first->Fitness( $first->Fitness( ) - 1);
$second->Fitness( $second->Fitness( ) + 1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment