-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
32 lines (25 loc) · 803 Bytes
/
main.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
26
27
28
29
30
31
32
% This script runs a cross validation simulation
% Example Constants
% Size of the sample (number of x and y columns)
SAMPLE_SIZE = 2000;
% Degree of Generator
DEGREE = 4;
% Degrees of fitted polynomials
MODEL_PARAMETERS = 3:7;
% Number k of folds (leave one out: SAMPLE_SIZE - 1)
FOLDS = [2:10, 20, 30];
% Don't make this much larger
NOISE = 0.2;
% Create a random polynomial
polynomial = (rand(DEGREE + 1, 1) - 0.5);
% Generate dataset
[y, x] = generateData(polynomial, SAMPLE_SIZE);
% Generate noise
y = y + (rand(SAMPLE_SIZE, 1) - 0.5) * ((max(y) - min(y)) * NOISE);
% Run simulation
% we fit a polynoial model to the data
rmse = crossVal(x, y, @polyfit, @polyval, MODEL_PARAMETERS, FOLDS);
% Print rmse
rmse
% Draw plot
plotSim(rmse, MODEL_PARAMETERS, FOLDS)