summaryrefslogtreecommitdiff
path: root/quad_regress_pred.m
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-05-10 12:28:53 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-05-10 12:30:30 +0200
commit22f962928280a8af26e500fedad29fc12024b45a (patch)
tree2e4c0f8977f905000268f28edb4b0713cf2c40bc /quad_regress_pred.m
parentd0b29ac2f35923e05deda5dbe1856f04911c55bf (diff)
downloaddmc-22f962928280a8af26e500fedad29fc12024b45a.tar.gz
dmc-22f962928280a8af26e500fedad29fc12024b45a.tar.bz2
dmc-22f962928280a8af26e500fedad29fc12024b45a.zip
Add quadratic interterpolation
Not usable at all, worse than mean value.
Diffstat (limited to 'quad_regress_pred.m')
-rw-r--r--quad_regress_pred.m23
1 files changed, 23 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