我使用scikit-learn拟合高斯过程回归。 (我的实际上是一个简单的一维案例)
#include <stdio.h>
struct rettype {
int start;
int end;
int sum;
};
struct rettype max_subarray(int array[], int length);
int main(void){
int array[20];
int len = 0, num;
struct rettype ret;
printf("Type length in.\n");
if(scanf("%d", &len) != 1){
printf("invalid input.\n");
return 1;
}
if(len > 20){
printf("too long.\n");
return 2;
}
for(num = 0; num < len; num++){
printf("%dth element: ", num);
if(scanf("%d", &array[num]) != 1){
printf("invalid input.\n");
len = num;
break;
}
}
if(len > 0){
ret = max_subarray(array, len);
printf("Maximum Subarray:\nfrom element %d to element %d with sum of %d\n", ret.start, ret.end, ret.sum);
}
return 0;
}
struct rettype max_subarray(int array[], int length){
struct rettype ret = { .sum = array[0] };
struct rettype curr = { .sum = array[0] };
for(int i = 1; i < length; ++i){
if(array[i] < array[i] + curr.sum){
curr.sum += array[i];
curr.end = i;
} else {
curr.sum = array[i];
curr.start = curr.end = i;
}
if(ret.sum < curr.sum){
ret = curr;
}
}
return ret;
}
一旦这个模型适合,我想计算另一个数据集(from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, WhiteKernel
import numpy as np
# Some example data
x = np.linspace(0,10,100)
y = np.sin(x) + np.random.normal(0, 0.1, x.shape)
# Fitting the model
some_kernel = RBF() + WhiteKernel()
gpr = GaussianProcessRegressor(kernel=some_kernel)
gpr.fit(x[:, None], y)
)在这个拟合模型下的概率。例如y1
。
一种非常天真的方式。
P(y1|GP_fit_on_y)
但这不会考虑GP的协方差结构。关于如何做的任何想法?