org.apache.mahout.ep
Class EvolutionaryProcess<T extends Payload<U>,U>
java.lang.Object
org.apache.mahout.ep.EvolutionaryProcess<T,U>
- Type Parameters:
T
- The payload class.
- All Implemented Interfaces:
- Closeable, org.apache.hadoop.io.Writable
public class EvolutionaryProcess<T extends Payload<U>,U>
- extends Object
- implements org.apache.hadoop.io.Writable, Closeable
Allows evolutionary optimization where the state function can't be easily
packaged for the optimizer to execute. A good example of this is with
on-line learning where optimizing the learning parameters is desirable.
We would like to pass training examples to the learning algorithms, but
we definitely want to do the training in multiple threads and then after
several training steps, we want to do a selection and mutation step.
In such a case, it is highly desirable to leave most of the control flow
in the hands of our caller. As such, this class provides three functions,
- Storage of the evolutionary state. The state variables have payloads
which can be anything that implements Payload.
- Threaded execution of a single operation on each of the members of the
population being evolved. In the on-line learning example, this is used for
training all of the classifiers in the population.
- Propagating mutations of the most successful members of the population.
This propagation involves copying the state and the payload and then updating
the payload after mutation of the evolutionary state.
The State class that we use for storing the state of each member of the
population also provides parameter mapping. Check out Mapping and State
for more info.
- See Also:
Mapping
,
Payload
,
State
Constructor Summary |
EvolutionaryProcess()
|
EvolutionaryProcess(int threadCount,
int populationSize,
State<T,U> seed)
Creates an evolutionary optimization framework with specified threadiness,
population size and initial state. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
EvolutionaryProcess
public EvolutionaryProcess()
EvolutionaryProcess
public EvolutionaryProcess(int threadCount,
int populationSize,
State<T,U> seed)
- Creates an evolutionary optimization framework with specified threadiness,
population size and initial state.
- Parameters:
threadCount
- How many threads to use in parallelDopopulationSize
- How large a population to useseed
- An initial population member
add
public void add(State<T,U> value)
mutatePopulation
public void mutatePopulation(int survivors)
- Nuke all but a few of the current population and then repopulate with
variants of the survivors.
- Parameters:
survivors
- How many survivors we want to keep.
parallelDo
public State<T,U> parallelDo(EvolutionaryProcess.Function<Payload<U>> fn)
throws InterruptedException,
ExecutionException
- Execute an operation on all of the members of the population with many threads. The
return value is taken as the current fitness of the corresponding member.
- Parameters:
fn
- What to do on each member. Gets payload and the mapped parameters as args.
- Returns:
- The member of the population with the best fitness.
- Throws:
InterruptedException
- Shouldn't happen.
ExecutionException
- If fn throws an exception, that exception will be collected
and rethrown nested in an ExecutionException.
setThreadCount
public void setThreadCount(int threadCount)
getThreadCount
public int getThreadCount()
getPopulationSize
public int getPopulationSize()
getPopulation
public List<State<T,U>> getPopulation()
close
public void close()
- Specified by:
close
in interface Closeable
write
public void write(DataOutput out)
throws IOException
- Specified by:
write
in interface org.apache.hadoop.io.Writable
- Throws:
IOException
readFields
public void readFields(DataInput input)
throws IOException
- Specified by:
readFields
in interface org.apache.hadoop.io.Writable
- Throws:
IOException
Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.