diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-05-10 12:28:53 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-05-10 12:30:30 +0200 |
commit | 22f962928280a8af26e500fedad29fc12024b45a (patch) | |
tree | 2e4c0f8977f905000268f28edb4b0713cf2c40bc | |
parent | d0b29ac2f35923e05deda5dbe1856f04911c55bf (diff) | |
download | dmc-22f962928280a8af26e500fedad29fc12024b45a.tar.gz dmc-22f962928280a8af26e500fedad29fc12024b45a.tar.bz2 dmc-22f962928280a8af26e500fedad29fc12024b45a.zip |
Add quadratic interterpolation
Not usable at all, worse than mean value.
-rw-r--r-- | quad_regress_pred.m | 23 | ||||
-rw-r--r-- | run_tests.m | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/quad_regress_pred.m b/quad_regress_pred.m new file mode 100644 index 0000000..aef8822 --- /dev/null +++ b/quad_regress_pred.m @@ -0,0 +1,23 @@ +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 + [a,b,c] = regress2(price(test_set, i), quantity(test_set, i)); + pred(:, i) = a .* price(pred_set, i).^2 + b * price(pred_set, i) + c; + end + +endfunction + + +function [a,b,c] = regress2(x, y) + abc = [ x.^2 x ones(length(x), 1) ] \ y; + a = abc(1); + b = abc(2); + c = abc(3); +endfunction diff --git a/run_tests.m b/run_tests.m index b7b1a83..358c6dc 100644 --- a/run_tests.m +++ b/run_tests.m @@ -6,6 +6,8 @@ % plot prediction quallity calc_error('mean', q(29:42, :), mean_pred(q(1:28, :), 14)); calc_error('regress', q(29:42, :), regress_pred(p, q(1:28, :))); +% quadratic just for reference, it sucks more than mean-predicition +calc_error('quad regress', q(29:42, :), quad_regress_pred(p, q(1:28, :))); calc_error('log regress', q(29:42, :), log_regress_pred(p, q(1:28, :))); calc_error('sevenday', q(29:42, :), repmat(sevenday_pred(q(1:28, :), 4), 2, 1)); calc_error('random', q(29:42, :), rand_pred(q(1:28, :), 14)); |