A physical model in Specview is represented by a set of spectral components (Sec. 6.1).
For fitting purposes, data is regarded as a set of 1-D arrays storing the independent (wavelength) and dependent variable (monochromatic flux density), and eventually errors associated with the dependent variable. These arrays are not required to be sorted in increasing or decreasing wavelength order, neither have to be equally spaced. However, at this point Specview does not provide any means to specify variable weighting of each datum beyond the standard chi-squared weighting. So when fitting on data sets with very different dispersions and / or sampling properties, fitting results may be biased towards the data sets with larger number of data points, regardless of their resolution and spectral coverage.
Chi-squared is computed under the Gaussian noise assumption. No other types of errors are supported yet.
Fitting is performed by non-linear minimization algorithms applied to the chi-squared value. These algorithms require that a first guess be provided for each single quantity to be fitted, in our case, each component parameter to be fitted. To this end, the model manager is equipped with a set of interactive tools that can be used to build a first guess spectral model suitable to be input to the fitting algorithms.
Models can be fitted to either raw or processed (Sec. 5) data. However, since processing in general involves operations such as resampling on the wavelength scale, and eventual low-pass filtering, it should be avoided in case one plans to fit models to the data.
Models can be fitted to either observed wavelengths, or to rest (co moving) wavelengths as built by the radial velocity tool (Sec. 4.3.1).
If data fitting is enabled, a button labeled Fit will appear among the display controls (Sec. 2.2). Clicking that button initiates a sequence of events. Basically, the original spectrogram is augmented with two extra data arrays, one to hold the model values and another to hold the residual values. These are data arrays with exactly the same attributes as the other data arrays in the spectrogram, and can be displayed and examined in the same way as the regular data arrays. The specific data array to which the model is associated to is the one that was being displayed at the moment the Fit button was clicked.
The plot is then replaced by a new plot of this augmented spectrogram. Notice that this new plot will be initialized in the same way as a regular plot, so the data array to which the model was associated to may not show up straight away and will need to be selected using the Y axis selector (Sec. 2.2).
Bug: the model plot may contain artifacts when the data is comprised of mixed types that require plotting as both continuous lines and separate symbols. Plotting the model data by itself using the Y axis array selector (Sec. 2.2) will get rid of the artifacts.
Specview also creates a window that gives access to the model
manager. It looks like this:
The window has four main elements. From top to bottom:
Specview provides a library of spectral components (Sec. 6.1.0) that can be combined at will to build a model. Spectral components are basically analytic functional forms that have associated with them a set of parameters, and some ancillary information such as the function name and ID string. Parameters in turn are basically floating point numbers that have associated with them a variety of attributes, such as physical units, validity range, step and tolerance, fitting mode, error, etc. Most of these attributes are of interest only to the model fitting algorithms and are not used by the spectral component when computing a component value.
Components can be classified as emission components or absorption components. Emission components contribute to the model in an additive way, absorption components are expressed in transparency and contribute to the model in a multiplicative way. The model is built by scanning the component list from top to bottom (according to the running number) and adding or multiplying each component's contribution in turn. Thus the order in which components are listed in the database is significant, and one can use this building mechanism to model the effect of emission components that are "in front" of absorption components, such as air glow lines or lines from excited circunstelar gas superimposed on a photosphere spectrum.
Spectral components can also be classified as broadband or line profile. The difference between these two types is that line profile components have a specific location in the independent variable space (wavelength) to which they are associated with. They contribute to the model over a finite range of wavelengths, their contribution outside this wavelength range being negligible. Broad band components on the other hand provide a non negligible contribution to the model over an unlimited range of wavelengths. This differentiation between the two types is important to bear in mind when using interactive graphics tools to initialize or modify the components. It is an important factor when it comes to speed up the model computations.
The difference between broadband and line profile components is also
important when considering the effects of any given component on the global
chi-squared computation. A large but
very narrow line profile component can have a very small or even negligible
contribution to the global chi-squared, if its wavelength range is much shorter
than the wavelength range spanned by the data being fitted. Such components
will be difficult to fit since the algorithm will have low sensitivity to
changes on the component parameters.
Buttons on the topmost row in the model
manager window are used to access a single component in the list. Most
of them require that a selection be made by clicking the mouse over the
component's entry in the list. The component can be added, deleted, re-inserted
or modified.
Adding a component takes place by clicking on the Add button. This brings up a selection window that displays, in tree form, all the available components. At first invocation, the tree is closed:
Opening the branches makes the components of each sub-type visible. Here is a view of the entire open tree:
By clicking on the desired component name, a component of that type is created, initialized, and placed at the end of the list. Details about each component are discussed in Sec. 6.1.0.
The initialization of each component is handled by the component itself, and the exact details depend on the component type. Usually a component tries to adjust itself to the current WCS view port in the main display window, or alternatively, tries to fit itself to the stretch of data showing up through the current WCS view port. So for example when adding a Gaussian absorption line to the model, one would first zoom in to the position where the Gaussian must be placed, and them click on one of the absorption Gaussian entries in the selector list. Once entered into the model, the component can be further modified (Sec. 6.2.2).
The component selector window also provides means for the user to add custom made components. This capability is discussed here in Sec. 6.1.4.
Note: the reddening components technically belong to the broad
band absorption group, but are grouped separately for convenience.
By selecting a component entry in the list and clicking on the Adjust button, the initialization procedure in the component will be re-activated and the component will re-adjust itself to the current WCS view port, or data, in the main display window.
Line profile components (Sec. 6.1) can also be
re-centered. This means modifying their parameter that specifies their location
on the independent variable axis, keeping all other parameters constant . This
is done by first selecting the desired component and then clicking on the Recenter
button. A message on the prompt line will
prompt for the user to position the cross-hair cursor over the desired
wavelength / frequency / energy value in the main display window and click the
mouse there. The component will then be re-centered.
The Copy button creates a copy of the selected component and places it at the end of the database list. No further adjustments are performed.
Bug: the copy button is disabled for now due to a unknown bug in the cloning mechanism.
The Delete button removes the selected component from the list. The
deleted component is kept in an internal buffer and can be re-inserted in the
list at the position of the currently selected component by clicking on the Re-insert
button. The currently selected component and all others below it will be pushed
one level downwards. This mechanism must be used to place emission and
absorption components into the required order (Sec. 6.1) of
the physical model being fitted.
Selecting a component in the list and clicking on the Edit button activates the component's interactive window. The specific contents of the window are dependent on the component type, but the general layout looks like this:
From top to bottom:
Each parameter sub-window in turn has the following elements:
Clicking on the arrow button brings up an ancillary window with the following elements:
The ancillary window provides a modal dialog, that is,
everything else in the application freezes until the OK button is
clicked. The component interactive window, on the other hand, can remain on
screen and will report all changes that take place on the parameters' values
and errors. The window can be dismissed using the standard dismiss mechanisms
provided by the windowing system .
Components are normally computed independently of each other. However, one can also constrain (tie) a component such that its parameters are individually expressed as a function of another component's parameters. There are a number of ways to implement such constraining mechanisms; in Specview we adopt a simple method that is sufficient to handle most problems. For a lengthier discussion, see Sec. 6.9.
Parameters in the constrained component (child) are constrained to their matching parameters in the parent component, using as matching criterion the parameter name. If the names are the same, the parameters are constrained. If the names do not match, the corresponding parameters are left unconstrained. Apart from this name matching criterion, there are no restrictions on the types of components that can be constrained together.
The value of a constrained parameter that is typed or reported in the parameter value window is not the actual value of the parameter, but a multiplicative factor that must be applied to the actual value of the matching parameter of the parent component, to recover the actual value of the parameter. This multiplicative factor is the constraint value. Constraint values are represented in blue color in their text windows.
This is an example where the [OIII] doublet at 4959/5007 A is constrained
using atomic physics values.
In this example, the constrained components are identical in type (both are emission Gaussians) thus, all parameters in the child component are constrained to their matching parameters in the parent component.
Constrained components are identified in the component list by the running number of their parent component. These identification numbers are automatically re-generated on the fly whenever components are added, deleted or re-inserted in the model. In output files generated by Specview's model manager, parameters are reported with their actual values and units, not the constraint values.
Parameters in constrained mode keep their ability to be set to either fixed or variable mode during a fit operation. The default action when constraining a parameter is to make it fixed, but the user can explicitly ask for specific parameters to be varied during a fit by clicking in their Fit boxes. Notice also that the Fix all and Default fit buttons discussed in Sec. 6.6 always set all constrained parameters to fixed mode.
Constrained parameters that are allowed to vary during the fit are handled exactly in the same way as non constrained parameters. The only difference is that the value (and eventual error) reported at he parameter's window (Sec. 6.2.4) is expressed as a constraint value, not the parameter's actual value. If required, a constrained parameter's actual value can be peeked at by temporarily unconstraining the component which it belongs to.
To constrain a component, select its entry in the model manager's component list and click on the Constrain button. The prompt line will then ask you to select the parent component. Select the desired parent component by clicking on its entry in the component list. At this point, the values reported at the child's interactive window (Sec. 6.2.4) for each constrained parameter are replaced by the constraint values that reflect the component's current state.
To un-constrain a component, just select its entry in the model manager's component list and click the Un-constrain button. Constraint values reported at the component's interactive window are replaced by the actual values that reflect the component's current state.
Components can be constrained in chain, that is, a constrained component can
be the parent of another constrained component.
The buttons in the mid row in the model manager window enable the user to define a subset of the whole wavelength / frequency / energy range encompassed by the spectrogram being fitted. The subset can be built out of one or more disjoint wavelength / frequency / energy ranges. See below though.
Clicking on the Define range button, a message appears on the prompt line asking the user to position the cross-hair cursor at an end of the desired range and click the mouse there. Then another message prompts the user to place the cursor at the other end of the desired range and click the mouse again. The display will then be updated with a mark that shows the selected range. Other ranges can be added at will using the same mechanism.
The Undo range button deletes the last range entered. Successive application of this function removes ranges, one by one, in the opposite order in which they were entered in.
The Reset ranges button clears all range settings and returns the model to the default (entire) wavelength range.
Superimposed ranges: if two or more ranges are
superimposed, the common sub range in between then will be counted multiple
times by the fitting algorithm. This has the effect of effectively increasing
the weights associated with the sub range. This effect can be regarded as
either a bug or a desirable feature. It is not clear at this point, if we
should keep this behavior in place or remove it; user feedback is welcome.
When fitting to a sub-range of the wavelength span of the data, line profile components that lie outside the selected ranges are placed in an inactive state. This means that they are effectively removed from all the model computations, and are not fitted, regardless of the state of their parameters. Line profile components are set to inactive when their position (or center) parameter value falls outside any of the existing wavelength ranges. The list displayed in the model manager window depicts inactive components in a lighter color.
The selection of each component active state is automatically performed by the
model manager whenever wavelength ranges are selected. See also paragraph 6.8.1.
The bottom row of buttons in the model manager window enables the user to perform operations of a global nature over the entire set of spectral components currently in the model.
The Reset model button puts all the model components back at the point they where before the last run of the fitting algorithm. This is a convenient way to go back to a meaningful state when e.g. the fitting algorithm diverges and some component parameters get stuck into meaningless regions of parameter space.
The Fix all button sets all parameters in all components to fixed
mode. The Default fit button sets all parameters in all components to
their default fit mode. The fit mode is selected by the Fit
check box in the parameter interactive window. Each type of component is
initialized with a default configuration for the fit mode of each of its
parameters. This default mode is supposed to maximize the stability of the
fitting algorithm when run for the first time. For instance, line profile
components usually have their Center parameter set to fixed mode to
prevent then from wandering around over a wild range of wavelengths. The
detailed behavior of course depends on the specific fitting algorithm being
used, as well as on how and if it uses the step and range attributes of each
parameter. In many cases users will require that spectral lines remain fixed at
their lab (or "known") wavelengths anyway (Planned upgrade:
radial velocity parameter to convert between lab and observed wavelengths).
Clicking on the Fit button brings up the fit manager
interactive window.
The topmost selector allows the selection of one of two available minimization algorithms: simplex, or Levenberg-Marquardt. Right to its side a one-line status message reports on the current running status of the algorithm. The quantity to be minimized can be selected in between the error-weighted reduced chi squared, or the unweighted sum of squared residuals, by selecting the corresponding radiobutton. If no errors are associated with the spectrogram data being fitted, the chisq button will be disabled.
The three status lines report the progress of the minimization algorithm. The meaning of the Convergency parameter is algorithm dependent. For the simplex algorithm, this parameter is defined as the maximum relative change in reduced chi-squared (or r.m.s.) that can be achieved at the current iteration. For the Levenberg-Marquardt algorithm, the convergency parameter is simply the difference in reduced chi-squared (or r.m.s.) between the current and last iteration.
For some types of data, the convergency target value (the value at which the algorithm will stop) must be adjusted empirically. E.g. ISO-LWS flux data require typical values in the range of 10^-10 instead of the default. If one notices that the algorithm runs for just a couple of iterations and stubbornly stops, one may decrease the convergency target value until a satisfactory fit is obtained.
The minimization algorithm runs in the background and can be stopped and re-started at will. When stopped, any windows that are on-screen and whose contents are affected by the fit, are updated automatically. One can thus monitor the minimization progress by stopping temporarily the algorithm to let the windows refresh, and then continuing the fit from that point. The Step button will run the algorithm for a single iteration. Both algorithms will stop regardless of any other condition at 5000 iterations. They also stop when the convergency criterion gets below the value listed in the Convergency parameter. In any case, as with any non-linear fitting algorithm, it is always wise to re-run the fit for a second time once a first solution is found.
Note that the simplex algorithm is unable, by design, to compute error estimates for the fitted parameters. However, one can always re-run the fit with the Levenberg-Marquardt algorithm, after simplex has converged to an acceptable solution. It will usually converge within a few iterations since it is already starting with the simplex solution as first guess. Levenberg-Marquardt computes error estimates for all fitted parameters simultaneously, based on the covariance matrix and chi-squared value. Note that if no errors are associated with the data being fitted, no parameter error estimation is possible.
The Levenberg-Marquardt algorithm can be slower than the simplex algorithm for the same problem, since it depends on computing the model and all its partial second derivatives at each single data point in the spectrogram array. The recommended strategy is to use the simplex algorithm during the exploratory phase. When a satisfactory solution is found, then the Levenberg-Marquardt algorithm can be run once to confirm the solution and compute the parameter's errors.
Bug: when the
Levenberg-Marquardt algorithm finishes running, it leaves the Fit
selectors of all parameters in a frozen, unresponsive state. The only
workaround at this time is to save the component list to file and read it back.
This seems to unlock the fit selectors of each parameter to their former state.
Specview can save the component list to a file and
read it back later. It can also write the list contents in text format to a
file. This text file is the main product of the fitting process. This
functionality is accessed through the File menu in the model manager interactive window:
Clicking in any of the items will bring up a file selector window. File names must have the suffix ".cdb" ("component data base"). The file selector will display only file names that end in ".cdb" and ".txt". Once a component data base file is written or read, subsequent save operations can be performed by simply clicking the Save button at the bottom row on the model manager window . This will overwrite the last accessed .cdb file with the current contents of the list.
Component data base files are written in XML format so they are portable across operating systems, versions of Specview, and versions of the Java Development Kit.
In the current version of Specview the wavelength ranges are not saved as part of the component list. The reason is that a component data base file can in practice be re-used to initialize the fit to other spectrograms than the one that was originally used to create the file. Thus, we avoid at this point to include in the component data base file any information that is specific to the data being fitted. It remains to be seen if this is the most convenient approach for the majority of users.
6.8.1: When reading a component list from an existing component data base file, it may happen that line profile components will lie outside the range of wavelengths spanned by the data. This will happen, say, when the data base file was generated from a spectrogram that encompasses a different wavelength range than the one at hand. In this case, the affected line profile components will be set to the inactive state (Sec. 6.5), and remain there for the entire fitting session.
When writing the component list to a text file, one can select that either
the entire list, or just the currently active components, be printed out.
There are a number of ways in which a generic constraining mechanism between component parameters can be devised. One could for instance constrain individual parameters from a given component, to individual parameters of one or more other components in the model, in a manner very independent of each parameter's type or name. One could also devise all kinds of elaborate mechanisms for the constraints themselves, including parameters that depend on more than a single parent parameter via an arbitrary mathematical expression. Most of these implementations are relatively straightforward to implement under an Object Oriented framework, and they exist in one form or another in other software packages. The main problem is the user interface. Under a command line interface, these more complex implementations are possible, but in general are hard to use and present a steep learning curve to the user. A graphical user interface to access an arbitrarily complex constraining mechanism would be complicated enough to undermine one of the main goals of Specview, which is to provide an easy to use user interface.
Thus, the constraining method used in Specview was simplified to the
point that provides appropriate functionality to solve most of the usual
problems, with the simplest possible user interface. However, the underlying
code was conceived in such a way that it can support arbitrarily complex
constraining methods; the user interface is the point where simplifications
were made such as to result in a simple to use program. If in the future one
comes up with a clever design for a user interface to support a more complex
constraining mechanism, the code is already in place to support it. Suggestions
from users in this regard are welcome.