-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrff_aproximation.m
More file actions
38 lines (30 loc) · 1.14 KB
/
rff_aproximation.m
File metadata and controls
38 lines (30 loc) · 1.14 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
% Sample script to compare Gaussian kernel Gram matrix with its RFF approximation
% Generate sample data
dim = 10; % Dimensionality of each data point
numData = 100; % Number of data points
X = randn(dim, numData); % Random data points
% Parameters for Gaussian kernel and RFF
sigma = 1; % Standard deviation for Gaussian kernel
D = 10000; % Number of random features for RFF approximation
% Compute the exact kernel Gram matrix
K_exact = cvtKernelGramMatrix(X, sigma);
% Compute the approximate kernel Gram matrix using RFF
K_approx = cvtKernelGramMatrixRFF(X, D, sigma);
% Comparison
% Compute the Frobenius norm of the difference between the exact and approximate matrices
error_norm = norm(K_exact - K_approx, 'fro');
% Compute the relative error in terms of Frobenius norm
relative_error = error_norm / norm(K_exact, 'fro');
% Display the results
fprintf('Error norm (Frobenius): %f\n', error_norm);
fprintf('Relative error: %f\n', relative_error);
% Visual comparison (Optional)
figure;
subplot(1,2,1);
imagesc(K_exact);
title('Exact Kernel Gram Matrix');
colorbar;
subplot(1,2,2);
imagesc(K_approx);
title('Approximate Kernel Gram Matrix (RFF)');
colorbar;