summaryrefslogtreecommitdiff
path: root/run_tests.m
blob: 836a3fee1a654bda545c6b610aeaefc154d47b16 (plain)
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
[p, q] = get_products();

% quantity sum over a day
%plot(sum(q'));

train_data = q( 1:28, :);
real_data  = q(29:42, :);

mean_data	= mean_pred(train_data, 14);
regress_data	= regress_pred(p, train_data);
quad_data	= quad_regress_pred(p, train_data);
log_data	= log_regress_pred(p, train_data);
lq_data		= [log_data(:,1:334) quad_data(:,335) log_data(:,336:570)];
sevenday_data	= repmat(sevenday_pred(train_data, 4), 2, 1);
random_data	= rand_pred(train_data, 14);

% plot prediction quallity
[meqerr, meterr] = calc_error('mean',	  real_data, mean_data);
[reqerr, reterr] = calc_error('regress',  real_data, regress_data);
% quadratic just for reference, it sucks more than mean-predicition
[quqerr, quterr] = calc_error('quad reg.',real_data, quad_data);
[loqerr, loterr] = calc_error('log reg.', real_data, log_data);
[lqqerr, lqterr] = calc_error('l&q reg.', real_data, lq_data);
[seqerr, seterr] = calc_error('sevenday', real_data, sevenday_data);
[raqerr, raterr] = calc_error('random',	  real_data, random_data);

qerr = [meqerr reqerr quqerr loqerr lqqerr seqerr raqerr];
terr = [meterr reterr quterr loterr lqterr seterr raterr];
bar(qerr);
bar(terr);

mean_err	= sum(abs(real_data - mean_data));
regress_err	= sum(abs(real_data - regress_data));
quad_err	= sum(abs(real_data - quad_data));
log_err		= sum(abs(real_data - log_data));
lq_err		= sum(abs(real_data - lq_data));
sevenday_err	= sum(abs(real_data - sevenday_data));
random_err	= sum(abs(real_data - random_data));

err = [mean_err;regress_err;quad_err;log_err;lq_err;sevenday_err;random_err];
min_err = sum(min(err));
printf('global min. error: %d\n', min_err);

[q2, removed] = remove_sevenday_frequency(q(1:14, :));
tmp = regress_pred(p([1:14 29:42],:), q2);
tmp = fft(tmp);
%tmp = (tmp .* (removed == 0)) + removed;
tmp = tmp + removed;
tmp = real(ifft(tmp));
calc_error('regress2', q(29:42, :), tmp);