Git Product home page Git Product logo

Comments (3)

pheuer avatar pheuer commented on June 20, 2024

I think this is a bug in lmfit 1.3.0. The documentation states that additional keywords to Model are passed to the model function, but this clearly isn't happening based on the following minimal non-working example. I will open an issue on the lmfit repository

import numpy as np
from lmfit import Model, Parameters

# Define some data
x = np.linspace(0,1,num=10)
data = 10*x+2



# Parameters list with one parameter
params = Parameters()
params.add("b", value=5, vary=True, min=0.5, max=25)


# Dictionary of constants to be passed to model function through **kws
# of `Model`
settings = {'a':2}


# Define a model function that takes the parameters and the settings keyword
def _model(x, settings=None, **params):
    
    # TypeError is raised here because `settings` keyword is not being 
    # passed through to `_model`, so `settings=None`
    a = settings['a']
    b = params['b']
    
    return x*b + a


model = Model(
     _model,
     independent_vars=["x"],
     settings=settings,
 )


# Try to fit
# This raises an exception
result = model.fit(
    data,
    params=params,
    x=x,
    method="leastsq",
)

print(result.best_values)

from plasmapy.

pheuer avatar pheuer commented on June 20, 2024

If lmfit doesn't want to restore this functionality (or it takes a while to get that in their release version), the following fix would work (around line 1007 of thomson.py). The lambda function provides a work around way of passing settings into _spectral_density_model

_spectral_density_model_lambda = lambda wavelengths, **params: _model(wavelengths, settings=settings, **params)

 return Model(
        _spectral_density_model_lambda,
        independent_vars=["wavelengths"],
        nan_policy="omit",
        )

from plasmapy.

pheuer avatar pheuer commented on June 20, 2024

Closed by #2623

from plasmapy.

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.