当前位置: 首页>>代码示例>>Python>>正文


Python Model.make_params方法代码示例

本文整理汇总了Python中lmfit.Model.make_params方法的典型用法代码示例。如果您正苦于以下问题:Python Model.make_params方法的具体用法?Python Model.make_params怎么用?Python Model.make_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lmfit.Model的用法示例。


在下文中一共展示了Model.make_params方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: center_on_cos

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def center_on_cos(raw_quadratures, phi0=None, omega=None, snap_omega=False):
    mean = scipy.average(raw_quadratures, axis=1)
    no_angles, no_pulses = raw_quadratures.shape
    model = Model(cos_model)
    offset, amplitude, phi0, omega = guess_initial_parameters(mean, phi0, omega)
    model.set_param_hint("offset", value=offset)
    model.set_param_hint("amplitude", min=0., value=amplitude)
    model.set_param_hint("phi0", value=phi0)
    model.set_param_hint("omega", min=0., value=omega)
    model.make_params(verbose=False)
    steps = scipy.arange(no_angles)
    res = model.fit(mean, x=steps, verbose=False)
    omega_param = res.params["omega"]
    if snap_omega:
        appx_omega = float(omega_param)
        no_pi_intervals = int(round(pi/appx_omega))
        omega = pi/no_pi_intervals
        omega_param.set(omega, vary=False)
        res.fit(mean, x=steps, verbose=False)
    d_value, p_value_ks = kstest(res.residual, 'norm')
    mean_fit = res.eval(x=steps)
    offset = mean-mean_fit
    aligned_quadratures = raw_quadratures - offset[:,None]
    centered_quadratures = aligned_quadratures - float(res.params["offset"])
    return (centered_quadratures,
            float(omega_param), float(res.params["phi0"]), p_value_ks)
开发者ID:tomohowk,项目名称:tomohowk,代码行数:28,代码来源:standardize_raw_quadratures.py

示例2: make_models

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def make_models(model,peaks):
    """ Make composite models for multiple peaks 
        
        Arguments:
            -- models
            -- peaks: dict of {prefix:"peak_name_", model_params:()}
    """
    if len(peaks)<2:
        mod = Model(model,prefix=peaks[0][0])
        p_guess = mod.make_params()
        values = peaks[0][1:]
        update_params(p_guess,values)

    elif len(peaks)>1:

        mod = Model(model,prefix=peaks[0][0])
        
        values = peaks[0][1:]
        print(values)
        for i in peaks[1:]:
            mod += Model(model,prefix=i[0])
            values.extend(i[1:])

        p_guess = mod.make_params()
        
        update_params(p_guess,values)

        return mod, p_guess
开发者ID:j-brady,项目名称:nmrsa,代码行数:30,代码来源:deconv.py

示例3: gauss_step_const

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def gauss_step_const(signal, guess):
    """
    Fits high contrast data very well
    """
    if guess == False:
        return [0, 0]
    else:
        amp, centre, stdev, offset = guess
        
        data = np.array([range(len(signal)), signal]).T
        X = data[:,0]
        Y = data[:,1]

#         gauss_mod = Model(gaussian)
        gauss_mod = Model(gaussian)
        const_mod = ConstantModel()
        step_mod = StepModel(prefix='step')
        
        pars = gauss_mod.make_params(height=amp, center=centre, width=stdev / 3., offset=offset)
#         pars = gauss_mod.make_params(amplitude=amp, center=centre, sigma=stdev / 3.)
        gauss_mod.set_param_hint('sigma', value = stdev / 3., min=stdev / 2., max=stdev)
        pars += step_mod.guess(Y, x=X, center=centre)

        pars += const_mod.guess(Y, x=X)
    
        
        mod = const_mod + gauss_mod + step_mod
        result = mod.fit(Y, pars, x=X)
        # write error report
        #print result.fit_report()
        print "contrast fit", result.redchi
    
    return X, result.best_fit, result.redchi
开发者ID:DiamondLightSource,项目名称:auto_tomo_calibration-experimental,代码行数:35,代码来源:fit_data.py

示例4: lmDDOPhaseFit

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def lmDDOPhaseFit(xdata, ydata, params, f0_range = 1.2, Q_range = 3):    
    f0= params[0]
    Q=1/(2*params[2])
    
    x = xdata
    y = ydata
#Define a linear model and a Damped Oscillator Model    
#    ddophase_mod = ExpressionModel('off + m*x- arctan(1/Q * 1/(f0/x - x/f0))-')
    ddophase_mod = Model(phase)
#Initial Pars for Linear Model
    pars =  ddophase_mod.make_params(off=0, m=0, f0=f0, Q=Q)

