From 7cf32b95e5090e97fb7502240d046369cc28293f Mon Sep 17 00:00:00 2001 From: Dorai Sitaram Date: Fri, 17 May 2024 10:03:23 -0400 Subject: [PATCH] multiple-regression(): first arg is now a list of N-tuples (each N-tuple representing one input (setting of indep vars to values). The returned predictor fn also takes an N-tuple #1732 --- src/js/trove/multiple-regression.js | 8 ++++---- tests/pyret/tests/test-statistics.arr | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/js/trove/multiple-regression.js b/src/js/trove/multiple-regression.js index ae9300fa8..1484e1279 100644 --- a/src/js/trove/multiple-regression.js +++ b/src/js/trove/multiple-regression.js @@ -132,8 +132,8 @@ let Y = new Array(num_mappings); let x_s_len = false; js_x_s_s.forEach(function(x_s, i) { - runtime.checkList(x_s); - let js_x_s = runtime.ffi.toArray(x_s); + runtime.checkTuple(x_s); + let js_x_s = x_s.vals; let x_s_n = js_x_s.length; if (x_s_len === false) { x_s_len = x_s_n; @@ -156,8 +156,8 @@ let XT = matrixTranspose(X); let B = matrixMultiply2(matrixInverse(matrixMultiply2(XT, X)), matrixMultiply2(XT, Y)); let Bfunc = function(x_s) { - runtime.checkList(x_s); - let js_x_s = runtime.ffi.toArray(x_s); + runtime.checkTuple(x_s); + let js_x_s = x_s.vals; if (js_x_s.length !== x_s_len) { throw runtime.ffi.throwMessageException("predictor: wrong number of arguments"); } diff --git a/tests/pyret/tests/test-statistics.arr b/tests/pyret/tests/test-statistics.arr index 6d6f86441..b3c227376 100644 --- a/tests/pyret/tests/test-statistics.arr +++ b/tests/pyret/tests/test-statistics.arr @@ -114,10 +114,10 @@ check "linear regression": end check "multiple regression": - x-s-s = [list: [list: 4], [list: 4.5], [list: 5], [list: 5.5], [list: 6], [list: 6.5], [list: 7]] + x-s-s = [list: {4}, {4.5}, {5}, {5.5}, {6}, {6.5}, {7}] y-s = [list: 33, 42, 45, 51, 53, 61, 62] pf = multiple-regression(x-s-s, y-s) - pf([list: 8]) is%(within-abs(0.001)) 73.3214 + pf({8}) is%(within-abs(0.001)) 73.3214 end