gov.sandia.cognition.learning.algorithm.genetic.reproducer.MutationReproducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cognitive-foundry Show documentation
Show all versions of cognitive-foundry Show documentation
A single jar with all the Cognitive Foundry components.
/*
* File: MutationReproducer.java
* Authors: Jonathan McClain and Justin Basilico
* Company: Sandia National Laboratories
* Project: Cognitive Foundry
*
* Copyright May 3, 2006, Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000, there is a non-exclusive license for use of this work by
* or on behalf of the U.S. Government. Export of this program may require a
* license from the United States Government. See CopyrightHistory.txt for
* complete details.
*
*/
package gov.sandia.cognition.learning.algorithm.genetic.reproducer;
import gov.sandia.cognition.annotation.CodeReview;
import gov.sandia.cognition.annotation.CodeReviews;
import gov.sandia.cognition.learning.algorithm.annealing.Perturber;
import gov.sandia.cognition.learning.algorithm.genetic.EvaluatedGenome;
import gov.sandia.cognition.learning.algorithm.genetic.selector.Selector;
import java.util.ArrayList;
import java.util.Collection;
/**
* The MutationReproducer class implements a Reproducer that applies a
* {@code Perturber} to the supplied population to produce a new population.
*
* @param Type of genome used to represent a single element in the
* genetic population, such as a Vector, for example
* @author Jonathan McClain
* @author Justin Basilico
* @since 1.0
*/
@CodeReviews(
reviews={
@CodeReview(
reviewer="Kevin R. Dixon",
date="2008-07-23",
changesNeeded=false,
comments={
"Moved previous code review as CodeReview annotation",
"Looks fine."
}
)
,
@CodeReview(
reviewer="Justin Basilico",
date="2006-10-04",
changesNeeded=false,
comments={
"Minor changes made.",
"Looks good."
}
)
}
)
public class MutationReproducer
extends Object
implements Reproducer
{
/** The perturber to use for mutation. */
private Perturber perturber;
/** The selector to use to select the population. */
private Selector selector;
/**
* Creates a new instance of MutationReproducer
*
* @param perturber The Perturber to use for mutating.
* @param selector The Selector to use for selecting genomes to mutate.
*/
public MutationReproducer(
Perturber perturber,
Selector selector)
{
super();
this.setPerturber(perturber);
this.setSelector(selector);
}
/**
* Produces a new mutated population based on the supplied population.
*
* @param genomes The population to mutate.
* @return The new population.
*/
public Collection reproduce(
Collection> genomes)
{
Collection> selectedGenomes =
this.getSelector().select(genomes);
ArrayList newGenomes =
new ArrayList(selectedGenomes.size());
for(EvaluatedGenome genome : selectedGenomes)
{
newGenomes.add(this.getPerturber().perturb(genome.getGenome()));
}
return newGenomes;
}
/**
* Gets the perturber used for mutation.
*
* @return The perturber used for mutation.
*/
public Perturber getPerturber()
{
return this.perturber;
}
/**
* Gets the selector used to select the population.
*
* @return The selector.
*/
public Selector getSelector()
{
return this.selector;
}
/**
* Sets the perturber used for mutation.
*
* @param perturber The new perturber.
*/
public void setPerturber(Perturber perturber)
{
this.perturber = perturber;
}
/**
* Sets the selector used to select the population.
*
* @param selector The new selector.
*/
public void setSelector(Selector selector)
{
this.selector = selector;
}
}