|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.jstacs.algorithms.optimization.DifferentiableFunction
de.jstacs.classifier.scoringFunctionBased.OptimizableFunction
de.jstacs.classifier.scoringFunctionBased.AbstractOptimizableFunction
de.jstacs.classifier.scoringFunctionBased.AbstractMultiThreadedOptimizableFunction
public abstract class AbstractMultiThreadedOptimizableFunction
This class enables the user to exploit all CPUs of an computer by using threads.
Each thread computes the function for a part of the data.
The number of compute threads can be determined in the constructor.
The main goal is on the one hand to hide the complete infrastructure that is used for the multi-threading from
the programmer and on the other hand to provide an simple interface in form of few abstract methods.
It is very important for this class that the clone() method (of the used items) works correctly, since each thread works on its own clones.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class de.jstacs.classifier.scoringFunctionBased.OptimizableFunction |
|---|
OptimizableFunction.KindOfParameter |
| Field Summary | |
|---|---|
protected double[] |
params
This is a pointer for the current parameters. |
| Fields inherited from class de.jstacs.classifier.scoringFunctionBased.AbstractOptimizableFunction |
|---|
cl, clazz, data, freeParams, logClazz, norm, sum, weights |
| Constructor Summary | |
|---|---|
AbstractMultiThreadedOptimizableFunction(int threads,
Sample[] data,
double[][] weights,
boolean norm,
boolean freeParams)
The constructor for an multi-threaded instance. |
|
| Method Summary | |
|---|---|
double |
evaluateFunction(double[] x)
Evaluates the function at a certain vector (in mathematical sense) x. |
protected abstract void |
evaluateFunction(int index,
int startClass,
int startSeq,
int endClass,
int endSeq)
This method evaluates the function for a part of the data. |
double[] |
evaluateGradientOfFunction(double[] x)
Evaluates the gradient of a function at a certain vector (in mathematical sense) x, i.e.,
. |
protected abstract void |
evaluateGradientOfFunction(int index,
int startClass,
int startSeq,
int endClass,
int endSeq)
This method evaluates the gradient of the function for a part of the data. |
static int |
getNumberOfAvailableProcessors()
This method returns the number of available processors. |
int |
getNumberOfThreads()
Returns the number of used threads for evaluating the function and for determining the gradient of the function. |
protected abstract double |
joinFunction()
This method joins the partial results that have been computed using evaluateFunction(int, int, int, int, int). |
protected abstract double[] |
joinGradients()
This method joins the gradients of each part that have been computed using evaluateGradientOfFunction(int, int, int, int, int). |
void |
setDataAndWeights(Sample[] data,
double[][] weights)
This method sets the data set and the sequence weights to be used. |
void |
setParams(double[] params)
Sets the current values as parameters. |
protected abstract void |
setParams(int index)
This method sets the parameters for thread index |
protected abstract void |
setThreadIndependentParameters()
This method allows to set thread independent parameters. |
void |
stopThreads()
This method can and should be used to stop all threads if they are not needed any longer. |
| Methods inherited from class de.jstacs.classifier.scoringFunctionBased.AbstractOptimizableFunction |
|---|
getData, getParameters, getParameters, getSequenceWeights |
| Methods inherited from class de.jstacs.classifier.scoringFunctionBased.OptimizableFunction |
|---|
reset |
| Methods inherited from class de.jstacs.algorithms.optimization.DifferentiableFunction |
|---|
findOneDimensionalMin |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface de.jstacs.algorithms.optimization.Function |
|---|
getDimensionOfScope |
| Field Detail |
|---|
protected double[] params
| Constructor Detail |
|---|
public AbstractMultiThreadedOptimizableFunction(int threads,
Sample[] data,
double[][] weights,
boolean norm,
boolean freeParams)
throws IllegalArgumentException
threads - the number of threads used for evaluating the function and determining the gradient of the functiondata - the array of Samples containing the data that is needed to evaluate the functionweights - the weights for each Sequence in each Sample of datanorm - the switch for using the normalization (division by the number
of sequences)freeParams - the switch for using only the free parameters
IllegalArgumentException - if the number of threads is not positive, the Samples contain too less Sequence for the number of threads, the number of classes or the dimension of the weights is not correct| Method Detail |
|---|
public static final int getNumberOfAvailableProcessors()
public void setDataAndWeights(Sample[] data,
double[][] weights)
throws IllegalArgumentException
OptimizableFunction
setDataAndWeights in class AbstractOptimizableFunctiondata - the data setsweights - the sequence weights for each sequence in each data set
IllegalArgumentException - if the data or the weights can not be used
public final double[] evaluateGradientOfFunction(double[] x)
throws DimensionException,
EvaluationException
DifferentiableFunctionx, i.e.,
.
evaluateGradientOfFunction in class DifferentiableFunctionx - the current vector
Function.getDimensionOfScope()
DimensionException - if dim(x) != n, with
EvaluationException - if there was something wrong during the evaluation of the
gradientFunction.getDimensionOfScope()
protected abstract void evaluateGradientOfFunction(int index,
int startClass,
int startSeq,
int endClass,
int endSeq)
index - the index of the partstartClass - the index of the start classstartSeq - the index of the start sequenceendClass - the index of the end class (inclusive)endSeq - the index of the end sequence (exclusive)
protected abstract double[] joinGradients()
throws EvaluationException
evaluateGradientOfFunction(int, int, int, int, int).
EvaluationException - if the gradient could not be evaluated properly
public final double evaluateFunction(double[] x)
throws DimensionException,
EvaluationException
Functionx.
x - the current vector
DimensionException - if dim(x) != n, with f: R^n -> R
EvaluationException - if there was something wrong during the evaluation of the
function
protected abstract void evaluateFunction(int index,
int startClass,
int startSeq,
int endClass,
int endSeq)
throws EvaluationException
index - the index of the partstartClass - the index of the start classstartSeq - the index of the start sequenceendClass - the index of the end class (inclusive)endSeq - the index of the end sequence (exclusive)
EvaluationException - if the gradient could not be evaluated properly
protected abstract double joinFunction()
throws EvaluationException,
DimensionException
evaluateFunction(int, int, int, int, int).
EvaluationException - if the gradient could not be evaluated properly
DimensionException - if the parameters could not be set
public final void setParams(double[] params)
throws DimensionException
OptimizableFunction
setParams in class OptimizableFunctionparams - the current values
DimensionException - if the dimension of the current values does not match with
the dimension of the internal parameters
protected abstract void setThreadIndependentParameters()
throws DimensionException
DimensionException - if the dimension of the parameters is wrongsetParams(double[])
protected abstract void setParams(int index)
throws DimensionException
index
index - the index of the thread
DimensionException - if the parameters could not be setparamspublic final void stopThreads()
public final int getNumberOfThreads()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||