public abstract class AbstractMultiThreadedOptimizableFunction extends AbstractOptimizableFunction implements MultiThreadedFunction
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, getSequenceWeights
reset
findOneDimensionalMin
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDimensionOfScope
protected de.jstacs.classifiers.differentiableSequenceScoreBased.AbstractMultiThreadedOptimizableFunction.Worker[] worker
AbstractMultiThreadedOptimizableFunction
protected 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 DataSet
s containing the data that is needed to evaluate the functionweights
- the weights for each Sequence
in each DataSet
of data
norm
- 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 DataSet
s 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
OptimizableFunction
setDataAndWeights
in class AbstractOptimizableFunction
data
- 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 double[] evaluateGradientOfFunction(double[] x) throws DimensionException, EvaluationException
DifferentiableFunction
x
, i.e.,
evaluateGradientOfFunction
in class DifferentiableFunction
x
- 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 double evaluateFunction(double[] x) throws DimensionException, EvaluationException
Function
x
.evaluateFunction
in interface Function
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
OptimizableFunction
setParams
in class OptimizableFunction
params
- 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
index
index
- the index of the threadDimensionException
- if the parameters could not be setparams
public final void stopThreads()
stopThreads
in interface MultiThreadedFunction
public final int getNumberOfThreads()
getNumberOfThreads
in interface MultiThreadedFunction