summaryrefslogtreecommitdiff
path: root/run_tests.m
blob: 71bd07e0b41a64b91188def68efe2f3df9ce9430 (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
[pall, q] = get_products();

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

p = pall([1:28 29:42], :);
train_data = q([1:28], :);
real_data  = q([29:42], :);

m = @(n,f) struct('name', n, 'func', f );
pred_methods = [
	m('mean',     @mean_pred)
	m('regress',  @(p,q) regress_pred(p, q, 1, @(x)x))
	m('quad',     @(p,q) regress_pred(p, q, 2, @(x)x))
	m('log reg.', @(p,q) regress_pred(p, q, 1, @log))
	m('sevenday', @sevenday_pred)
%	m('norm rand.',@rand_pred)
%	m('chi rand.',@chi_pred)
	m('regress2', @regress_frequency_removal)
%	m('reg 7day', @(p,q) regress_interval_pred(p, q, 7))
];
num_methods = size(pred_methods, 1);

pred_list = {};
for i = 1:num_methods
	pred_list{i} = pred_methods(i).func(p, train_data);
end

qerr = terr = zeros(1, num_methods);
err  = zeros(num_methods, size(real_data,2));
for i = 1:num_methods
	[qerr(i), terr(i), err(i, :)] = calc_error(pred_methods(i).name, real_data, pred_list{i});
end

method_idx = opt_idx(real_data, pred_list);
opt_data = opt_pred(method_idx, pred_list);
[qerr(end+1), terr(end+1), opt_err] = calc_error('optimize', real_data, opt_data);

%bar(qerr);
%bar(terr);

[min_err, err_idx] = min(err);
printf('global min. error: %d\n', sum(min_err));
printf('local min count:');
local_min_count=zeros(1, size(err, 1));
for i=1:size(err,1)
	local_min_count(i) = sum(sum(err_idx == i));
	printf(' %d', local_min_count(i));
end
printf('\n');