|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.algorithms.optimization.DifferentiableFunction
de.jstacs.classifiers.differentiableSequenceScoreBased.OptimizableFunction
de.jstacs.classifiers.differentiableSequenceScoreBased.AbstractOptimizableFunction
de.jstacs.classifiers.differentiableSequenceScoreBased.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.classifiers.differentiableSequenceScoreBased.OptimizableFunction |
---|
OptimizableFunction.KindOfParameter |
Field Summary | |
---|---|
protected double[] |
params
This is a pointer for the current parameters. |
Fields inherited from class de.jstacs.classifiers.differentiableSequenceScoreBased.AbstractOptimizableFunction |
---|
cl, clazz, data, freeParams, logClazz, norm, sum, weights |
Constructor Summary | |
---|---|
AbstractMultiThreadedOptimizableFunction(int threads,
DataSet[] 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(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. |
Methods inherited from class de.jstacs.classifiers.differentiableSequenceScoreBased.AbstractOptimizableFunction |
---|
getData, getParameters, getParameters, getSequenceWeights |
Methods inherited from class de.jstacs.classifiers.differentiableSequenceScoreBased.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, 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 parameters
IllegalArgumentException
- 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 correctMethod Detail |
---|
public 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 set
IllegalArgumentException
- if the data or the weights can not be usedpublic final double[] evaluateGradientOfFunction(double[] x) throws DimensionException, EvaluationException
DifferentiableFunction
x
, i.e.,
evaluateGradientOfFunction
in class DifferentiableFunction
x
- 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 properlypublic final double evaluateFunction(double[] x) throws DimensionException, EvaluationException
Function
x
.
x
- the current vector
DimensionException
- 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 properly
DimensionException
- if the parameters could not be setpublic final void setParams(double[] params) throws DimensionException
OptimizableFunction
setParams
in class OptimizableFunction
params
- the current values
DimensionException
- 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 thread
DimensionException
- if the parameters could not be setparams
public final void stopThreads()
public final int getNumberOfThreads()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |