/usr/lib/perl5/PDL/Minuit.pm is in pdl 1:2.4.7+dfsg-2ubuntu5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | #
# GENERATED WITH PDL::PP! Don't modify!
#
package PDL::Minuit;
@EXPORT_OK = qw( mn_init mn_def_pars mn_excm mn_pout mn_stat mn_err mn_contour mn_emat PDL::PP mninit PDL::PP mn_abre PDL::PP mn_cierra PDL::PP mnparm PDL::PP mnexcm PDL::PP mnpout PDL::PP mnstat PDL::PP mnemat PDL::PP mnerrs PDL::PP mncont );
%EXPORT_TAGS = (Func=>[@EXPORT_OK]);
use PDL::Core;
use PDL::Exporter;
use DynaLoader;
@ISA = ( 'PDL::Exporter','DynaLoader' );
push @PDL::Core::PP, __PACKAGE__;
bootstrap PDL::Minuit ;
=head1 NAME
PDL::Minuit -- a PDL interface to the Minuit library
=head1 DESCRIPTION
This package implements an interface to the Minuit minimization routines (part
of the CERN Library)
=head1 SYNOPSIS
A basic fit with Minuit will call three functions in this package. First, a basic
initialization is done with mn_init(). Then, the parameters are defined via
the function mn_def_pars(), which allows to set upper and lower bounds. Then
the function mn_excm() can be used to issue many Minuit commands, including simplex
and migrad minimization algorithms (see Minuit manual for more details).
See the test file minuit.t in the test (t/) directory for a basic example.
=head1 FUNCTIONS
=head2 mn_init()
=for ref
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. The function
to be minimized has to receive five arguments
($npar,$grad,$fval,$xval,$iflag). The first is the number
of parameters currently variable. The second is the gradient
of the function (which is not necessarily used, see
the Minuit documentation). The third is the current value of the
function. The fourth is a piddle with the values of the parameters.
The fifth is an integer flag, which indicates what
the function is supposed to calculate. The function has to
return the values ($fval,$grad), the function value and
the function gradient.
There are three optional arguments to mn_init(). By default, the output of Minuit
will come through STDOUT unless a filename $logfile is given
in the Log option. Note that this will mercilessly erase $logfile
if it already exists. Aditionally, 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.
=for usage
Usage:
mn_init($function_ref,{Log=>$logfile,Title=>$title,Unit=>$unit})
=for example
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 a piddle 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);
}
=head2 mn_def_pars()
=for ref
The function mn_def_pars() defines the initial values of the parameters of the function to
be minimized and the value of the initial steps around these values that the
minimizer will use for the first variations of the parameters in the search for the minimum.
There are several optional arguments. One allows to assign names to these parameters which
otherwise get names (Par_0, Par_1,....,Par_n) by default. Another two arguments can give
lower and upper bounds for the parameters via two piddles. 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 piddles are set to zeroes(n), where n is the number of parameters, i.e. the
parameters are unbound by default.
The function needs two input variables: a piddle giving the initial values of the
parameters and another piddle giving the initial steps. An optional reference to a
perl array with the variable names can be passed, as well as piddles
with upper and lower bounds for the parameters (see example below).
It returns an integer variable which is 0 upon success.
=for usage
Usage:
$iflag = mn_def_pars($pars, $steps,{Names => \@names,
Lower_bounds => $lbounds,
Upper_bounds => $ubounds})
=for example
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 explictly 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 betwen 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}});
=head2 mn_excm()
The function mn_excm() executes a Minuit command passed as
a string. The first argument is the command string and an optional
second argument is a piddle 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.
=for usage
Usage:
$iflag = mn_excm($command_string, {$arglis})
=for example
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);
=head2 mn_pout()
The function mn_pout() gets the current value of a parameter. It
takes as input the parameter number and returns an array with the
parameter value, the current estimate of its uncertainty (0 if
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,
zero if the parameter is constant and negative if parameter is
not defined) and the parameter name.
=for usage
Usage:
($val,$err,$bnd1,$bnd2,$ivarbl,$par_name) = mn_pout($par_number);
=head2 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 UP defining parameter uncertainties (default is 1), 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 all; 1=diagonal approximation, not accurate;
2=full matrix, but forced positive definite; 3=full accurate matrix)
=for usage
Usage:
($fmin,$fedm,$errdef,$npari,$nparx,$istat) = mn_stat();
=head2 mn_emat()
The function mn_emat returns the covariance matrix as a piddle.
=for usage
Usage:
$emat = mn_emat();
=head2 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 0 and 1 which gives
the correlation between the requested parameter and that linear
combination of all other parameters which is most strongly
correlated with it. Unless the command 'MINOS' has been issued via
the function mn_excm(), the first three values will be equal.
=for usage
Usage:
($eplus,$eminus,$eparab,$globcc) = mn_err($par_number);
=head2 mn_contour()
The function mn_contour() 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
specfied by the user, or 1.0 by default (see Minuit manual). The contour
calculated by this function is dynamic, in the sense that it represents the
minimum of the funcion being minimized with respect to all the other NPAR-2 parameters
(if any).
The function takes as input the parameter numbers with respect to which the contour
is to be determined (two) and the number of points $npt required on the contour (>4).
It returns an array with piddles $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.
=for usage
Usage:
($xpt,$ypt,$nfound) = mn_contour($par_number_1,$par_number_2,$npt)
=head1 SEE ALSO
L<PDL>
The Minuit documentation is online at
http://wwwasdoc.web.cern.ch/wwwasdoc/minuit/minmain.html
=head1 AUTHOR
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.
=cut
=head1 FUNCTIONS
=cut
# Package variable
my $mn_options;
sub mn_init{
my $fun_ref = shift;
$mn_options = { Log => undef,
Title => 'Minuit Fit',
N => undef,
Unit => undef,
Function => $fun_ref,
};
if ( @_ ){
my $args = $_[0];
for my $key (qw/ Log Title Unit/){
$mn_options->{$key} = $args->{$key} if exists $args->{$key};
}
}
# Check if there was a valid F77 available and barf
# if there was not and the user is trying to pass Log
if (defined($mn_options->{Log})) {
$mn_options->{Unit} = 88 unless defined $mn_options->{Unit};
}
else { $mn_options->{Unit} = 6; }
if (defined (my $logfile = $mn_options->{Log})){
if (-e $logfile) { unlink $logfile; }
PDL::Minuit::mn_abre($mn_options->{Unit},$logfile,'new');
print "Opening file $logfile....\n";
}
PDL::Minuit::mninit(5,$mn_options->{Unit},$mn_options->{Unit});
PDL::Minuit::mnseti($mn_options->{Title});
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_cierra($mn_options->{Unit});
}
}
=head2 mninit
=for sig
Signature: (int a();int b(); int c())
=for ref
info not available
=for bad
mninit does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mninit = \&PDL::Minuit::mninit;
=head2 mn_abre
=for sig
Signature: (int l(); char* nombre; char* mode)
=for ref
info not available
=for bad
mn_abre does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mn_abre = \&PDL::Minuit::mn_abre;
=head2 mn_cierra
=for sig
Signature: (int l())
=for ref
info not available
=for bad
mn_cierra does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mn_cierra = \&PDL::Minuit::mn_cierra;
sub mn_def_pars{
my $pars = shift;
my $steps = shift;
my $n = nelem($pars);
$mn_options->{N} = $n;
#print "Unit :".$mn_options->{Unit}."\n";
my @names = ();
for (my $i=0; $i < $n; $i++) { $names[$i] = "Par_$i"; }
my $lo_bounds = zeroes($n);
my $up_bounds = zeroes($n);
if ( @_ ) {
my $opts = $_[0];
$lo_bounds = $opts->{Lower_bounds} if defined $opts->{Lower_bounds};
$up_bounds = $opts->{Upper_bounds} if defined $opts->{Upper_bounds};
if (defined($opts->{Names})){
$names_t = $opts->{Names};
barf " Names has to be an array reference" unless ref($names_t) eq 'ARRAY';
@names = @$names_t;
barf " Names has to have as many elements as there are parameters " unless ( @names == $n);
}
}
my $iflag = 0;
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_abre($mn_options->{Unit},$logfile,'old');
}
foreach my $i ( 0..(nelem($pars)-1) ){
my $ii = $i + 1;
$iflag = PDL::Minuit::mnparm($ii,$pars->slice("($i)"),
$steps->slice("($i)"),
$lo_bounds->slice("($i)"),
$up_bounds->slice("($i)"),
$names[$i]);
barf "Problem initializing parameter $i in Minuit " unless ($iflag == 0);
}
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_cierra($mn_options->{Unit});
}
}
=head2 mnparm
=for sig
Signature: (int a(); double b(); double c(); double d(); double e(); int [o] ia(); char* str)
=for ref
info not available
=for bad
mnparm does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mnparm = \&PDL::Minuit::mnparm;
sub mn_excm{
my $command = shift;
my $fun_ref = $mn_options->{Function};
my ($arglis,$narg);
if ( @_ ) { $arglis = shift; $narg = nelem($arglis);}
else { $arglis = pdl(0); $narg = 0; }
if ( @_ ) { barf "Usage : mn_excm($command, [$arglis]) \n"; }
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_abre($mn_options->{Unit},$logfile,'old');
}
my $iflag = pdl(0);
$iflag = PDL::Minuit::mnexcm($arglis, $narg, $command, $fun_ref,$mn_options->{N});
warn "Problem executing command '$command' " unless ($iflag == 0);
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_cierra($mn_options->{Unit});
}
return $iflag;
}
=head2 mnexcm
=for sig
Signature: (double a(n); int ia(); int [o] ib(); char* str; SV* funcion; int numelem)
=for ref
info not available
=for bad
mnexcm does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mnexcm = \&PDL::Minuit::mnexcm;
sub mn_pout{
barf "Usage: mn_pout(par_number)" unless ($#_ == 0);
my $par_num = shift;
my $n = $mn_options->{N};
if (($par_num < 1) || ($par_num > $n)) { barf "Parameter numbers range from 1 to $n "; }
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_abre($mn_options->{Unit},$logfile,'old');
}
my $val = pdl(0);
my $err = pdl(0);
my $bnd1 = pdl(0);
my $bnd2 = pdl(0);
my $ivarbl = pdl(0);
my $par_name = " ";
PDL::Minuit::mnpout($par_num,$val,$err,$bnd1,$bnd2,$ivarbl,\$par_name);
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_cierra($mn_options->{Unit});
}
return ($val,$err,$bnd1,$bnd2,$ivarbl,$par_name);
}
=head2 mnpout
=for sig
Signature: (int ia(); double [o] a(); double [o] b(); double [o] c(); double [o] d();int [o] ib(); SV* str)
=for ref
info not available
=for bad
mnpout does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mnpout = \&PDL::Minuit::mnpout;
sub mn_stat{
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_abre($mn_options->{Unit},$logfile,'old');
}
my ($fmin,$fedm,$errdef,$npari,$nparx,$istat) = PDL::Minuit::mnstat();
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_cierra($mn_options->{Unit});
}
return ($fmin,$fedm,$errdef,$npari,$nparx,$istat);
}
=head2 mnstat
=for sig
Signature: (double [o] a(); double [o] b(); double [o] c(); int [o] ia(); int [o] ib(); int [o] ic())
=for ref
info not available
=for bad
mnstat does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mnstat = \&PDL::Minuit::mnstat;
sub mn_emat{
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_abre($mn_options->{Unit},$logfile,'old');
}
my ($fmin,$fedm,$errdef,$npari,$nparx,$istat) = PDL::Minuit::mnstat();
my $n = $npari->sum;
my $mat = zeroes($n,$n);
PDL::Minuit::mnemat($mat);
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_cierra($mn_options->{Unit});
}
return $mat;
}
=head2 mnemat
=for sig
Signature: (double [o] mat(n,n))
=for ref
info not available
=for bad
mnemat does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mnemat = \&PDL::Minuit::mnemat;
sub mn_err{
barf "Usage: mn_err(par_number)" unless ($#_ == 0);
my $par_num = shift;
my $n = $mn_options->{N};
if (($par_num < 1) || ($par_num > $n)) { barf "Parameter numbers range from 1 to $n "; }
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_abre($mn_options->{Unit},$logfile,'old');
}
my ($eplus,$eminus,$eparab,$globcc) = PDL::Minuit::mnerrs($par_num);
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_cierra($mn_options->{Unit});
}
return ($eplus,$eminus,$eparab,$globcc);
}
=head2 mnerrs
=for sig
Signature: (int ia(); double [o] a(); double [o] b(); double [o] c(); double [o] d())
=for ref
info not available
=for bad
mnerrs does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mnerrs = \&PDL::Minuit::mnerrs;
sub mn_contour{
barf "Usage: mn_contour(par_number_1,par_number_2,npt)" unless ($#_ == 2);
my $par_num_1 = shift;
my $par_num_2 = shift;
my $npt = shift;
my $fun_ref = $mn_options->{Function};
my $n = $mn_options->{N};
if (($par_num_1 < 1) || ($par_num_1 > $n)) { barf "Parameter numbers range from 1 to $n "; }
if (($par_num_2 < 1) || ($par_num_2 > $n)) { barf "Parameter numbers range from 1 to $n "; }
if ($npt < 5) { barf "Have to specify at least 5 points in routine contour "; }
my $xpt = zeroes($npt);
my $ypt = zeroes($npt);
my $nfound = pdl->new;
PDL::Minuit::mncont($par_num_1,$par_num_2,$npt,$xpt,$ypt,$nfound,$fun_ref,$n);
if (defined (my $logfile = $mn_options->{Log})){
PDL::Minuit::mn_cierra($mn_options->{Unit});
}
return ($xpt,$ypt,$nfound);
}
=head2 mncont
=for sig
Signature: (int ia(); int ib(); int ic(); double [o] a(n); double [o] b(n); int [o] id(); SV* funcion; int numelem)
=for ref
info not available
=for bad
mncont does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*mncont = \&PDL::Minuit::mncont;
;
# Exit with OK status
1;
|