我试图在R中的以下代码中匹配正交多项式:
X <- cbind(1, poly(x = x, degree = 9))
Run Code Online (Sandbox Code Playgroud)
但是在python中.
为此,我实现了自己的方法来给出正交多项式:
def get_hermite_poly(x,degree):
#scipy.special.hermite()
N, = x.shape
##
X = np.zeros( (N,degree+1) )
for n in range(N):
for deg in range(degree+1):
X[n,deg] = hermite( n=deg, z=float(x[deg]) )
return X
Run Code Online (Sandbox Code Playgroud)
虽然它似乎不匹配它.有人知道它使用的正交多项式的类型吗?我尝试在文档中搜索但没有说.
为了给出一些上下文,我试图在python中实现以下R代码(https://stats.stackexchange.com/questions/313265/issue-with-convergence-with-sgd-with-function-approximation-using-polynomial- lin/315185#comment602020_315185):
set.seed(1234)
N <- 10
x <- seq(from = 0, to = 1, length = N)
mu <- sin(2 * pi * x * 4)
y <- mu
plot(x,y)
X <- cbind(1, poly(x = x, degree …Run Code Online (Sandbox Code Playgroud) R poly()函数产生用于数据拟合的正交多项式.但是,我想使用R之外的回归结果(比如在C++中),并且似乎没有办法获得每个正交多项式的系数.
注1:我不是指回归系数,而是正交多项式本身的系数),例如p_i(x)in
y = a0 + a1*p_1(x) + a2*p_2(x) + ...
Run Code Online (Sandbox Code Playgroud)
注2:我知道poly(x, n, raw=T)强制多边形来返回非正交多项式,但我想对正交多项式进行回归,这就是我正在寻找的东西.