FreeHEP API
Version current

hep.aida.ref.optimizer.minuit
Class MinuitCommands

java.lang.Object
  extended byhep.aida.ref.optimizer.minuit.MinuitCommands

public class MinuitCommands
extends Object

Minuit commands.

Author:
Tony Johnson, Victor Serbo, Max Turri
Source Code:
MinuitCommands.java

Field Summary
protected static int DETAILED_OUTPUT
           
protected static int MATRIX_DIAGONAL_APPROX
           
protected static int MATRIX_FULL_ACCURATE
           
protected static int MATRIX_FULL_FORCED_POS
           
protected static int MATRIX_NOT_CALCULATED
          The possible status of the covariance matrix
protected static int MAXIMAL_OUTPUT
           
protected static int MIGRAD_MIN
           
protected static int MINIMAL_OUTPUT
           
protected static int MINIMIZE_MIN
           
protected static int NO_OUTPUT
          The printout levels for the minimizer output are the following:
protected static int NORMAL_OUTPUT
           
protected static int SIMPLEX_MIN
          The different types of minimization.
 
Constructor Summary
protected MinuitCommands(MinuitOptimizer theOptimizer)
          Default constructor.
 
Method Summary
protected  double[][] calculateContour(String parName1, String parName2)
          Calculate the Error Matrix in the current configuration.
protected  double[][] calculateContour(String parName1, String parName2, int nPoints)
           
protected  double[][] calculateContour(String parName1, String parName2, int nPoints, double nSigmas)
           
static double[] evaluateDerivatives(double[] vars)
          Evaluate the function's derivatives.
static double evaluateFunction(double[] vars)
          Evaluate the function.
static void finalizeFunction()
          Finalize the function after the fit is over.
protected  void fixVariable(String varName)
           
protected  double[][] getCovarianceMatrix()
           
protected  double getErrorDef()
          Get the value of UP, the errorDefinition.
protected  int getNVariables()
          Get the number of (released) variables in the minimization.
protected  int getStatus()
          Get the status of the fit.
static void initializeFunction()
          Initialize the function.
protected static void jmncont(int parNum1, int parNum2, int nPoints, double[] xPoints, double[] yPoints, int[] nFound)
          Get the two dimensional contour for the current configuration.
protected static void jmnemat(double[] errorMatrix, int nDim)
          Get the covariance matrix.
protected static void jmnerrs(int parNum, double[] errors)
          Get the current parameter's errors.
protected static int jmnexcm(String command, double[] argList, int nArg)
          Execute a Minuit command, the command is executed on the current function.
protected static void jmninit(int inputUnit, int outputUnit, int saveUnit)
          Initialize minuit.
protected static int jmnparm(int parNum, String parName, double parValue, double stepSize, double minValue, double maxValue)
          Define a new fit parameter.
protected static int jmnpout(int parNum, String[] parName, double[] parVals)
          Get the current value of a parameter.
protected static void jmnseti(String title)
          Set the title of the minimization session.
protected static int jmnstat(double[] vals, int[] pars)
          Get the current status of minimization.
protected  void minos()
          Perform the Minos error analysis on the specified variables.
protected  void optimize(String method, int maxIterations, double tolerance)
          Minimize the function.
protected  void resetMinuit()
          Reset Minuit.
protected  void setErrorDef(int errDef)
          Set the Error Definition, the Minuit UP value.
protected  void setErrorDefinition(double errDef)
           
protected  void setFunction(hep.aida.IFunction function, MinuitOptimizer optimizer)
          Set the function to be minimized.
protected  void setPrecision(double precision)
          Informs Minuit on the machin precision.
 void setPrintLevel(int printLevel)
           
protected  void setStrategy(int strategy)
          Set the strategy to be used in calculating the first and second derivative and in certain optimization methods.
protected  void setUseFunctionGradient(boolean useFunctionGradient)
          Tell Minuit if the derivatives provided by the function are to be used.
