Minuit(3pm)
π Minuit(3pm) π
okay so hi bestie π«Ά this is the Minuit(3pm) page from the User Contributed Perl Documentation, and it's giving extremely niche, extremely powerful energy. buckle up.
β¨ NAME β¨
PDL::Minuit β a PDL interface to the Minuit library. that's it, that's the whole name. iconic. π
πΈ DESCRIPTION πΈ
This package implements an interface to the Minuit minimization routines β which are part of the CERN Library. no cap, actual CERN. we're doing physics-grade minimization over here. π§
π¦ SYNOPSIS π¦
so a basic fit with Minuit calls three functions in this package, in this order:
- First, a basic initialization happens with
mn_init(). - Then the parameters get defined via
mn_def_pars(), which is the one that lets you set upper and lower bounds. π - Then
mn_excm()is your girl for issuing a whole bunch of Minuit commands β including the simplex and migrad minimization algorithms (go read the Minuit manual for the full deets, bestie).
Also fr fr: go look at the test fileminuit.tin the test (t/) directory for a basic example. it's right there, it's free, it's helpful. π
π FUNCTIONS π
π«Ά mninit π«Ά
Signature: (longlong a();longlong b(); longlong c())
info not available. like, genuinely, the page says info not available. we're not gonna make stuff up. π
mninit does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mn_abre π«Ά
Signature: (longlong l(); char* nombre; char* mode)
info not available. yeah yeah, same vibe. π
mn_abre does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mn_cierra π«Ά
Signature: (longlong l())
info not available. (i know. it's a whole thing.)
mn_cierra does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mnparm π«Ά
Signature: (longlong a(); double b(); double c(); double d(); double e(); longlong [o] ia(); char* str)
info not available. π
mnparm does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mnexcm π«Ά
Signature: (double a(n); longlong ia(); longlong [o] ib(); char* str; SV* function; IV numelem)
info not available. slay but unlabeled. β¨
mnexcm does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mnpout π«Ά
Signature: (longlong ia(); double [o] a(); double [o] b(); double [o] c(); double [o] d();longlong [o] ib(); SV* str)
info not available. (the mystery is the aesthetic at this point.) π
mnpout does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mnstat π«Ά
Signature: (double [o] a(); double [o] b(); double [o] c(); longlong [o] ia(); longlong [o] ib(); longlong [o] ic())
info not available. π₯
mnstat does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mnemat π«Ά
Signature: (double [o] mat(n,n))
info not available. matrix girlie, but undocumented. π¦
mnemat does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mnerrs π«Ά
Signature: (longlong ia(); double [o] a(); double [o] b(); double [o] c(); double [o] d())
info not available. π
mnerrs does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π«Ά mncont π«Ά
Signature: (longlong ia(); longlong ib(); longlong ic(); double [o] a(n); double [o] b(n); longlong [o] id(); SV* function; IV numelem)
info not available. the last of the mystery squad. π
mncont does not process bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mn_init() π
okay THIS one has actual info, we love to see it. π
The function mn_init() does the basic initialization of the fit. The first argument has to be a reference to the function to be minimized. And that function you're minimizing has to receive five arguments:
$nparβ the number of parameters currently variable.$gradβ the gradient of the function (which is not necessarily used, see the Minuit documentation).$fvalβ the current value of the function.$xvalβ an ndarray with the values of the parameters.$iflagβ an integer flag, which indicates what the function is supposed to calculate.
and the function has to return the values ($fval,$grad) β the function value and the function gradient. that's the deal. π€
There are three optional arguments to mn_init():
- By default, the output of Minuit comes through
STDOUTβ unless a filename$logfileis given in the Log option.
β οΈ warning bestie: this will mercilessly erase $logfile if it already exists. not "append", not "ask nicely". erase. consider yourself warned. π
- A title can be given to the fit by the Title option. the default is
'Minuit Fit'. - If the output is written to a logfile, this is assigned Fortran unit number
88. If for whatever reason you want to have control over the unit number that Fortran associates to the logfile, you can pass the number through the Unit option.
Usage:
mn_init($function_ref,{Log=>$logfile,Title=>$title,Unit=>$unit})
Example:
mn_init(\&my_function);
#same as above but outputting to a file 'log.out'.
#title for fit is 'My fit'
mn_init(\&my_function,
{Log => 'log.out', Title => 'My fit'});
sub my_function{
# the five variables input to the function to be minimized
# xval is an ndarray containing the current values of the parameters
my ($npar,$grad,$fval,$xval,$iflag) = @_;
# Here is code computing the value of the function
# and potentially also its gradient
# ......
# return the two variables. If no gradient is being computed
# just return the $grad that came as input
return ($fval, $grad);
}
πΈ mn_def_pars() πΈ
The function mn_def_pars() defines the initial values of the parameters of the function to be minimized, plus the value of the initial steps around those values that the minimizer will use for the first variations of the parameters while it searches for the minimum. β¨
There are several optional arguments, and they're all kinda cute:
- One lets you assign names to these parameters β otherwise they get named
(Par_0, Par_1,....,Par_n)by default. - Two more arguments can give lower and upper bounds for the parameters, via two ndarrays. If the lower and upper bound for a given parameter are both equal to 0, then the parameter is unbound. By default these lower and upper bound ndarrays are set to
zeroes(n), wherenis the number of parameters β i.e. the parameters are unbound by default.
So the function needs two input variables: an ndarray giving the initial values of the parameters, and another ndarray giving the initial steps. An optional reference to a perl array with the variable names can be passed, as well as ndarrays with upper and lower bounds for the parameters (see example below, bestie). π
It returns an integer variable which is 0 upon success. π
Usage:
$iflag = mn_def_pars($pars, $steps,{Names => \@names,
Lower_bounds => $lbounds,
Upper_bounds => $ubounds})
Example:
#initial parameter values
my $pars = pdl(2.5,3.0);
#steps
my $steps = pdl(0.3,0.5);
#parameter names
my @names = ('intercept','slope');
#use mn_def_pars with default parameter names (Par_0,Par_1,...)
my $iflag = mn_def_pars($pars,$steps);
#use of mn_def_pars explicitly specify parameter names
$iflag = mn_def_pars($pars,$steps,{Names => \@names});
# specify lower and upper bounds for the parameters.
# The example below leaves parameter 1 (intercept) unconstrained
# and constrains parameter 2 (slope) to be between 0 and 100
my $lbounds = pdl(0, 0);
my $ubounds = pdl(0, 100);
$iflag = mn_def_pars($pars,$steps,{Names => \@names,
Lower_bounds => $lbounds,
Upper_bounds => $ubounds}});
#same as above because $lbounds is by default zeroes(n)
$iflag = mn_def_pars($pars,$steps,{Names => \@names,
Upper_bounds => $ubounds}});
π mn_excm() π
The function mn_excm() executes a Minuit command passed as a string. First argument is the command string, and an optional second argument is an ndarray with arguments to the command. The available commands are listed in Chapter 4 of the Minuit manual (see url below). π
It returns an integer variable which is 0 upon success. π
Usage:
$iflag = mn_excm($command_string, {$arglis})
Example:
#start a simplex minimization
my $iflag = mn_excm('simplex');
#same as above but specify the maximum allowed numbers of
#function calls in the minimization
my $arglist = pdl(1000);
$iflag = mn_excm('simplex',$arglist);
#start a migrad minimization
$iflag = mn_excm('migrad')
#set Minuit strategy in order to get the most reliable results
$arglist = pdl(2)
$iflag = mn_excm('set strategy',$arglist);
# each command can be specified by a minimal string that uniquely
# identifies it (see Chapter 4 of Minuit manual). The comannd above
# is equivalent to:
$iflag = mn_excm('set stra',$arglis);
iykyk, you can just type the shortest string that uniquely identifies the command. π€
π mn_pout() π
The function mn_pout() gets the current value of a parameter. You feed it the parameter number, and it returns an array with:
- the parameter value,
- the current estimate of its uncertainty (
0if parameter is constant), - lower bound on the parameter, if any (otherwise
0), - upper bound on the parameter, if any (otherwise
0), - integer flag β which is equal to the parameter number if variable,
zeroif the parameter is constant, and negative if parameter is not defined, - and the parameter name.
Usage:
($val,$err,$bnd1,$bnd2,$ivarbl,$par_name) = mn_pout($par_number);
β mn_stat() β
The function mn_stat() gets the current status of the minimization. It returns an array with:
- the best function value found so far,
- the estimated vertical distance remaining to minimum,
- the value of
UPdefining parameter uncertainties (default is1), - the number of currently variable parameters,
- the highest parameter defined,
- and an integer flag indicating how good the covariance matrix is:
0= not calculated at all1= diagonal approximation, not accurate2= full matrix, but forced positive definite3= full accurate matrix
Usage:
($fmin,$fedm,$errdef,$npari,$nparx,$istat) = mn_stat();
π mn_emat() π
The function mn_emat returns the covariance matrix as an ndarray. short. sweet. matrix. π
Usage:
$emat = mn_emat();
π§ mn_err() π§
The function mn_err() returns the current existing values for the error in the fitted parameters. It returns an array with:
- the positive error,
- the negative error,
- the "parabolic" parameter error from the error matrix,
- and the global correlation coefficient β which is a number between
0and1that gives the correlation between the requested parameter and that linear combination of all other parameters which is most strongly correlated with it.
heads up bestie: unless the command'MINOS'has been issued via the functionmn_excm(), the first three values will be equal. π
Usage:
($eplus,$eminus,$eparab,$globcc) = mn_err($par_number);
π¦ mn_contour() π¦
okay bestie, mn_contour() is literally the contour-finding queen π she finds contours of the function being minimized with respect to two chosen parameters. The contour level is given by F_min + UP, where F_min is the minimum of the function and UP is the ERRordef specified by the user, or 1.0 by default (see the Minuit manual, iykyk π). And the contour this function calculates is dynamic, in the sense that it represents the minimum of the function being minimized with respect to all the other NPAR-2 parameters (if any). no cap.
The function takes as input the parameter numbers with respect to which the contour is to be determined (two of them, bestie) and the number of points $npt required on the contour (>4). It returns an array with ndarrays $xpt,$ypt containing the coordinates of the contour and a variable $nfound indicating the number of points actually found in the contour. If all goes well $nfound will be equal to $npt, but it can be negative if the input arguments are not valid, zero if less than four points have been found, or <$npt if the program could not find $npt points. π
Usage:
($xpt,$ypt,$nfound) = mn_contour($par_number_1,$par_number_2,$npt)
β¨ SEE ALSO β¨
PDL is right there in the see-also squad π
The Minuit documentation is online at
http://wwwasdoc.web.cern.ch/wwwasdoc/minuit/minmain.html
π AUTHOR π
okay so legal tea β: This file copyright (C) 2007 Andres Jordan <ajordan@eso.org>. All rights reserved. There is no warranty. You are allowed to redistribute this software/documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file. periodt. π«Ά
mwah π this page came from perl v5.38.2, dated 2024-04-10, and it's the Minuit(3pm) manpage. slay. β¨
π¦ where this page comes from
- ubuntu noble: pdl 1:2.085-1ubuntu1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms