[go: up one dir, main page]

File: interactive.py

package info (click to toggle)
iminuit 2.30.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,660 kB
  • sloc: cpp: 14,591; python: 11,177; makefile: 11; sh: 5
file content (22 lines) | stat: -rw-r--r-- 533 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from iminuit import Minuit, cost
import numpy as np
from matplotlib import pyplot as plt


# custom visualization; x, y, model are taken from outer scope
def viz(args):
    plt.plot(x, y, "ok")
    xm = np.linspace(x[0], x[-1], 100)
    plt.plot(xm, model(xm, *args))


def model(x, a, b):
    return a + b * x


x = np.array([1, 2, 3, 4, 5])
y = np.array([1.03, 1.58, 2.03, 2.37, 3.09])
c = cost.LeastSquares(x, y, 0.1, model)
m = Minuit(c, 0.5, 0.5)
m.interactive(viz)
# m.interactive() also works and calls LeastSquares.visualize