【发布时间】:2022-01-04 01:49:05
【问题描述】:
对于我目前正在开发的新应用,我一直在尝试在 Python 中执行以下操作:
输入:
-
list_of_points- n 个样本点 x。每个都有 d 个维度(每个都表示为一个列表),其中 d 被假定为很大(越大越好)。 -
list_of_values- n 值“隐藏函数” f.即list_of_values[i] = f(list_of_points[i]) + noise -
domain- 定义 f 的 d-minsional 范围,因此list_of_points也在此域中。域可能是整个 R^d。
输出:domain 上 f 的全局最大值的点列表。
为了过滤噪声,我决定使用回归来估计 f,然后才寻找它的最大值点。
将以上内容总结为伪代码,我们得到:
def filter_noise_and_return_global_maxima(list_of_points, list_of_values, domain, degree_of_regression_polynomial):
f = polynomial_regression(list_of_points, list_of_values, degree = degree_of_regression_polynomial)
return f.global_maxima(domain)
现在我试图弄清楚如何做到这一点,但我找不到任何方法,特别是如果我希望代码在合理的时间内运行(考虑到维度 d 相当大)。
对于多项式回归,我在网上找到了以下内容:
from sklearn.preprocessing import PolynomialFeatures
from sklearn import linear_model
X = [[0.44, 0.68], [0.99, 0.23]]
vector = [109.85, 155.72]
predict= [0.49, 0.18]
poly = PolynomialFeatures(degree=2)
X_ = poly.fit_transform(X)
predict_ = poly.fit_transform(predict)
clf = linear_model.LinearRegression()
clf.fit(X_, vector)
print(clf.predict(predict_))
但不幸的是,这会引发错误。另外,我不确定如何生成下面使用的 sympy 的多项式。
最后,为了找到全局最大值,我发现了这个:
from sympy.calculus.util import *
x = symbols('x')
f = (x**3 / 3) - (2 * x**2) - 3 * x + 1
print(minimum(f, x, ivl))
print(maximum(f, x, ivl))
print(stationary_points(f, x, ivl))
但我不确定选择符号计算是否是一个好的选择,因为我处理的是大尺寸,而且我也没有意识到如何将它用于多变量情况。例如,以下不起作用f = x[0]**2+ 2*x[1]。
【问题讨论】:
-
您的数据集上是否有 y 或因变量?或者您只有 x 或自变量(训练和测试)?如果你没有 y,那么你就不能适应。
-
是的,当然。我编辑了我的问题以强调这一点
-
你能在
list_of_points中给一个样品吗? -
list_of_points=[[1,2,3.2],[2,4.2, 5.1], [-1,0.1, 0.9]] list_of_values=[4,5,6], domain=[[-10,10], [-10,10], [-10, 10]]#-10<=x,y,z<=10, degree_of_regression_polynomial=1 -
p1=[1,2,3.2], p2=[2,4.2, 5.1], p3=[-1,0.1, 0.9]对应的值分别为 4、5、6。这是正确的吗?我们将创建一个适合这些值的模型。从给定的具有维度 3 的 p1 加上它的值,我们现在正在处理 4D 数据,对吗?Output: list of points that are global maxima of f on domain.到底是什么意思,是不是说我们建好模型后,会搜索最大值的点?
标签: python machine-learning optimization regression