Code Monkey home page Code Monkey logo

adadjust's Introduction

doc License: GPL v3

Status

pytests push-pypi push-doc

maintained issues pr

Compatibilities

ubuntu unix

python

Contact

linkedin website mail

AdAdjust

Package allowing to fit any mathematical function to (for now 1-D only) data.

Installation

pip install adadjust

Usage

from adadjust import Function
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams.update({"text.usetex": True})  # Needs texlive installed

nsamples = 1000
a = 0.3
b = -10
xstart = 0
xend = 1
noise = 0.01
x = np.linspace(xstart, xend, nsamples)
y = a * x ** 2 + b + np.random.normal(0, noise, nsamples)


def linfunc(xx, p):
    return xx * p[0] + p[1]


def square(xx, p):
    return xx ** 2 * p[0] + p[1]


func = Function(linfunc, "$a \\times p[0] + p[1]$")
func2 = Function(square, "$a^2 \\times p[0] + p[1]$")

params = func.fit(x, y, np.array([0, 0]))[0]
rr = func.compute_rsquared(x, y, params)

params2 = func2.fit(x, y, np.array([0, 0]))[0]
rr2 = func2.compute_rsquared(x, y, params2)

table = Function.make_table(
    [func, func2], [params, params2], [rr, rr2], caption="Linear and Square fit", path_output="table.pdf"
)
table.compile()
Function.plot(x, [func, func2], [params, params2], y=y, rsquared=[rr, rr2])
plt.gcf().savefig("plot.pdf")

NOTE : to have pretty gaphs, put the line plt.rcParams.update({"text.usetex": True}) just after you imported adadjust. This requiers that you have TexLive full installed on your computer.

The result will be :

Alt text

adadjust's People

Contributors

actions-user avatar

Watchers

Christophe Geissler 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.