#Add fit parameters, Center, Amplitude, and Sigma
    pars['f0'].set(min=f0/f0_range, max=f0*f0_range)
    pars['Q'].set(min=Q/Q_range, max=Q*Q_range)
#Create full model. Add linear model and all peaks
#Initialize fit
    init = ddophase_mod.eval(pars, x=x)
#Do the fit. The weight exponential can weight the points porportional to the
#amplitude of y point. In this way, points on peak can be given more weight.     
    out=ddophase_mod.fit(y, pars,x=x)
#Get the fit parameters
    fittedf0= out.params['f0'].value
    fittedQ = out.params['Q'].value
#Returns the output fit as well as an array of the fit parameters
    """Returns output fit as will as list of important fitting parameters"""
    return out, [fittedf0, np.nan, np.nan, fittedQ]
开发者ID:davidmiller3,项目名称:plotterGUI,代码行数:29,代码来源:lmPeakFit.py

示例5: get_resvar

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def get_resvar(x, y, mod='linear', zero_intercept=False):
    """
    If `mod == 'linear'` then uses linear regression; otherwise
    `mod == 'sigmoid'` and uses sigmoid regression.
    """
    assert len(x) == len(y)
    if len(x) < 3 or mod == 'linear':
        model = Model(linear)
        params = model.make_params()
        params['a'].value = (y.max() - y.min()) / (x.max() - x.min())
        params['b'].value = y.min()
        if zero_intercept:
            params['b'].value = 0
            params['b'].vary = False
        modfit = model.fit(y, x=x, params=params)
    else:
        model = Model(sigmoid)
        modfit = model.fit(y, x=x, a=y.max(), b=1 / (x.max() - x.min()),
                           c=x.max())
    finex = np.linspace(x.min(), x.max(), 50)
    result = {
        'mod': mod,
        'params': modfit.best_values,
        'resvar': modfit.residual.var(),
        'y': modfit.best_fit,
        'finex': finex,
        'finey': modfit.eval(x=finex),
        'r2': 1 - modfit.residual.var() / np.var(y),
        'modfit': modfit}
    return result
开发者ID:yw5aj,项目名称:YoshiRecordingData,代码行数:32,代码来源:convert10.py

示例6: fit_data_bg

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def fit_data_bg(x, y, peak_pos, peak_type='LO', width=None, bg_ord=0):
    """ 
    Builds a lmfit model of peaks in listed by index in `peak_pos`

    Parameters
    ----------
    peak_type : string (default='lorentizian')
        Peaks can be of the following types:

        - 'LO' : symmetric lorentzian
        - 'GA' : symmetric gaussain
        - 'VO' : symmetric pseudo voigt

    max_width : int (default = total points/10)
        max width (in data points) that peak fitted can be

    bg_ord: int
        order of the background polynomial
        0: constant, 1: linear, ...

    Returns
    -------
    out: 
        fitted model

    """
    # need to define peak width finding
    if width is None:
        width = guess_peak_width(x, y)
    
    # start with polynomial background
    model = PolynomialModel(bg_ord, prefix='bg_')
    pars = model.make_params()

    if peak_type == 'LO':
        peak_function = lorentzian
    elif peak_type == 'GA':
        peak_function = gaussian
    elif peak_type == 'VO':
        peak_function = voigt

    # add peak type for all peaks
    for i, peak in enumerate(peak_pos):
        temp_model = Model(peak_function, prefix='p%s_' % i)
        pars.update(temp_model.make_params())
        model += temp_model

    # set initial background as flat line at zeros
    for i in range(bg_ord + 1):
        pars['bg_c%i' % i].set(0)

    # give values for other peaks, keeping width and height positive
    for i, peak in enumerate(peak_pos):
        pars['p%s_x0' % i].set(x[peak])
        pars['p%s_fwhm' % i].set(width, min=0)
        pars['p%s_amp' % i].set(y[peak], min=0)

    out = model.fit(y, pars, x=x)
    return out
开发者ID:rohanisaac,项目名称:spectra,代码行数:61,代码来源:fitting.py

示例7: multi_disk_fit

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def multi_disk_fit(arcmin_sma, intens, intens_err, bounds, psf):
    h_mat_0 = numpy.ones(len(bounds - 1))
    mod = Model(multi_disk_func)
    pars = mod.make_params(I0 = 1.0, h_mat = h_mat_0, bounds = bounds, PSF = PSF)
    pars['bounds'].vary = False
    pars['PSF'].vary = False
    results = mod.fit(intens, params = pars, x = arcmin_sma, weights = 1.0/intens_err)
    pdb.set_trace()
开发者ID:sstaudaher,项目名称:Ellipse,代码行数:10,代码来源:profile_fitting.py

