-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_approximation.m
25 lines (19 loc) · 973 Bytes
/
run_approximation.m
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
function [miseError,f_approx] = run_approximation(f,M,x_j,lambda,d,gamma,alpha)
%run a 'simulation' of estimating the density function f and compute the
%MISE error, repeat the simulation until the averaged MISE error is accurate
%enough
if(class(f) == "func_interpolation") %if f is of type func_interpolation then convert it into a function handle
fTable = f.dataTable;
f = @(x) f.interpolate(x);
end
S = 1;
miseError = 0;
while(length(miseError) == 1 || sqrt(var(miseError)/S)*2 > 0.1*mean(miseError)) %repeat simulating until the standard deviation of the averaged mise error satisfies 2*sigma > 0.1 * E(MISE)
%Generate samples, compute estimator, and calculate MISE error
display("Running Iteration: #" + num2str(S));
Y = generateSamp(f,[0,1],M,d,x_j);
[f_approx,~] = approximate_density(Y,x_j,gamma,alpha,lambda);
miseError(S) = mise(f,f_approx,x_j,d);
S = S + 1;
end
miseError = mean(miseError);