scipy-optimize

How to pass multiple constants and variables to Scipy Optimize?

给你一囗甜甜゛ 提交于 2021-02-17 06:26:05
问题 I am trying to fit model data (calculated from eR ) to my experimental data e_exp . I am not quite sure how to pass constants and variables to func . import numpy as np import math from scipy.optimize import curve_fit, least_squares, minimize f_exp = np.array([1, 1.6, 2.7, 4.4, 7.3, 12, 20, 32, 56, 88, 144, 250000]) e_exp = np.array([7.15, 7.30, 7.20, 7.25, 7.26, 7.28, 7.32, 7.25, 7.35, 7.34, 7.37, 13.55]) ezero = np.min(e_exp) einf = np.max(e_exp) ig_fc = 500 ig_alpha = 0.35 def CCER(einf,

Fitting multiple Lorentzians to Brillouin Spectrum using Scipy in Python 3

醉酒当歌 提交于 2021-02-11 17:00:52
问题 I am trying to fit Brillouin Spectra (with several peaks) using scipy.optimize.curve_fit. I have have multiple spectra with several peaks and I am trying to fit them with lorentzian functions (one Lorentzian per peak). I am trying to automate the process for bulk analysis (i.e., using the peak finding algorithm of scipy to get peak positions, peak widths and peaks heights and use them as initial guesses for the fit). I am now working on one spectrum to see if the general idea works, then I

Fitting multiple Lorentzians to Brillouin Spectrum using Scipy in Python 3

杀马特。学长 韩版系。学妹 提交于 2021-02-11 16:58:45
问题 I am trying to fit Brillouin Spectra (with several peaks) using scipy.optimize.curve_fit. I have have multiple spectra with several peaks and I am trying to fit them with lorentzian functions (one Lorentzian per peak). I am trying to automate the process for bulk analysis (i.e., using the peak finding algorithm of scipy to get peak positions, peak widths and peaks heights and use them as initial guesses for the fit). I am now working on one spectrum to see if the general idea works, then I

Simultaneous optimization of two different functions to provide a universal solution for both

爷,独闯天下 提交于 2021-02-11 15:38:45
问题 I asked a similar question in January that @Miłosz Wieczór was kind enough to answer. Now, I am faced with a similar but different challenge since I need to fit two parameters ( fc and alpha ) simultaneously on two datasets ( e_exp and iq_exp ). I basically need to find the values of fc and alpha that are the best fits to both data e_exp and iq_exp . import numpy as np import math from scipy.optimize import curve_fit, least_squares, minimize f_exp = np.array([1, 1.6, 2.7, 4.4, 7.3, 12, 20, 32

How to minimize a real function with only integer input

北战南征 提交于 2021-02-11 15:33:03
问题 Which optimization algorithms work for integer input, float output? One thought is just using Brent search but making up a method that interpolates two nearest points to fake a real number input as opposed to an integer input. My second thought is that seems like such a common need, there must already be something in scipy to do it and/or an algorithm more suited for it? Bisect certainly works for this, but for huge inputs, its convergence time could be improved. Something hybrid like Brent

exponential decay with scipy just gives step function

微笑、不失礼 提交于 2021-02-11 14:26:35
问题 I'm trying to do an exponential fit with a set of data: import matplotlib.pyplot as plt import numpy as np import scipy.optimize as opt def func(x, a, b, c): return a * np.exp(x / -b) + c epr_data = np.loadtxt('T2_text', skiprows=1) time = epr_data[:, 1] intensity = epr_data[:, 2] optimizedParameters, pcov = opt.curve_fit(func, time, intensity) print(optimizedParameters) plt.plot(time, intensity, func(time, *optimizedParameters), label="fit") plt.show() but i just get this step function and

TypeError: Improper input: N=5 must not exceed M=2

霸气de小男生 提交于 2021-02-11 14:19:40
问题 I'm trying to use scipy.optimize.curve_fit with a custom fit function (roughly following this tutorial): # Fit function def fit_function(x, y, x0, y0, A, FWHM): return A*np.exp(1)*4*np.log(2)*((x+x0)**2 + (y+y0)**2)/FWHM**2*np.exp(-4*np.log(2)*((x+x0)**2 + (y+y0)**2)/FWHM**2) # Open image file img = Image.open('/home/user/image.tif') # xdata X, Y = img.size xRange = np.arange(1, X+1) yRange = np.arange(1, Y+1) xGrid, yGrid = np.meshgrid(xRange, yRange) xyGrid = np.vstack((xGrid.ravel(), yGrid

How to organize list of list of lists to be compatible with scipy.optimize fmin init array

时间秒杀一切 提交于 2021-02-11 13:27:36
问题 I am very amateur when it comes to scipy. I am trying to use scipy's fmin function on a multidimensional variable system. For the sake of simplicity I am using list of list of list's. My data is 12 dimensional, when I enter np.shape(DATA) it returns (3,2,2) , I am not even sure if scipy can handle that many dimensions, if not no problem I can reduce them, the point is that the optimize.fmin() function doesn't accept list based arrays as x0 initial parameters, so I need help either rewriting

How to organize list of list of lists to be compatible with scipy.optimize fmin init array

有些话、适合烂在心里 提交于 2021-02-11 13:27:34
问题 I am very amateur when it comes to scipy. I am trying to use scipy's fmin function on a multidimensional variable system. For the sake of simplicity I am using list of list of list's. My data is 12 dimensional, when I enter np.shape(DATA) it returns (3,2,2) , I am not even sure if scipy can handle that many dimensions, if not no problem I can reduce them, the point is that the optimize.fmin() function doesn't accept list based arrays as x0 initial parameters, so I need help either rewriting

How to organize list of list of lists to be compatible with scipy.optimize fmin init array

久未见 提交于 2021-02-11 13:27:18
问题 I am very amateur when it comes to scipy. I am trying to use scipy's fmin function on a multidimensional variable system. For the sake of simplicity I am using list of list of list's. My data is 12 dimensional, when I enter np.shape(DATA) it returns (3,2,2) , I am not even sure if scipy can handle that many dimensions, if not no problem I can reduce them, the point is that the optimize.fmin() function doesn't accept list based arrays as x0 initial parameters, so I need help either rewriting