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

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

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',  @regress_pred)
	m('quad',     @quad_regress_pred)
	m('log reg.', @log_regress_pred)
	m('sevenday', @sevenday_pred)
	m('random',   @rand_pred)
	m('regress2', @regress_frequency_removal)
];
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

opt_data = opt_pred(real_data, 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');