2014-07-21 2 views
0

포인트가 정렬되지 않은 데이터 세트에서 외삽 법을 적용하는 방법에 대해 머리를 감싸고 있지 않습니다. 즉, 'x'에 대해 감소 할 것입니다. 과 같이 :굴곡 된 데이터 포인트에서 외삽하기

http://www.pic-host.org/images/2014/07/21/0b5ad6a11266f549.png

나는 별도로 x와 y 값에 대한 그래프를 만들 필요가 있어요. 그래서 나에게 이것을 얻는 코드 :

x = bananax 
y = bananay 

t = np.arange(x.shape[0], dtype=float) 
t /= t[-1] 
nt = np.linspace(0, 1, 100) 

x1 = scipy.interpolate.spline(t, x, nt) 
y1 = scipy.interpolate.spline(t, y, nt) 

plt.plot(nt, x1, label='data x') 
plt.plot(nt, y1, label='data y') 

이제 보간 된 스플라인을 얻었습니다. 나는 f (nt) = x1 및 f (nt) = y1에 대해 외삽 법을 수행해야한다고 생각한다. 간단한 선형 회귀를 사용하여 데이터를 보간하는 방법을 얻었지만 더 복잡한 스플라인 (?)을 얻는 방법을 놓치고 있습니다. 목표는 외삽 된 함수가 데이터 점의 곡률을 따르도록하는 것입니다. (적어도 한쪽 끝에서)

환호와 감사합니다!

답변

0

덕분에이 바른 길에 저를 얻었다 . 나를 위해 일한 것은 다음과 같습니다 :

x = bananax 
y = bananay 

#------ fit a spline to the coordinates, x and y axis are interpolated towards t 
t = np.arange(x.shape[0], dtype=float) #t is # of values 
t /= t[-1] #t is now devided from 0 to 1 
nt = np.linspace(0, 1, 100) #nt is array with values from 0 to 1 with 100 intermediate values 

x1 = scipy.interpolate.spline(t, x, nt) #The x values where spline should estimate the y values 
y1 = scipy.interpolate.spline(t, y, nt) 

#------ create a new linear space for nnt in which an extrapolation from the interpolated spline will be made 
nnt = np.linspace(-1, 1, 100) #values <0 are extrapolated (interpolation started at the tip(=0) 

x1fit = np.polyfit(nt,x1,3) #fits a polynomial function of the nth order with the spline as input, output are the function parameters 
y1fit = np.polyfit(nt,y1,3) 

xpoly = np.poly1d(x1fit) #genereates the function based on the parameters obtained by polyfit 
ypoly = np.poly1d(y1fit) 
0

포인트가 정렬되어 있기 때문에 파라 메트릭 커브 (x (t) 및 y (t) 생성)가 생성된다는 점에서 올바른 방향이라고 생각합니다. 문제의 한 부분은 spline 함수가 스플라인의 형식 및 매개 변수가 아닌 개별 값을 돌려주는 것 같습니다. scipy.optimize에는 점을 계산하는 대신 함수를 찾는 데 도움이되는 유용한 도구가 있습니다.

데이터를 생성하는 기본 프로세스에 대한 통찰력이 있다면 해당 함수를 사용하여 피팅 함수를 선택하는 것이 좋습니다. 이보다 더 자유로운 형식의 메소드는 유연성을 제공합니다.

x (t)와 y (t)를 맞추고 결과 피팅 함수를 유지합니다. 그들은 t=0에서 t=1까지의 데이터로 생성되지만 아무 것도 * 해당 범위를 벗어나는 수치는 평가하지 않습니다.

나는 커브 피팅 절차에 대한 안내는 다음 링크를 추천 할 수 있습니다 :

짧은 : http://glowingpython.blogspot.com/2011/05/curve-fitting-using-fmin.html

긴 : http://nbviewer.ipython.org/gist/keflavich/4042018

* 거의 아무것도