18 #include <dlib/matrix.h>
42 inline void evaluate1(
int i,
int j,
double *input_x,
double *output_y,
double *output_dy=0,
double *output_ddy=0,
double *output_dddy=0)
44 double local_x = (input_x[i]-
breaks[j]);
54 output_dddy[i]=6*
coef_1[j];
61 void evaluate(
int outN,
double *input_x,
double *output_y,
double *output_dy=0,
double *output_ddy=0,
double *output_dddy=0)
68 for (
int i=0;i<outN;i++)
74 if( j==N-1 || input_x[i]+
eps <
breaks[j+1] )
83 for (
int i=0;i<outN;i++)
85 evaluate1(i,localIndex[i],input_x,output_y,output_dy,output_ddy,output_dddy);
92 void evaluate_ordered(
int outN,
double *input_x,
double *output_y,
double *output_dy=0,
double *output_ddy=0,
double *output_dddy=0)
95 for (
int i=0;i<outN;i++)
97 while( j<N-1 && input_x[i] >
breaks[j+1] ) j++;
98 evaluate1(i,j,input_x,output_y,output_dy,output_ddy,output_dddy);
109 void fit(
double *input_x,
double *input_y,
double *input_w,
double smoothingFactor)
114 double oneDivDx[N-1];
119 for(
int i=0;i<N-1;i++){oneDivDx[i]=1.0/dx[i];}
124 double dx2x1n_20n_3[N-2];
127 for(
int i=0;i<N-2;i++){ dx2x1n_20n_3[i]=2*(dx1n_2[i]+dx0n_3[i]);}
130 double sp_dx1n_2 [(N-2)*(N-2)];
131 double sp_dx0n_3 [(N-2)*(N-2)];
132 double sp_dx2x1n_20n_3 [(N-2)*(N-2)];
137 double R[(N-2)*(N-2)];
138 for(
int i=0; i<N-2;i++)
140 for(
int j=0; j<N-2;j++)
142 R[i*(N-2)+j]=sp_dx1n_2[i*(N-2)+j]+sp_dx0n_3[i*(N-2)+j]+sp_dx2x1n_20n_3[i*(N-2)+j];
146 double oneDivDx1n_2[N-2];
147 double oneDivDx0n_3[N-2];
148 double oneDivDx_1n_20n_3[N-2];
152 for(
int i=0;i<N-2;i++){
153 oneDivDx_1n_20n_3[i]=-1*(oneDivDx1n_2[i]+oneDivDx0n_3[i]);}
156 double sp_oneDivDx1n_2[(N-2)*(N)];
157 double sp_oneDivDx0n_3[(N-2)*(N)];
158 double sp_oneDivDx_1n_20n_3[(N-2)*(N)];
164 double Qt[(N-2)*(N)];
165 double QtT[(N)*(N-2)];
167 for(
int i=0; i<N-2;i++)
169 for(
int j=0; j<N;j++)
171 Qt[i*(N)+j]=sp_oneDivDx1n_2[i*(N)+j]+sp_oneDivDx0n_3[i*(N)+j]+sp_oneDivDx_1n_20n_3[i*(N)+j];
179 double QtDQ[(N-2)*(N-2)];
181 for(
int i=0;i<N;i++) { D[i]=1.0/input_w[i];}
189 dlib::matrix<double> M(N-2,N-2);
190 dlib::matrix<double> inv_M;
191 for(
int i=0; i<(N-2);i++){
192 for(
int j=0; j<(N-2); j++){
193 M(i,j)=6*(1-smoothingFactor)*QtDQ[i*(N-2)+j]+smoothingFactor*R[i*(N-2)+j];
199 double temp_invM[(N-2)*(N-2)];
201 for(
int i=0; i<(N-2);i++)
203 for(
int j=0; j<(N-2); j++)
205 temp_invM[i*(N-2)+j]=inv_M(i,j);
209 double diff_DyDx[N-2];
212 double diff_u_n[N-1];
218 for(
int i=0; i<N-2; i++) {u_n[i+1]=u[i];}
222 double diff_u_n_oneDivDx [N-1];
223 double diff_unoneDivDx_n1[N+1];
224 double diff2_unoneDivDx_n1[N];
226 diff_unoneDivDx_n1[0]=0;
227 diff_unoneDivDx_n1[N]=0;
228 for(
int i=0; i<N-1; i++) {diff_unoneDivDx_n1[i+1]=diff_u_n_oneDivDx[i];}
233 for(
int i=0; i<N; i++)
235 yi[i]=input_y[i]-(6*(1-smoothingFactor))*sp_D[i*N+i]*diff2_unoneDivDx_n1[i];
248 for(
int i=0; i<N-2; i++) {c3[i+1]=u[i]*smoothingFactor;}
250 for(
int i=0; i<N-1; i++) {c2[i]=diff_yi[i]*oneDivDx[i]-dx[i]*(2*c3[i]+c3[i+1]);}
252 for(
int i=0; i<N-1; i++)
255 coef_1[i]=diff_c3[i]*oneDivDx[i];
260 breaks[N-1] = input_x [N-1];
Definition: cubicpiecewisefunctionstatic.h:33
void evaluate1(int i, int j, double *input_x, double *output_y, double *output_dy=0, double *output_ddy=0, double *output_dddy=0)
Definition: cubicpiecewisefunctionstatic.h:42
double coef_4[N-1]
Definition: cubicpiecewisefunctionstatic.h:39
void fit(double *input_x, double *input_y, double *input_w, double smoothingFactor)
Definition: cubicpiecewisefunctionstatic.h:109
double breaks[N]
Definition: cubicpiecewisefunctionstatic.h:35
double coef_1[N-1]
Definition: cubicpiecewisefunctionstatic.h:36
double coef_2[N-1]
Definition: cubicpiecewisefunctionstatic.h:37
void evaluate_ordered(int outN, double *input_x, double *output_y, double *output_dy=0, double *output_ddy=0, double *output_dddy=0)
Definition: cubicpiecewisefunctionstatic.h:92
void evaluate(int outN, double *input_x, double *output_y, double *output_dy=0, double *output_ddy=0, double *output_dddy=0)
Definition: cubicpiecewisefunctionstatic.h:61
double coef_3[N-1]
Definition: cubicpiecewisefunctionstatic.h:38
const double inf
Definition: cubic_piecewise_function.cpp:17
const double eps
Definition: cubic_piecewise_function.cpp:16
Definition: areaofeffectconverter.h:20