示例8: lmfit

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def lmfit(mjd,flux,fluxerr):
    t0_guess = mjd[np.argmax(flux)]
    tau_fall_guess = 40.
    tau_rise_guess = -5.
    A = 150.
    B = 20.
    # nflux = np.zeros(2+len(np.array(flux)))
    # nfluxerr = np.ones(2+len(np.array(flux)))/10.
    # nmjd = np.zeros(2+len(np.array(flux)))
    #
    # nflux[1:-1] = flux
    # nfluxerr[1:-1] = fluxerr
    # nmjd[1:-1] = mjd
    # nmjd[1] = mjd[0]-100.
    # nmjd[-1] = mjd[-1]+150
    #
    # flux = nflux
    # fluxerr = nfluxerr
    # mjd = nmjd

    bmod = Model(bazinfunc)
    bmod.set_param_hint('t0', value=t0_guess, min=t0_guess-20, max=t0_guess+20)
    bmod.set_param_hint('tau_fall', value=tau_fall_guess)
    bmod.set_param_hint('tau_rise', value=tau_rise_guess)
    bmod.set_param_hint('A',value=A)
    bmod.set_param_hint('B',value=B)

    pars = bmod.make_params()
    #print(bmod.param_names)
    #print(bmod.independent_vars)
    # print(np.array(flux))
    # print(np.array(1./np.array(fluxerr)))
    # print(np.array(mjd))
    result = bmod.fit(np.array(flux),method='leastsq',weights=1./np.array(fluxerr), t=np.array(mjd))

    #print(result.fit_report())
    # plt.clf()
    # plt.errorbar(np.array(mjd), np.array(flux), yerr=fluxerr,fmt='o')
    # plt.plot(np.array(mjd), result.init_fit, 'k--')
    # plt.plot(np.array(mjd), result.best_fit, 'r-')
    # #plt.xlim(mjd[1],mjd[-2])
    # plt.savefig('bazinfit.png')



    chisq = result.redchi
    ps = result.best_values
    popt = [ps['t0'],ps['tau_fall'],ps['tau_rise'],ps['A'],ps['B']]
    #print('popt',popt)
    #sys.exit()
    # if chisq < 2.:
    #     input('good chisq!')

    # popt, pcov, infodict, errmsg, ier = curve_fit(bazinfunc, mjd, flux,
    #                                               sigma=fluxerr, p0=p0, maxfev=2000000, full_output=True)
    #
    # chisq = (infodict['fvec'] ** 2).sum() / (len(infodict['fvec']) - len(popt))
    return chisq,popt
开发者ID:djbrout,项目名称:deepsnid,代码行数:60,代码来源:bazin.py

示例9: fit_D_phi_powerlaw

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def fit_D_phi_powerlaw(phi_, D):
    """fit stuff"""
    Dmod = Model(Dhop_powerlaw)
    params = Dmod.make_params() 
    params['p'].set(0.3)
    result = Dmod.fit(D, params, phi=phi_)
    print result.fit_report(min_correl=0.5)
    p = result.params['p'].value
    return p
开发者ID:sprakellab,项目名称:dopantdynamics,代码行数:11,代码来源:msd.py

示例10: test_extra_param_issues_warning

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
    def test_extra_param_issues_warning(self):
        # The function accepts extra params, Model will warn but not raise.
        def flexible_func(x, amplitude, center, sigma, **kwargs):
            return gaussian(x, amplitude, center, sigma)

        flexible_model = Model(flexible_func)
        pars = flexible_model.make_params(**self.guess())
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            flexible_model.fit(self.data, pars, x=self.x, extra=5)
        self.assertTrue(len(w) == 1)
        self.assertTrue(issubclass(w[-1].category, UserWarning))
开发者ID:NWUHEP,项目名称:lmfit-py,代码行数:14,代码来源:test_model.py

示例11: fit_D_phi_alt

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def fit_D_phi_alt(phi_, D, c1, c2, c1o, c2o):
    """fit stuff"""
    Dmod = Model(Dhopalt)
    params = Dmod.make_params()
    params['c1'].set(c1, vary=False)
    params['c2'].set(c2, vary=False)
    params['c1o'].set(c1o, vary=False)
    params['c2o'].set(c2o, vary=False)
    params['c3'].set(0.25)
    result = Dmod.fit(D, params, phi=phi_)
    print result.fit_report(min_correl=0.5)
    c3 = result.params['c3'].value
    return c3
开发者ID:sprakellab,项目名称:dopantdynamics,代码行数:15,代码来源:msd.py

示例12: fit_D_phi

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def fit_D_phi(phi_, D, c1, c2):
    """fit stuff"""
    Dmod = Model(Dhop)
    params = Dmod.make_params()
    params['c1'].set(c1, vary=False)
    params['c2'].set(c2, vary=False)
    params['c3'].set(1, vary=False)
    params['beta'].set(0.70, min=0)
    result = Dmod.fit(D, params, phi=phi_)
    print result.fit_report(min_correl=0.5)
    beta = result.params['beta'].value
    c3 = result.params['c3'].value
    return c3, beta
