gov.sandia.cognition.learning.function.cost
Class ParallelizedCostFunctionContainer

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.performance.AbstractSupervisedPerformanceEvaluator<InputType,TargetType,TargetType,Double>
          extended by gov.sandia.cognition.learning.function.cost.AbstractSupervisedCostFunction<Vector,Vector>
              extended by gov.sandia.cognition.learning.function.cost.ParallelizedCostFunctionContainer
All Implemented Interfaces:
ParallelAlgorithm, Evaluator<Evaluator<? super Vector,? extends Vector>,Double>, CostFunction<Evaluator<? super Vector,? extends Vector>,Collection<? extends InputOutputPair<? extends Vector,Vector>>>, DifferentiableCostFunction, SupervisedCostFunction<Vector,Vector>, PerformanceEvaluator<Evaluator<? super Vector,? extends Vector>,Collection<? extends InputOutputPair<Vector,Vector>>,Double>, SupervisedPerformanceEvaluator<Vector,Vector,Vector,Double>, CloneableSerializable, Summarizer<TargetEstimatePair<? extends Vector,? extends Vector>,Double>, Serializable, Cloneable

public class ParallelizedCostFunctionContainer
extends AbstractSupervisedCostFunction<Vector,Vector>
implements DifferentiableCostFunction, ParallelAlgorithm

A cost function that automatically splits a ParallelizableCostFunction across multiple cores/processors to speed up computation.

Since:
2.1
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
protected static class ParallelizedCostFunctionContainer.SubCostEvaluate
          Callable task for the evaluate() method.
protected static class ParallelizedCostFunctionContainer.SubCostGradient
          Callable task for the computeGradient() method
 
Constructor Summary
ParallelizedCostFunctionContainer()
          Default constructor for ParallelizedCostFunctionContainer.
ParallelizedCostFunctionContainer(ParallelizableCostFunction costFunction)
          Creates a new instance of ParallelizedCostFunctionContainer
ParallelizedCostFunctionContainer(ParallelizableCostFunction costFunction, ThreadPoolExecutor threadPool)
          Creates a new instance of ParallelizedCostFunctionContainer
 
Method Summary
 ParallelizedCostFunctionContainer clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 Vector computeParameterGradient(GradientDescendable function)
          Differentiates function with respect to its parameters.
protected  void createPartitions()
          Splits the data across the numComponents cost functions
protected  void createThreadPool()
          Creates the thread pool using the Foundry's global thread pool.
 Double evaluate(Evaluator<? super Vector,? extends Vector> evaluator)
          Computes the cost of the given target.
 Double evaluatePerformance(Collection<? extends TargetEstimatePair<? extends Vector,? extends Vector>> data)
          Evaluates the performance accuracy of the given estimates against the given targets.
 ParallelizableCostFunction getCostFunction()
          Getter for costFunction
 int getNumThreads()
          Gets the number of threads in the thread pool.
 ThreadPoolExecutor getThreadPool()
          Gets the thread pool for the algorithm to use.
 void setCostFunction(ParallelizableCostFunction costFunction)
          Setter for costFunction
 void setCostParameters(Collection<? extends InputOutputPair<? extends Vector,Vector>> costParameters)
          Sets the parameters of the cost function used to evaluate the cost of a target.
 void setThreadPool(ThreadPoolExecutor threadPool)
          Sets the thread pool for the algorithm to use.
 
Methods inherited from class gov.sandia.cognition.learning.function.cost.AbstractSupervisedCostFunction
getCostParameters, summarize
 
Methods inherited from class gov.sandia.cognition.learning.performance.AbstractSupervisedPerformanceEvaluator
evaluatePerformance
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.learning.function.cost.CostFunction
getCostParameters
 
Methods inherited from interface gov.sandia.cognition.util.Summarizer
summarize
 
Methods inherited from interface gov.sandia.cognition.learning.performance.PerformanceEvaluator
evaluatePerformance
 

Constructor Detail

ParallelizedCostFunctionContainer

public ParallelizedCostFunctionContainer()
Default constructor for ParallelizedCostFunctionContainer.


ParallelizedCostFunctionContainer

