-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexp1d.cpp
50 lines (41 loc) · 1.29 KB
/
exp1d.cpp
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
#include "cutting_plane.hpp"
#include "ell.hpp"
#include <xtensor/xarray.hpp>
#include <xtensor/xrandom.hpp>
#include <xtensor-blas/xlinalg.hpp>
// #include <iostream>
#include <cmath>
int main() {
using xt::linalg::dot;
using Arr = xt::xarray<double, xt::layout_type::row_major>;
const auto n = 4u; // number of points
const auto s_begin = 1U;
const auto s_end = 10u;
const auto sdkern = 0.5; // width of kernel
const auto var = 2.; // standard derivation
const auto N = 500u; // number of samples
// auto dist = s_end - s_begin;
Arr s = xt::linspace(s_begin, s_end, n);
//shape_type shape = {n, n};
Arr Sig = xt::ones<double>({n, n});
for (auto i = 0; i != n; ++i) {
for (auto j = i+1; j != n; ++j) {
const auto d = s[j] - s[i];
Sig(i, j) = std::exp(-0.5*(d*d)/(sdkern*sdkern)/2);
Sig(j, i) = Sig(i,j);
}
}
Arr A = xt::linalg::cholesky(Sig);
Arr Ys = zeros({n, N});
Arr ym = xt::random::randn<double>({n});
for (auto k = 0; k != N; ++k) {
Arr x = var * xt::random::randn<double>({n});
Arr y = dot(A,x) + ym + 0.5*xt::random::randn<double>({n});
xt::view(Ys, xt::all(), k) = y;
}
Arr Ys_T = xt::transpose(Ys);
Arr Y = dot(Ys, Ys_T);
Y *= 1./N;
//auto Y = xt::cov(Ys, bias=True);
// std::cout << Y << std::endl;
}