开发者ID:sprakellab,项目名称:dopantdynamics,代码行数:15,代码来源:msd.py

示例13: fit_Dinf_model

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def fit_Dinf_model(Input, diffusion, startindex, endindex):
    time_ = diffusion[startindex:endindex,0]
    D = diffusion[startindex:endindex,1]
    Dmod = Model(Dinf_model)
    params = Dmod.make_params()
    params['var1'].set(0.1) 
    params['Dinf'].set(0.0001)#, min = 0, max=0.1)
    result = Dmod.fit(D, params, time=time_)
    print result.fit_report(min_correl=0.5)
    var1 = result.params['var1'].value
    Dinf = result.params['Dinf'].value
    Dinfstderr = result.params['Dinf'].stderr
    return var1, Dinf, Dinfstderr
开发者ID:sprakellab,项目名称:dopantdynamics,代码行数:15,代码来源:msd.py

示例14: tau_fitter

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def tau_fitter(data,nbins, verbose=True):
    profile_peak = np.max(data)
    binpeak = np.argmax(data)  
    modelname = GxETrain
    model = Model(modelname)
                 
    model.set_param_hint('nbins', value=nbins, vary=False)            
    model.set_param_hint('sigma', value=15, vary=True, min =0, max = nbins)
    model.set_param_hint('mu', value=binpeak, vary=True, min=0, max = nbins)
    model.set_param_hint('A',value=profile_peak, vary=True, min=0)
    model.set_param_hint('tau',value=200, vary=True, min=0)
    model.set_param_hint('dc',value = 0, vary = True)
    pars = model.make_params()
    xax=np.linspace(1,nbins,nbins)

    #"""Fit data"""
    result = model.fit(data,pars,x=xax)
    if verbose == True:
        print(result.fit_report(show_correl = True))
    else:
        print "To see fit report, use verbose=True"
    
    noiselessmodel = result.best_fit
    besttau = result.best_values['tau']
    taustd = result.params['tau'].stderr  ##estimated 1 sigma error
    if taustd == None:
       taustd = 0

    bestsig = result.best_values['sigma']
    bestmu = result.best_values['mu']
    bestA = result.best_values['A']
    bestdc = result.best_values['dc']
    
    bestsig_std = result.params['sigma'].stderr
    bestmu_std = result.params['mu'].stderr
    bestA_std = result.params['A'].stderr
    bestdc_std = result.params['dc'].stderr    
    
    bestparams = np.array([bestsig,bestmu,bestA,bestdc])
    bestparams_std = np.array([bestsig_std,bestmu_std,bestA_std,bestdc_std])
    
    """correlations with sigma"""    
    corsig = result.params['sigma'].correl
    #corA = result.params['A'].correl
    #corlist = [corsig,corA]
    
    
    rchi = result.redchi
    #return best values and std errors on the other parameters as well    
    
    return result, noiselessmodel, besttau, taustd, bestparams, bestparams_std, rchi, corsig
开发者ID:marisageyer,项目名称:Scattering,代码行数:53,代码来源:scatterutils_lofar.py

示例15: fit_data

# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import make_params [as 别名]
def fit_data(x, y, peak_pos, peak_type='LO', width=None):
    """ 
    Builds a lmfit model of peaks in listed by index in `peak_pos` with lineshape
    given by `peak_type`. 

    Parameters
    ----------
    x : array
    y : array
    peak_pos : array of peak postion indices
    
    peak_type : string
        Peaks can be of the following types:
        - 'LO' : symmetric lorentzian (default)
        - 'GA' : symmetric gaussain
        - 'VO' : symmetric pseudo voigt

    width : float
    amp : float

    Returns
    -------
    out : Fitted lmfit model

    """
    
    # get appropriate line shape function

    if peak_type == 'LO':
        peak_function = lorentzian
    elif peak_type == 'GA':
        peak_function = gaussian
    elif peak_type == 'VO':
        peak_function = voigt

    # build model
    model = Model(peak_function, prefix='p0_')
    for i, p in enumerate(peak_pos[1:]):
        model += Model(peak_function, prefix='p%s_' % str(i+1))

    pars = model.make_params()

    # initialize params
    for i, p in enumerate(peak_pos):
        pars['p%s_x0' % i].set(x[p])
        pars['p%s_fwhm' % i].set(width, min=0)
        pars['p%s_amp' % i].set(y[p], min=0)

    out = model.fit(y, pars, x=x)
    return out
开发者ID:rohanisaac,项目名称:spectra,代码行数:52,代码来源:fitting.py


注:本文中的lmfit.Model.make_params方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。