public ParallelizedCostFunctionContainer(ParallelizableCostFunction costFunction)
Creates a new instance of ParallelizedCostFunctionContainer

Parameters:
costFunction - Cost function to parallelize

ParallelizedCostFunctionContainer

public ParallelizedCostFunctionContainer(ParallelizableCostFunction costFunction,
                                         ThreadPoolExecutor threadPool)
Creates a new instance of ParallelizedCostFunctionContainer

Parameters:
threadPool - Thread pool used to parallelize the computation
costFunction - Cost function to parallelize
Method Detail

clone

public ParallelizedCostFunctionContainer clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CostFunction<Evaluator<? super Vector,? extends Vector>,Collection<? extends InputOutputPair<? extends Vector,Vector>>>
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractSupervisedCostFunction<Vector,Vector>
Returns:
A clone of this object.

getCostFunction

public ParallelizableCostFunction getCostFunction()
Getter for costFunction

Returns:
Cost function to parallelize

setCostFunction

public void setCostFunction(ParallelizableCostFunction costFunction)
Setter for costFunction

Parameters:
costFunction - Cost function to parallelize

createPartitions

protected void createPartitions()
Splits the data across the numComponents cost functions


setCostParameters

public void setCostParameters(Collection<? extends InputOutputPair<? extends Vector,Vector>> costParameters)
Description copied from interface: CostFunction
Sets the parameters of the cost function used to evaluate the cost of a target.

Specified by:
setCostParameters in interface CostFunction<Evaluator<? super Vector,? extends Vector>,Collection<? extends InputOutputPair<? extends Vector,Vector>>>
Overrides:
setCostParameters in class AbstractSupervisedCostFunction<Vector,Vector>
Parameters:
costParameters - The parameters of the cost function.

evaluate

public Double evaluate(Evaluator<? super Vector,? extends Vector> evaluator)
Description copied from interface: CostFunction
Computes the cost of the given target.

Specified by:
evaluate in interface Evaluator<Evaluator<? super Vector,? extends Vector>,Double>
Specified by:
evaluate in interface CostFunction<Evaluator<? super Vector,? extends Vector>,Collection<? extends InputOutputPair<? extends Vector,Vector>>>
Overrides:
evaluate in class AbstractSupervisedCostFunction<Vector,Vector>
Parameters:
evaluator - The object to evaluate.
Returns:
The cost of the given object.

evaluatePerformance

public Double evaluatePerformance(Collection<? extends TargetEstimatePair<? extends Vector,? extends Vector>> data)
Description copied from interface: SupervisedPerformanceEvaluator
Evaluates the performance accuracy of the given estimates against the given targets.

Specified by:
evaluatePerformance in interface SupervisedPerformanceEvaluator<Vector,Vector,Vector,Double>
Specified by:
evaluatePerformance in class AbstractSupervisedCostFunction<Vector,Vector>
Parameters:
data - The target-estimate pairs to use to evaluate performance.
Returns:
The performance evaluation result.

computeParameterGradient

public Vector computeParameterGradient(GradientDescendable function)
Description copied from interface: DifferentiableCostFunction
Differentiates function with respect to its parameters.

Specified by:
computeParameterGradient in interface DifferentiableCostFunction
Parameters:
function - The object to differentiate.
Returns:
Derivatives of the object with respect to the cost function.

getThreadPool

public ThreadPoolExecutor getThreadPool()
Description copied from interface: ParallelAlgorithm
Gets the thread pool for the algorithm to use.

Specified by:
getThreadPool in interface ParallelAlgorithm
Returns:
Thread pool used for parallelization.

setThreadPool

public void setThreadPool(ThreadPoolExecutor threadPool)
Description copied from interface: ParallelAlgorithm
Sets the thread pool for the algorithm to use.

Specified by:
setThreadPool in interface ParallelAlgorithm
Parameters:
threadPool - Thread pool used for parallelization.

getNumThreads

public int getNumThreads()
Description copied from interface: ParallelAlgorithm
Gets the number of threads in the thread pool.

Specified by:
getNumThreads in interface ParallelAlgorithm
Returns:
Number of threads in the thread pool

createThreadPool

protected void createThreadPool()
Creates the thread pool using the Foundry's global thread pool.