【发布时间】:2020-11-26 18:33:43
【问题描述】:
一组坐标为x 和y 的点看起来像this。我想在y = 0 下方的区域中构造一条曲线,形式为- a - np.exp(-(x - b)/c),其中参数a、b 和c 是通过以下条件找到的,即y = 0 以下90% 的点被包围通过这一行和有问题的功能。
我编写了以下代码来执行此操作,但 minimize 函数给出了最初的猜测结果,我不知道我错过了什么。
from scipy.optimize import minimize
import numpy as np
def enclosed_points(params):
a, b, c = params
den = (y < 0).sum() # Calculate the number of points with y coordinate below y0
func = - a - np.exp(-(x - b)/c) # Calculate the value of the function for each x
num = ((y < 0) & (y > func)).sum() # Calculate the number of points with y coordinate
# below y0 and above the function
return np.abs(num/den - 0.9) # Return the absolute value of the difference between
# the ratio of num and den and the target number (0.9)
initial_guess = [0.1, 0.2, 1] # Dummy initial guess
result = minimize(enclosed_points, initial_guess)
编辑。 Here我已经上传了npy格式的整个数据的随机样本。
【问题讨论】:
-
您能提供您的示例数据吗?使用示例数据更容易发现问题。
-
@mrhajbabaei 您可以从帖子最后一行的链接下载数据的随机样本。谢谢!文件比较大,不是全集,如果需要我可以上传全集。