protected  void updateFunction(MinuitOptimizer optimizer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MATRIX_NOT_CALCULATED

protected static final int MATRIX_NOT_CALCULATED
The possible status of the covariance matrix

See Also:
Constant Field Values

MATRIX_DIAGONAL_APPROX

protected static final int MATRIX_DIAGONAL_APPROX
See Also:
Constant Field Values

MATRIX_FULL_FORCED_POS

protected static final int MATRIX_FULL_FORCED_POS
See Also:
Constant Field Values

MATRIX_FULL_ACCURATE

protected static final int MATRIX_FULL_ACCURATE
See Also:
Constant Field Values

NO_OUTPUT

protected static final int NO_OUTPUT
The printout levels for the minimizer output are the following:

See Also:
Constant Field Values

MINIMAL_OUTPUT

protected static final int MINIMAL_OUTPUT
See Also:
Constant Field Values

NORMAL_OUTPUT

protected static final int NORMAL_OUTPUT
See Also:
Constant Field Values

DETAILED_OUTPUT

protected static final int DETAILED_OUTPUT
See Also:
Constant Field Values

MAXIMAL_OUTPUT

protected static final int MAXIMAL_OUTPUT
See Also:
Constant Field Values

SIMPLEX_MIN

protected static final int SIMPLEX_MIN
The different types of minimization.

See Also:
Constant Field Values

MIGRAD_MIN

protected static final int MIGRAD_MIN
See Also:
Constant Field Values

MINIMIZE_MIN

protected static final int MINIMIZE_MIN
See Also:
Constant Field Values
Constructor Detail

MinuitCommands

protected MinuitCommands(MinuitOptimizer theOptimizer)
Default constructor.

Method Detail

jmninit

protected static void jmninit(int inputUnit,
                              int outputUnit,
                              int saveUnit)
Initialize minuit.

Parameters:
inputUnit - Unit number for input to Minuit (default 5)
outputUnit - Unit number for output from Minuit (default 6)
saveUnit - Unit number to be used for SAVE command (default 7)

jmnseti

protected static void jmnseti(String title)
Set the title of the minimization session. The title maximum length is 50 characters.

Parameters:
title - The title.

jmnparm

protected static int jmnparm(int parNum,
                             String parName,
                             double parValue,
                             double stepSize,
                             double minValue,
                             double maxValue)
Define a new fit parameter.

Parameters:
parNum - The parameter number (+1) as referenced by the IFunction to be minimized.
parName - The parameter's name. (maximum 10 characters).
parValue - The parameter's starting value.
stepSize - Starting step size or approximate error.
minValue - The parameter's lower limit.
maxValue - The parameter's upper limit. If the upper and the lower limits are set to 0, the parameter is considered unbounded.
Returns:
Error code. 0 if no error, > 0 if request failed.

jmnexcm

protected static int jmnexcm(String command,
                             double[] argList,
                             int nArg)
Execute a Minuit command, the command is executed on the current function.

Parameters:
command - The Minuit command to be executed.
argList - Array containing the numeric arguments to the command.
nArg - The number of arguments specified.
Returns:
Error code. 0 if no error, > 0 otherwise.

jmnpout

protected static int jmnpout(int parNum,
                             String[] parName,
                             double[] parVals)
Get the current value of a parameter.

Parameters:
parNum - The parameter's number (+1) as referenced in the function to be minimized.
parName - The parameter's name (it is a one dimensional array);
parVals - The parameter's values. This array contains four entries: the current value of the parameter, the current error on the parameter, the parameter's lower and upper bound (both 0 if parameter is unbounded).
Returns:
Internal parameter's number (as used by the fit); 0 if parameter is a constant, a negative number if parameter is not defined.

jmnstat

protected static int jmnstat(double[] vals,
                             int[] pars)
Get the current status of minimization.

Parameters:
vals - The values of the minimization. This array contains the following three entries: the current best value of the function, the estimated vertical distance to the minimum, the value of UP defining the errors.
pars - The parameters information. This array contains the following two entries: the number of variables in the fit, the highest parameter number (as seen by the function to be minimized).
Returns:
The status of the fit telling at what stage the covariance matrix is: 0 not calculated, 1 diagonal approximation, 2 full matrix but forced positive-definite, 3 full accurate matrix.

jmnemat

protected static void jmnemat(double[] errorMatrix,
                              int nDim)
Get the covariance matrix.

Parameters:
errorMatrix - The error matrix. It is an array of length nDim*nDim
nDim - The dimension of the error matrix (at least the number of free variables).

jmnerrs

protected static void jmnerrs(int parNum,
                              double[] errors)
Get the current parameter's errors.

Parameters:
parNum - The parameter's number; if positive it is the number as referenced by the function to be minimized, if negative it is the negative of the parameter number as used within Minuit (the internal representation)
errors - The parameter's errors. This array has four entries: the positive MINOS error, the negative MINOS error, the parabolic error from the error matrix and the global correlation coerricient.

jmncont

protected static void jmncont(int parNum1,
                              int parNum2,
                              int nPoints,
                              double[] xPoints,
                              double[] yPoints,
                              int[] nFound)
Get the two dimensional contour for the current configuration.

Parameters:
parNum1 - The external number of the first parameter.
parNum2 - The external number of the second parameter.
nPoints - The number of points that are to be calculated on the contour (>4).
xPoints - The array of the x-coordinate of the found points.
yPoints - The array of the y-coordinate of the found points.
nFound - The number of points that have been found. This is a 1-dimensional array.

setPrintLevel

public void setPrintLevel(int printLevel)
                   throws IllegalArgumentException
Throws:
IllegalArgumentException

resetMinuit

protected void resetMinuit()
Reset Minuit.


evaluateFunction

public static double evaluateFunction(double[] vars)
Evaluate the function.

Parameters:
vars - The values of the parameters where the function has to be evaluated.
Returns:
The value of the function.

evaluateDerivatives

public static double[] evaluateDerivatives(double[] vars)
Evaluate the function's derivatives.

Parameters:
vars - The values of the parameters where the function's derivatives have to be evaluated.
Returns:
The array containing the function's derivatives.

initializeFunction

public static void initializeFunction()
Initialize the function.


finalizeFunction

public static void finalizeFunction()
Finalize the function after the fit is over.


setFunction

protected void setFunction(hep.aida.IFunction function,
                           MinuitOptimizer optimizer)
Set the function to be minimized. When setting a new function the minimizer is cleared of previous information.

Parameters:
function - The function to be minimized.

updateFunction

protected void updateFunction(MinuitOptimizer optimizer)

fixVariable

protected void fixVariable(String varName)

getStatus

protected int getStatus()
Get the status of the fit.

Returns:
The status of the fit based on the current status of the covariance matrix.

getNVariables

protected int getNVariables()
Get the number of (released) variables in the minimization.

Returns:
The number of variables in the minimization.

getErrorDef

protected double getErrorDef()
Get the value of UP, the errorDefinition.

Returns:
The number of UP.

setErrorDef

protected void setErrorDef(int errDef)
Set the Error Definition, the Minuit UP value. Minuit defines variable's errors as the change in the variable's value required to change the function value by the Error Definition (UP). For chiSquared fits UP=1, for negative log likelihood UP=0.5.

Parameters:
errDef - The new value for the Error Definition

setErrorDefinition

protected void setErrorDefinition(double errDef)

setUseFunctionGradient

protected void setUseFunctionGradient(boolean useFunctionGradient)
Tell Minuit if the derivatives provided by the function are to be used.


setStrategy

protected void setStrategy(int strategy)
Set the strategy to be used in calculating the first and second derivative and in certain optimization methods. It determines the reliability of the calculation as it changes the number of allowed function calls.


setPrecision

protected void setPrecision(double precision)
Informs Minuit on the machin precision.


optimize

protected void optimize(String method,
                        int maxIterations,
                        double tolerance)
Minimize the function.

Parameters:
method - The optimization method. It can be: - SIMPLEX performs a minimixation using the simplex method of Nedler and Mead. The minimization will stop after maxIter call have been performed or when the EDM is less than the tolerance (default is 0.1*UP) - MIGRAD The default minimization using the Migrad method. maxIter is the (optional) maximum amount of iterations; when this is reached the minimization will stopped even if it did not converge. The minimization converges when the EDM is less than 0.001*tolerance*UP. - MINIMIZE It starts by using the MIGRAD minimization; it this does not converge it switches to the SIMPLEX method. - IMPROVE If a previous minimization has converged and the function is in and optimal solution, it searches for additional global optimal points. The calculation will be stopped after maxIterations calls. - SEEK Causes a Monte Carlo minimization of the function, by choosing uniformely random values of the variables in an hypercube centered in the current variable values. The size of the hypercube is specified by the value of tolerance.
maxIterations - The maximum amount of allowed iterations.
tolerance - The tolerance for the minimization.
Returns:
true if the command was successfull; false otherwise. Check the status of the minimization to know what went wrong.

minos

protected void minos()
Perform the Minos error analysis on the specified variables. param maxIter The maximum number of iterations allowed. param vars The list of variables whose errors are to be recalculated. return true if the command was successfull; false otherwise. Check the status of the minimization to know what went wrong.


calculateContour

protected double[][] calculateContour(String parName1,
                                      String parName2)
Calculate the Error Matrix in the current configuration.

Returns:
true if the error matrix was calculated successfully. false otherwise.

calculateContour

protected double[][] calculateContour(String parName1,
                                      String parName2,
                                      int nPoints)

calculateContour

protected double[][] calculateContour(String parName1,
                                      String parName2,
                                      int nPoints,
                                      double nSigmas)

getCovarianceMatrix

protected double[][] getCovarianceMatrix()

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.