Package park :: Package fitting :: Module fit

Module fit

source code

Fitting service interface.

A fit consists of a set of models and a fitting engine. The models are collected in an assembly, which manages the parameter set and the constraints between them. The models themselves are tightly coupled to the data that they are modeling and the data is invisible to the fit.

The fitting engine can use a variety of methods depending on model.

Usage

The fitter can be run directly on the local machine:

import park
M1 = park.models.Peaks(datafile=park.sampledata('peak.dat'))
M1.add_peak('P1', 'gaussian', A=[4,6], mu=[0.2, 0.5], sigma=0.1)
result = park.fit(models=[M1])
print result

The default settings print results every time the fit improves, and print a global result when the fit is complete. This is a suitable interface for a fitting script.

For larger fit jobs you will want to run the fit on a remote server. The model setup is identical, but the fit call is different:

service = park.FitService('server:port')
result = park.fit(models=[M1], service=service)
print result

Again, the default settings print results every time the fit improves, and print a global result when the fit is complete.

For long running fit jobs, you want to be able to disconnect from the server after submitting the job, and later reconnect to fetch the results. An additional email field will send notification by email when the fit starts and ends, and daily updates on the status of all fits:

service = park.FitService('server:port')
service.notify(email='me@my.email.address',update='daily')
fit = park.Fit(models=[M1])
id = service.start(fit, jobname='peaks')
print id

The results can be retrieved either by id returned from the server, or by the given jobname:

import park
service = park.FitService('server:port',user='userid')
fitlist = service.retrieve('peaks')
for fit in fitlist:
    print fit.summary()

The fit itself is a complicated object, including the model, the optimizer, and the type of uncertainty analysis to perform.

GUI Usage

When used from a graphical user interface, a different programming interface is needed. In this case, the user may want to watch the progress of the fit and perhaps stop it. Also, as fits can take some time to complete, the user would like to be able to set up additional fits and run them at the same time, switching between them as necessary to monitor progress:

import park

def start
service = park.FitService('server:port',user='userid')
fit = park.Fit(models=[M1])
id = sevice.start(fit,
Classes
  Objective
Abstract interface to the fitness function for the park minimizer classes.
  Fitter
Abstract interface for a fitness optimizer.
  FitJob
Fit job.
  LocalQueue
Simple interface to the local job queue.
Functions
 
fit(models=None, fitter=None, service=None, handler=None)
Start a fit with a set of models.
source code
 
assembly_example() source code
Function Details

fit(models=None, fitter=None, service=None, handler=None)

source code 

Start a fit with a set of models. The model set must be in a form accepted by park.assembly.Assembly.

This is a convenience function which sets up the default optimizer and uses the local fitting engine to do the work. Progress reports are printed as they are received.

The choice of fitter, service and handler can be specified by the caller.

The default fitter is FitMC, which is a monte carlo Nelder-Mead simplex local optimizer with 100 random start points.

The default handler does nothing. Instead, ConsoleUpdate could be used to report progress during the fit.

The default service is to run in a separate thread with FitThread. Note that this will change soon to run in a separate process on the local machine so that python's global interpreter lock does not interfere with parallelism.