Giter Site home page Giter Site logo

datafit's Introduction

datafit.py

This is a python implementation for fitting experimental data to mathematical models and analyzing the quality of fit. The fitting itself is performed by a Levenberg-Marquardt algorithm via the scipy.optimize.leastsq function, and the main role of this code is to facilitate viewing and analysis of the fitting results, including

Standard deviations of best-fit parameter values
Sum of squares of residuals
Parameter covariance matrix
Parameter correlation matrix
Parameter partial correlation matrix
Plotting of model against data
Plotting of fit residuals

The original code was written in the Sage mathematics environment (http://www.sagemath.org) during a graduate data analysis class in order to analyze a series of specific case studies, which are included in the repository along with some of the code adapted to a pure python implementation. Because it began as Sage worksheets, it retains some aspects of the Sage implementation such as the use of symbolic expressions to define model functions (via the sympy module).

In general, csv data is imported and the x and y columns selected using the get_data and get_xy functions. The model expression is defined symbolically, using the sympy.symbols method to initialize the variables and fitting parameters, and passed to a Model object. The x and y data are then passed to the find_fit method of the model along with a dictionary of initial guess values. If the fit is successful, an instance of the Fit class will be returned.

The Fit class includes summary, plot, and plot_residuals methods. The summary prints the best-fit parameter values as well as several outputs useful for analyzing the quality of fit. By default the partial correlation matrix is omitted, as it can become relatively slow to calculate as the number of parameters increases, but it can be requested by setting the partial_correlations keyword of the Model's find_fit call to True.

Dependencies

numpy, scipy, matplotlib, and sympy.

datafit's People

Contributors

adamstone avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.