Fitness ODE Example

From QuB

Jump to: navigation, search

Using Fitness to find the parameters of a system of differential equations

In this example, we use the software package Fitness to solve for the parameters of a spring-dashpot system. Fitness is a graphical program for nonlinear least-squares curve fitting (regression). The data consist of input and output signals. The equations are given as a system of ODEs which are functions of time and the input signal.

Contents

Screen Shot

Pressure clamp Data

figure 7
figure 7

As described in Besch et al (2002), the pressure was recorded from a pressure clamp setup. Ordinarily one records the pressure at the valve, while the cells are at the other end of a tube; they feel a pressure pulse some time later.

In figure 7, they recorded pressure at both ends of the tube. Here we will use their data to model the effect of the tube on pressure.

Modeling with a spring-dashpot system

Our model is a form of spring-dashpot or mass-spring-damper system. It can be written

p'' + 2 \zeta \omega_0 p' + \omega_0^2 p = 0

wnere ζ is the damping ratio and ω0 is the natural frequency.

As given, the spring is driven by deviation from zero: \omega_0^2 p = \omega_0^2 (p - 0);
our system is driven by deviation from the input signal: \omega_0^2 (p - input_t),
so the full equation is:

p''  + 2 \zeta \omega_0 p' + \omega_0^2 (p - input_t) = 0

To use it in Fitness, we must rewrite it as a system of first-order equations:

p' = v

v' = - 2 \zeta \omega_0 v - \omega_0^2 (p - input_t)


Fitness curve fitting software

Fitness is a free program for weighted nonlinear least-squares curve fitting. Download this installer (Windows) and run it. (If you have Ubuntu Linux, see the instructions here. Then run the program by going to the Start menu, all programs, and choosing Fitness.

Now download the example data. To prepare it for Fitness, I already

  1. made sure data are in columns, separated by tab or comma
  2. made sure each column has a unique header

Prepare data

In Fitness, choose File -> Open data file... and pick Fitness_example. This file has three columns: S (time in seconds), pressure_out and pressure_in. The first series S is assumed to be the X (time) axis, and both pressure series are shown in the top graph.

The lower graph shows only the data series (and sub-selection) chosen for fitting. Make sure X is S and Y is pressure_out.

Toward the right it says N is 2500. To integrate the ODEs through all 2500 datapoints would take too long, so we apply a 1000 Hz low-pass filter with automatic decimation. It's hidden with the extra data options -- to show it click the green triangle. When you check the Filter checkbox and type "1000" Hz, you should see N go down to a manageable 50.

Set up equations

Below the graphs we type in the two equations together. Fitness finds the fittable parameters: initial values p0 and v0 and undefined names z and w, along with Slope and Intercept in case you need them (we don't).

We type the equation for p' first because we want to fit pressure_out to p (position) not v (velocity).

Fitting is quicker and more reliable with a good guess at starting parameter values. p0 and v0 should both be 0, since the pressure signals start at 0. The damping ratio, z, can start at 1 (neither over- nor under-damped), and for the natural frequency let's guess 1000.

Also, check the boxes labeled "z" and "w" since those are the parameters we want to estimate.

It would be a shame to have to type the equations again, so click on the Presets menu at right and "Add to menu..."

Already, the red fit curve is similar to the data. Take a look at the stats in the lower right. "SS Residual" is the raw sum of squared difference between curve and data. R-squared is already a respectable 0.968. "Runs p-value" -- the probability a random signal would cross the origin as often as the residual does here -- is almost above the threshold for statistical significance.

Fit

Now click "Fit" at the bottom-right...

And soon we have optimized parameters z=.624 and w=1120, with good R^2 and runs p-value.

Finally, click "Keep It" to make an entry in the "Fitness Fit Table". You can double-click an entry any time to bring it back onscreen.

Etc

VODE for stiff systems

If your ODEs are particularly stiff, you may need to switch to the VODE solver. Click the blue triangle to the right of the equations, choose "VODE", and retype the equations.

Trouble with large N

Differential integration can take literally forever with too many data points. You might accidentally leave your ODE system in the "Curve" area while opening a huge data file. First thing, Fitness tries to integrate the ODEs over all those data points, and it becomes unresponsive. With my apologies, here's how to get it back:

  1. Force quit -- maybe it would take a week to finish
  2. delete this file: c:\\Documents and Settings\username\Application Data\.fitness\qpr\Curve\__active.qpr

(In Windows 2000/XP, Application Data might be hidden. To show it, go to c:\Documents and Settings\username, then Tools menu -> Folder options, then View, and click the box "Show hidden files and folders.")

Other Incredible Features

This example showed just a fraction of the features in Fitness. Please consult the manual to learn more about

  1. Sub-selecting and excluding datapoints
  2. Histograms and spectrum
  3. Image and table output
  4. Y-axis adaptive resampling
  5. Limits -- lower and/or upper bounds on parameters
  6. Weighted curve fitting
  7. Fitting ordinary f(x) style functions
  8. Fitting a list of data files
  9. Custom fitting strategy; e.g. fit this parameter first, then the other
  10. Cross-correlation
  11. Plugins for your own curves and minimizer algorithms.
Personal tools