From 0f6d90832f1c436a804f847c769a28b544995812 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Fri, 11 May 2012 11:49:42 +0200 Subject: run_tests: Use an vector of structs for the prediction methods Allows use to use e.g. pred_methods.name. --- run_tests.m | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/run_tests.m b/run_tests.m index 57cb722..da1f7d9 100644 --- a/run_tests.m +++ b/run_tests.m @@ -6,26 +6,26 @@ train_data = q( 1:28, :); real_data = q(29:42, :); -pred_methods = { - { 'mean', @mean_pred }, - { 'regress', @regress_pred }, - { 'quad', @quad_regress_pred }, - { 'log reg.', @log_regress_pred }, - { 'sevenday' @sevenday_pred }, - { 'random' @rand_pred }, - { 'regress2' @regress_frequency_removal } -}; +pred_methods = [ + struct('name', 'mean', 'func', @mean_pred ) + struct('name', 'regress', 'func', @regress_pred ) + struct('name', 'quad', 'func', @quad_regress_pred ) + struct('name', 'log reg.', 'func', @log_regress_pred ) + struct('name', 'sevenday', 'func', @sevenday_pred ) + struct('name', 'random', 'func', @rand_pred ) + struct('name', 'regress2', 'func', @regress_frequency_removal ) +]; num_methods = size(pred_methods, 1); pred_list = {}; for i = 1:num_methods - pred_list{i} = pred_methods{i}{2}(p, train_data); + 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}{1}, real_data, pred_list{i}); + [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); -- cgit