summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quad_regress_pred.m20
-rw-r--r--regress.m7
-rw-r--r--regress_frequency_removal.m2
-rw-r--r--regress_pred.m4
-rw-r--r--run_tests.m6
5 files changed, 10 insertions, 29 deletions
diff --git a/quad_regress_pred.m b/quad_regress_pred.m
deleted file mode 100644
index d9e3b6e..0000000
--- a/quad_regress_pred.m
+++ /dev/null
@@ -1,20 +0,0 @@
-function pred = quad_regress_pred(price, quantity)
-
- days = size(price, 1) - size(quantity, 1);
- product_count = size(price, 2);
- test_count = size(quantity, 1);
- test_set = 1:test_count;
- pred_set = test_count+1:size(price, 1);
-
- pred = zeros(days, product_count);
- for i = 1:product_count
- abc = regress2(price(test_set, i), quantity(test_set, i));
- pred(:, i) = polyval(abc, price(pred_set, i));
- end
-
-endfunction
-
-
-function abc = regress2(x, y)
- abc = [ x.^2 x ones(length(x), 1) ] \ y;
-endfunction
diff --git a/regress.m b/regress.m
index ad06796..4d13c62 100644
--- a/regress.m
+++ b/regress.m
@@ -1,4 +1,5 @@
-function mn = regress(x, y)
- mn = [ x ones(length(x), 1) ] \ y;
+function polynom = regress(x, y, degree)
+ pot = @(x) x.^[degree:-1:0];
+ M = reshape(cell2mat(arrayfun(pot, x(:)', 'UniformOutput', false)), degree+1, [])';
+ polynom = M \ y(:);
endfunction
-
diff --git a/regress_frequency_removal.m b/regress_frequency_removal.m
index 4b7624b..a60d93a 100644
--- a/regress_frequency_removal.m
+++ b/regress_frequency_removal.m
@@ -7,7 +7,7 @@ function pred = regress_frequency_removal(price, quantity)
pred_set = size(quantity, 1)+1:size(price, 1);
[q2, removed] = remove_sevenday_frequency(quantity(test_set, :));
- pred = regress_pred(price([test_set pred_set],:), q2, @(x)x);
+ pred = regress_pred(price([test_set pred_set],:), q2, 1, @(x)x);
pred = fft(pred);
%pred = (pred .* (removed == 0)) + removed;
pred = pred + removed;
diff --git a/regress_pred.m b/regress_pred.m
index 119738c..8788bee 100644
--- a/regress_pred.m
+++ b/regress_pred.m
@@ -1,4 +1,4 @@
-function pred = regress_pred(price, quantity, prefunc)
+function pred = regress_pred(price, quantity, degree, prefunc)
days = size(price, 1) - size(quantity, 1);
product_count = size(price, 2);
@@ -8,7 +8,7 @@ function pred = regress_pred(price, quantity, prefunc)
pred = zeros(days, product_count);
for i = 1:product_count
- mn = regress(prefunc(price(test_set, i)), quantity(test_set, i));
+ mn = regress(prefunc(price(test_set, i)), quantity(test_set, i), degree);
pred(:, i) = polyval(mn, prefunc(price(pred_set, i)));
end
diff --git a/run_tests.m b/run_tests.m
index 3ef7aeb..34a758f 100644
--- a/run_tests.m
+++ b/run_tests.m
@@ -10,9 +10,9 @@ 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, @(x)x))
- m('quad', @quad_regress_pred)
- m('log reg.', @(p,q) regress_pred(p, q, @log))
+ 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)