public abstract class AbstractMultiThreadedOptimizableFunction extends AbstractOptimizableFunction
OptimizableFunction.KindOfParameter| Modifier and Type | Field and Description |
|---|---|
protected double[] |
params
This is a pointer for the current parameters.
|
protected de.jstacs.classifiers.differentiableSequenceScoreBased.AbstractMultiThreadedOptimizableFunction.Worker[] |
worker
The worker threads for computing value and gradient of this
AbstractMultiThreadedOptimizableFunction |
cl, clazz, data, freeParams, logClazz, norm, sum, weights| Constructor and Description |
|---|
AbstractMultiThreadedOptimizableFunction(int threads,
DataSet[] data,
double[][] weights,
boolean norm,
boolean freeParams)
The constructor for an multi-threaded instance.
|
| Modifier and Type | Method and Description |
|---|---|
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). |
protected void |
prepareThreads()
Assigns parts of the data to the threads
|
void |
setDataAndWeights(DataSet[] 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.
|
getData, getParameters, getParameters, getSequenceWeightsresetfindOneDimensionalMinclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetDimensionOfScopeprotected de.jstacs.classifiers.differentiableSequenceScoreBased.AbstractMultiThreadedOptimizableFunction.Worker[] worker
AbstractMultiThreadedOptimizableFunctionprotected double[] params
public AbstractMultiThreadedOptimizableFunction(int threads,
DataSet[] 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 DataSets containing the data that is needed to evaluate the functionweights - the weights for each Sequence in each DataSet of datanorm - the switch for using the normalization (division by the number
of sequences)freeParams - the switch for using only the free parametersIllegalArgumentException - if the number of threads is not positive, the DataSets contain too less Sequence for the number of threads, the number of classes or the dimension of the weights is not correctpublic static final int getNumberOfAvailableProcessors()
public void setDataAndWeights(DataSet[] data, double[][] weights) throws IllegalArgumentException
OptimizableFunctionsetDataAndWeights in class AbstractOptimizableFunctiondata - the data setsweights - the sequence weights for each sequence in each data setIllegalArgumentException - if the data or the weights can not be usedprotected void prepareThreads()
public final double[] evaluateGradientOfFunction(double[] x)
throws DimensionException,
EvaluationException
DifferentiableFunctionx, i.e.,
.evaluateGradientOfFunction in class DifferentiableFunctionx - the current vectorFunction.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 properlypublic final double evaluateFunction(double[] x)
throws DimensionException,
EvaluationException
Functionx.x - the current vectorDimensionException - if dim(x) != n, with 
EvaluationException - if there was something wrong during the evaluation of the
functionprotected 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 properlyprotected abstract double joinFunction()
throws EvaluationException,
DimensionException
evaluateFunction(int, int, int, int, int).EvaluationException - if the gradient could not be evaluated properlyDimensionException - if the parameters could not be setpublic final void setParams(double[] params)
throws DimensionException
OptimizableFunctionsetParams in class OptimizableFunctionparams - the current valuesDimensionException - if the dimension of the current values does not match with
the dimension of the internal parametersprotected abstract void setThreadIndependentParameters()
throws DimensionException
DimensionException - if the dimension of the parameters is wrongsetParams(double[])protected abstract void setParams(int index)
throws DimensionException
indexindex - the index of the threadDimensionException - if the parameters could not be setparamspublic final void stopThreads()
public final int getNumberOfThreads()