-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplekernels.cpp
More file actions
181 lines (142 loc) · 4.67 KB
/
Copy pathsimplekernels.cpp
File metadata and controls
181 lines (142 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* 1d undifferentiated kernels
*
*
*/
#include <vector>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
const double PI = 3.14159265359;
const double OVERPI = 0.31830988618;
const double FIVETHIRDS = 5./3.;
const double SQRT5 = sqrt(5.);
int mat52perconv(double *h, int D, double* ih){
ih[0] = pow(h[0],2);
ih[1] = 1./h[1];
ih[2] = h[2];
return 0;
}
//all are searched in log space
int mat52persearchconv(double *h, int D, double* ih){
ih[0] = pow(10.,h[0]);
ih[1] = pow(10.,h[1]);
ih[2] = pow(10.,h[2]);
return 0;
}
double mat52per(double *x1, double *x2, int d1, int d2, int D, double* ih, double* smodel){
//strictly 1d kernel
//A mat52( sin2(2pix/p) )
//ihyps outputscale**2,1/lengthscale,period
if (d1!=0 or d2!=0 or D!=1){
printf("no derivatives for this kernel, D must be 1 %d %d %d",d1,d2,D);
return 0.;
}
//double r = abs(ih[2]*ih[1]*OVERPI*sin(PI*(x1[0]-x2[0])/ih[2]));
double r = fabs(double(ih[2]*ih[1]*OVERPI*sin(PI*(x1[0]-x2[0])/ih[2])));
return ih[0]*(1.+SQRT5*r+FIVETHIRDS*pow(r,2))*exp(-SQRT5*r);
}
int mat52pptconv(double *h, int D, double* ih){
ih[0] = pow(h[0],2);
ih[1] = 1./h[1];
ih[2] = h[2];
ih[3] = 1./pow(h[3],2);
return 0;
}
//all are searched in log space
int mat52pptsearchconv(double *h, int D, double* ih){
ih[0] = pow(10.,h[0]);//mat52( sin2(2pix/p) )
ih[1] = pow(10.,h[1]);
ih[2] = pow(10.,h[2]);
ih[3] = pow(10.,h[3]);
return 0;
}
double mat52ppt(double *x1, double *x2, int d1, int d2, int D, double* ih, double* smodel){
//strictly 1d kernel
//A mat52( sin2(2pix/p) )*squexp
//ihyps outputscale**2,1/lengthscale,period,1/decay**2
if (d1!=0 or d2!=0 or D!=1){
printf("no derivatives for this kernel, D must be 1 %d %d %d",d1,d2,D);
return 0.;
}
double dx = x1[0]-x2[0];
//double r = abs(ih[2]*ih[1]*OVERPI*sin(PI*(x1[0]-x2[0])/ih[2]));
double r = fabs(double(ih[2]*ih[1]*OVERPI*sin(PI*dx/ih[2])));
return ih[0]*(1.+SQRT5*r+FIVETHIRDS*pow(r,2))*exp(-SQRT5*r)*exp(-0.5*pow(dx,2)*ih[3]);
}
int matppconv(double *h, int D, double* ih){
ih[0] = pow(h[0],2);
ih[1] = 1./h[1];
ih[2] = h[2];
ih[3] = pow(h[3],2);
ih[4] = 1./h[4];
//ih[6] = pow(h[6],2);
//ih[7] = 1./h[7];
return 0;
}
//all are searched in log space
int matppsearchconv(double *h, int D, double* ih){
ih[0] = pow(10.,h[0]);
ih[1] = pow(10.,h[1]);
ih[2] = pow(10.,h[2]);
ih[3] = pow(10.,h[3]);
ih[4] = pow(10.,h[4]);
return 0;
}
double matpp(double *x1, double *x2, int d1, int d2, int D, double* ih, double* smodel){
//strictly 1d kernel
//A mat52( sin2(2pix/p) )*squexp
//ihyps outputscale**2,1/lengthscale,period,1/decay**2
if (d1!=0 or d2!=0 or D!=1){
printf("no derivatives for this kernel, D must be 1 %d %d %d",d1,d2,D);
return 0.;
}
double dx = x1[0]-x2[0];
double r1 = fabs(double(ih[2]*ih[1]*OVERPI*sin(PI*dx/ih[2])));
double mp1 = ih[0]*(1.+SQRT5*r1+FIVETHIRDS*pow(r1,2))*exp(-SQRT5*r1);
double r3 = fabs(dx*ih[4]);
double mm = ih[3]*(1.+SQRT5*r3+FIVETHIRDS*pow(r3,2))*exp(-SQRT5*r3);
return mp1+mm;
}
int devconv(double *h, int D, double* ih){
ih[0] = pow(h[0],2);
ih[1] = 1./h[1];
ih[2] = h[2];
ih[3] = pow(h[3],2);
ih[4] = 1./h[4];
ih[5] = h[5];
ih[6] = pow(h[6],2);
ih[7] = 1./h[7];
//ih[6] = pow(h[6],2);
//ih[7] = 1./h[7];
return 0;
}
//all are searched in log space
int devsearchconv(double *h, int D, double* ih){
ih[0] = pow(10.,h[0]);
ih[1] = pow(10.,h[1]);
ih[2] = pow(10.,h[2]);
ih[3] = pow(10.,h[3]);
ih[4] = pow(10.,h[4]);
ih[5] = pow(10.,h[5]);
ih[6] = pow(10.,h[4]);
ih[7] = pow(10.,h[5]);
return 0;
}
double dev(double *x1, double *x2, int d1, int d2, int D, double* ih, double* smodel){
//strictly 1d kernel
//A mat52( sin2(2pix/p) )*squexp
//ihyps outputscale**2,1/lengthscale,period,1/decay**2
if (d1!=0 or d2!=0 or D!=1){
printf("no derivatives for this kernel, D must be 1 %d %d %d",d1,d2,D);
return 0.;
}
double dx = x1[0]-x2[0];
double r1 = fabs(double(ih[2]*ih[1]*OVERPI*sin(PI*dx/ih[2])));
double mp1 = ih[0]*(1.+SQRT5*r1+FIVETHIRDS*pow(r1,2))*exp(-SQRT5*r1);
double r2 = fabs(double(ih[5]*ih[4]*OVERPI*sin(PI*dx/ih[5])));
double mp2 = ih[3]*(1.+SQRT5*r2+FIVETHIRDS*pow(r2,2))*exp(-SQRT5*r2);
double r3 = fabs(dx*ih[7]);
double mm = ih[6]*(1.+SQRT5*r3+FIVETHIRDS*pow(r3,2))*exp(-SQRT5*r3);
return mp1+mp2+mm;
}