Created
March 5, 2019 19:45
-
-
Save gavincangan/927ba96493b97c45a17a2296604d313a to your computer and use it in GitHub Desktop.
Check whether a kernel results in a positive semi-definite covariance matrix using rejection sampling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% https://stats.stackexchange.com/a/394487/204863 | |
clear; close all; | |
num_points = 100; | |
xrange = [-100, 100]; | |
x = xrange(1) + 2 * xrange(2) * rand(num_points, 1); | |
yrange = [0, 20]; | |
y = yrange(1) + 2 * yrange(2) * rand(num_points, 1); | |
lambda = 1e3; | |
cov = zeros(num_points); | |
for i = 1:num_points | |
for j = 1:num_points | |
% term1 = (x(i)-x(j))^2; | |
% term2 = 1 + y(i) * y(j); | |
cov(i, j) = ((2*y(i))/(y(i).^2+1))^(3/2) .* exp(-1 * ( (x(i)^2 + (y(i))^2) ) ./ ( y(i)^2 + 1 ) ); | |
end | |
end | |
eval = eig(cov); | |
min(eval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment