Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: is_functional - Function Up: Utility Previous: fitter.fitted - Function


functionals - Module

Postscript file available

Functionals handling

include "functionals.g"



Description


Introduction

A functional is a function with parameters, defined as f (p;x), where p are the parameters, and x the arguments. Methods are available to calculate the value of a function for a series of argument values for the given set of parameters, and for the automatic calculation of the derivatives with respect to the parameters.

The created functionals can be used in the fitting tool or in any other tool that needs to have generic function values or their derivatives.

A functional has a mask associated with it, to indicate if certain parameters have to be solved for. See masks for details.

To access the functionals module, include the functionals.g Glish script. This will create a default Functionalserver tool called dfs.

- include 'functionals.g'
- dfs.type()             # Default tool created for you
functionals

The Functionalserver tool has no state (it doesn't remember anything), so there is generally no need to create your own tool; just use the default one. However, if you do require one, perhaps in a script, then use the functionals constructor to make one.

- include 'functionals.g';
- myqt := functionals();
- myqt.type();  
functionals

The basic purpose of the Functionalserver tool is to create Functional tools. You do not create Functional tools directly (the Functional tool has no constructor), you always create them via the Functionalserver tool.

Functionals are created in a variety of ways, in general by specifying the name of the functional, together with some necessary information like e.g. the order of a polynomial, or the code needed to compile your privately defined function. Parameters can be set at creation time or later.

- include 'functionals.g'
- a := dfs.gaussian1d()	           # creates a 1D Gaussian, default arguments
- b := dfs.functional('gaussian1') # creates the same one
- a.state()                        # the 'state' of the functional
[type=0, order=-1, ndim=1, npar=3, params=[1 0 1] ] 
- a.type()                         # its type
gaussian1d 
- a.ndim()                         # its dimension (number of arguments)
1 
- a.npar()                         # its number of parameters
3 
- b.state()
[type=0, order=-1, ndim=1, npar=3, params=[1 0 1] ] 
- a.f(1);                          # the value at x=1
0.0625
- a.fdf([0,0.5]);                  # value and derivatives
[[1:2,]
    1   1   0       0
    0.5 0.5 1.38629 0.693147]

In some cases an order can be specified as well (e.g. for polynomials):

- include 'functionals.g'
- a := dfs.poly(3)               # creates a 3rd order polynomial
- b := dfs.functional('polyn',3) # creates the same one, but with
                                 # original defaults
- a.state()
[type=5, order=3, ndim=1, npar=4, params=[1 1 1 1] ] 
- b.state()
[type=5, order=3, ndim=1, npar=4, params=[0 0 0 0] ]

An extremely valuable aspect of the Functionals module is the ability to create a functional from a compiled string specifying an arbitrary function. For example, let us make our own polynomial 1 + 2*x + 3*x2 and evaluate it at a few abcissa locations

- include 'functionals.g'
- a := dfs.compiled ('p0 + p1*x + p2*x*x', [1,2,3])   # Define
- a.f([0,10,20])                                      # Evaluate at x=[0,10,20]
[1 321 1241]

The functions created can also be used to specify the function to be fitted in a least squares fit (see the fitting tool ).

Functions
is_functional Check if functional

Tools
functional functional tool
functionalserver functionalserver tool




next up previous contents index
Next: is_functional - Function Up: Utility Previous: fitter.fitted - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15