From 17ee31b51081b8281b652fa06b997918003f7772 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 8 Jul 2009 01:04:31 +0000 Subject: asymptote 1.80 git-svn-id: svn://tug.org/texlive/trunk@14179 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/utils/asymptote/base/animation.asy | 31 +++++---- Build/source/utils/asymptote/base/lmfit.asy | 89 ++++++++++++++++++------- 2 files changed, 83 insertions(+), 37 deletions(-) (limited to 'Build/source/utils/asymptote/base') diff --git a/Build/source/utils/asymptote/base/animation.asy b/Build/source/utils/asymptote/base/animation.asy index 2b7519c700a..6fcd2ad70e2 100644 --- a/Build/source/utils/asymptote/base/animation.asy +++ b/Build/source/utils/asymptote/base/animation.asy @@ -38,8 +38,8 @@ struct animation { this.global=global; } - string basename(string prefix=prefix) { - return "_"+stripextension(prefix); + string basename(string prefix=stripextension(prefix)) { + return "_"+prefix; } string name(string prefix, int index) { @@ -47,7 +47,7 @@ struct animation { } private string nextname() { - string name=name(prefix,index); + string name=basename(name(prefix,index)); ++index; return name; } @@ -61,8 +61,9 @@ struct animation { void add(picture pic=currentpicture, fit fit=NoBox) { if(global) { + ++index; pictures.push(pic.copy()); - } else this.shipout(nextname(),fit(prefix,pic)); + } else this.shipout(fit(prefix,pic)); } void purge(bool keep=settings.keep) { @@ -89,6 +90,7 @@ struct animation { void export(string prefix=prefix, fit fit=NoBox, bool multipage=false, bool view=false) { if(pictures.length == 0) return; + if(!global) multipage=false; rescale(pictures); frame multi; bool inlinetex=settings.inlinetex; @@ -119,6 +121,7 @@ struct animation { string load(int frames, real delay=animationdelay, string options="", bool multipage=false) { + if(!global) multipage=false; string s="\animategraphics["+options+"]{"+format("%.18f",1000/delay,"C")+ "}{"+basename(); if(!multipage) s += "+"; @@ -129,13 +132,13 @@ struct animation { string pdf(fit fit=NoBox, real delay=animationdelay, string options="", bool keep=settings.keep, bool multipage=true) { if(settings.inlinetex) multipage=true; + if(!global) multipage=false; if(settings.tex != "pdflatex") abort("inline pdf animations require -tex pdflatex"); if(settings.outformat != "") settings.outformat="pdf"; string filename=basename(); string pdfname=filename+".pdf"; - bool single=global && multipage; if(global) export(filename,fit,multipage=multipage); @@ -147,28 +150,28 @@ struct animation { void exitfunction() { if(currentexitfunction != null) currentexitfunction(); this.purge(); - if(single) + if(multipage) delete(pdfname); } atexit(exitfunction); } - if(!single) + if(!multipage) delete(pdfname); - return load(pictures.length,delay,options,multipage); + return load(index,delay,options,multipage); } int movie(fit fit=NoBox, int loops=0, real delay=animationdelay, string format=settings.outformat == "" ? "gif" : settings.outformat, string options="", bool keep=settings.keep) { - if(global && format == "pdf") { - export(fit,multipage=true,view=true); - return 0; - } - - if(global) + if(global) { + if(format == "pdf") { + export(fit,multipage=true,view=true); + return 0; + } export(fit); + } return merge(loops,delay,format,options,keep); } } diff --git a/Build/source/utils/asymptote/base/lmfit.asy b/Build/source/utils/asymptote/base/lmfit.asy index d0367547b74..72745625824 100644 --- a/Build/source/utils/asymptote/base/lmfit.asy +++ b/Build/source/utils/asymptote/base/lmfit.asy @@ -22,6 +22,18 @@ SOFTWARE. */ +/* + Fitting $n$ data points $(x_1, y_1 \pm \Delta y_1), \dots, (x_n, y_n \pm \Delta y_n)$ + to a function $f$ that depends on $m$ parameters $a_1, \dots, a_m$ means minimizing + the least-squares sum + % + \begin{equation*} + \sum_{i = 1}^n \left( \frac{y_i - f(a_1, \dots, a_m; x_i)}{\Delta y_i} \right)^2 + \end{equation*} + % + with respect to the parameters $a_1, \dots, a_m$. +*/ + /* This module provides an implementation of the Levenberg--Marquardt (LM) algorithm, converted from the C lmfit routine by Joachim Wuttke @@ -747,16 +759,20 @@ void lm_minimize(int m_dat, int n_par, real[] par, lm_evaluate_ftype evaluate, l // convenience functions; wrappers of lm_minimize -struct FitControl { - real squareSumTolerance; - real approximationTolerance; - real desiredOrthogonality; - real epsilon; - real stepBound; - int maxIterations; - bool verbose; - void operator init(real squareSumTolerance, real approximationTolerance, real desiredOrthogonality, real epsilon, real stepBound, int maxIterations, bool verbose) { +/* + The structure FitControl specifies various control parameters. +*/ +struct FitControl { + real squareSumTolerance; // relative error desired in the sum of squares + real approximationTolerance; // relative error between last two approximations + real desiredOrthogonality; // orthogonality desired between the residue vector and its derivatives + real epsilon; // step used to calculate the jacobian + real stepBound; // initial bound to steps in the outer loop + int maxIterations; // maximum number of iterations + bool verbose; // whether to print detailed information about every iteration, or nothing + + void operator init(real squareSumTolerance=LM_USERTOL, real approximationTolerance=LM_USERTOL, real desiredOrthogonality=LM_USERTOL, real epsilon=LM_USERTOL, real stepBound=100, int maxIterations=100, bool verbose=false) { this.squareSumTolerance = squareSumTolerance; this.approximationTolerance = approximationTolerance; this.desiredOrthogonality = desiredOrthogonality; @@ -779,30 +795,44 @@ struct FitControl { } }; +FitControl operator init() { + return FitControl(); +} + FitControl defaultControl; -defaultControl.squareSumTolerance = LM_USERTOL; -defaultControl.approximationTolerance = LM_USERTOL; -defaultControl.desiredOrthogonality = LM_USERTOL; -defaultControl.epsilon = LM_USERTOL; -defaultControl.stepBound = 100; -defaultControl.maxIterations = 100; -defaultControl.verbose = false; +/* + Upon returning, this structure provides information about the fit. +*/ struct FitResult { - restricted real norm; - restricted int iterations; - restricted int status; + real norm; // norm of the residue vector + int iterations; // actual number of iterations + int status; // status of minimization - void operator init(real norm, int status, int iterations) { + void operator init(real norm, int iterations, int status) { this.norm = norm; - this.status = status; this.iterations = iterations; + this.status = status; } }; -// Fits data points (xdata, ydata ± errors) to the given function using the given parameters. +/* + Fits data points to a function that depends on some parameters. + + Parameters: + - xdata: Array of x values. + - ydata: Array of y values. + - errors: Array of experimental errors; each element must be strictly positive + - function: Fit function. + - parameters: Parameter array. Before calling fit(), this must contain the initial guesses for the parameters. + Upon return, it will contain the solution parameters. + - control: object of type FitControl that controls various aspects of the fitting procedure. + + Returns: + An object of type FitResult that conveys information about the fitting process. +*/ FitResult fit(real[] xdata, real[] ydata, real[] errors, real function(real[], real), real[] parameters, FitControl control=defaultControl) { int m_dat = min(xdata.length, ydata.length); int n_par = parameters.length; @@ -831,7 +861,20 @@ FitResult fit(real[] xdata, real[] ydata, real[] errors, real function(real[], r } -// Fits data points (xdata, ydata) to the given function using the given parameters. +/* + Fits data points to a function that depends on some parameters. + + Parameters: + - xdata: Array of x values. + - ydata: Array of y values. + - function: Fit function. + - parameters: Parameter array. Before calling fit(), this must contain the initial guesses for the parameters. + Upon return, it will contain the solution parameters. + - control: object of type FitControl that controls various aspects of the fitting procedure. + + Returns: + An object of type FitResult that conveys information about the fitting process. +*/ FitResult fit(real[] xdata, real[] ydata, real function(real[], real), real[] parameters, FitControl control=defaultControl) { return fit(xdata, ydata, array(min(xdata.length, ydata.length), 1.0), function, parameters, control); } -- cgit v1.2.3