summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-05-12 15:04:03 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-05-12 15:04:46 +0200
commitc44e670ebbb1e1690398ac2837e5e79e17a19c7b (patch)
treea5f2f8f762422f4885d9d33126901ab084b48717
parenta5ce7b1ab782d4948c0ec6605aaa8c9d35aa73c2 (diff)
downloaddmc-c44e670ebbb1e1690398ac2837e5e79e17a19c7b.tar.gz
dmc-c44e670ebbb1e1690398ac2837e5e79e17a19c7b.tar.bz2
dmc-c44e670ebbb1e1690398ac2837e5e79e17a19c7b.zip
Use polyval where appropriate
..instead of doing the polynom multiplication by hand.
-rw-r--r--log_regress_pred.m11
-rw-r--r--quad_regress_pred.m9
-rw-r--r--regress.m4
-rw-r--r--regress_pred.m4
4 files changed, 8 insertions, 20 deletions
diff --git a/log_regress_pred.m b/log_regress_pred.m
index 3c90441..e6cfe05 100644
--- a/log_regress_pred.m
+++ b/log_regress_pred.m
@@ -8,15 +8,8 @@ function pred = log_regress_pred(price, quantity)
pred = zeros(days, product_count);
for i = 1:product_count
- [a,b] = regress_log(price(test_set, i), quantity(test_set, i));
- pred(:, i) = a * log(price(pred_set, i)) + b;
+ ab = regress(log(price(test_set, i)), quantity(test_set, i));
+ pred(:, i) = polyval(ab, log(price(pred_set, i)));
end
endfunction
-
-
-function [a,b] = regress_log(x, y)
- ab = [ log(x) ones(length(x), 1) ] \ y;
- a = ab(1);
- b = ab(2);;
-endfunction
diff --git a/quad_regress_pred.m b/quad_regress_pred.m
index aef8822..d9e3b6e 100644
--- a/quad_regress_pred.m
+++ b/quad_regress_pred.m
@@ -8,16 +8,13 @@ function pred = quad_regress_pred(price, quantity)
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;
+ abc = regress2(price(test_set, i), quantity(test_set, i));
+ pred(:, i) = polyval(abc, price(pred_set, i));
end
endfunction
-function [a,b,c] = regress2(x, y)
+function abc = 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/regress.m b/regress.m
index 5a7336b..ad06796 100644
--- a/regress.m
+++ b/regress.m
@@ -1,6 +1,4 @@
-function [m, n] = regress(x, y)
+function mn = regress(x, y)
mn = [ x ones(length(x), 1) ] \ y;
- m = mn(1);
- n = mn(2);
endfunction
diff --git a/regress_pred.m b/regress_pred.m
index 0c66b1e..2992471 100644
--- a/regress_pred.m
+++ b/regress_pred.m
@@ -8,8 +8,8 @@ function pred = regress_pred(price, quantity)
pred = zeros(days, product_count);
for i = 1:product_count
- [m,n] = regress(price(test_set, i), quantity(test_set, i));
- pred(:, i) = m .* price(pred_set, i) + n;
+ mn = regress(price(test_set, i), quantity(test_set, i));
+ pred(:, i) = polyval(mn, price(pred_set, i));
end
endfunction