Code Monkey home page Code Monkey logo

Comments (4)

HDembinski avatar HDembinski commented on July 29, 2024

Thanks for reporting, that is indeed a bug. I will see how this can be fixed. A temporary workaround for you is

# Minuit fit
p0 = np.array([2., 2., 0., -1., -1.5])
mFit = LeastSquares(x, y, ey, fitFun)
mFit.visualize = lambda x, *args: None
m = Minuit(mFit, p0)  # pass starting values
m.migrad()
# m.hesse()

from iminuit.

HDembinski avatar HDembinski commented on July 29, 2024

If you want to fit a smooth function $f(x)$ through your data points under the condition $f(x) \ge 0$, you can also use Bernstein polynomials. They are guaranteed to be positive inside the domain, if all the parameters are positive. You cannot safely extrapolate Bernstein polynomials outside their domain, though. If you need to query the function outside the fitted range, make the domain of the polynomial as large as you need to query it.

from numba_stats import bernstein

def model(x, p):
    domain_of_polynomial = (-0.4, 0.4)
    return bernstein.density(x, p, *domain_of_polynomial)

start = np.ones(4)  # increase this to increase flexibility of Bernstein polynomial
m = Minuit(LeastSquares(x, y, ey, model), start) 
m.limits = (0, None)  # ensure positiveness
m.migrad()

from iminuit.

claudiocc1 avatar claudiocc1 commented on July 29, 2024

Yes I know :)
We are working with people that like splines (I dont), so here we are....
C.

from iminuit.

HDembinski avatar HDembinski commented on July 29, 2024

I like splines, too :). Bernstein polynomials are a special case of splines.

from iminuit.

Related Issues (20)

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.