Implement preliminary GDT linear model function - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/gdt-plot.lua
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年12月17日 17:37:36 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年12月17日 17:37:36 +0100
commitc912cffd0e942d77f998488f7b7746d0aa30f052 (patch)
tree1df71f6f82157ce82c3a287ac8a8fc813f411adb /gdt-plot.lua
parent38bac83e37c24e5be164edad90650076247b2717 (diff)
downloadgsl-shell-c912cffd0e942d77f998488f7b7746d0aa30f052.tar.gz
Implement preliminary GDT linear model function
Diffstat (limited to 'gdt-plot.lua')
-rw-r--r--gdt-plot.lua 35
1 files changed, 35 insertions, 0 deletions
diff --git a/gdt-plot.lua b/gdt-plot.lua
index a1308c4d..8d624474 100644
--- a/gdt-plot.lua
+++ b/gdt-plot.lua
@@ -1,4 +1,5 @@
local concat = table.concat
+local select = select
local function collate(ls)
return concat(ls, ' ')
@@ -257,7 +258,41 @@ local function gdt_table_reduce(t_src, jxs, jys, jes)
return t
end
+local function count_args(...)
+ return select('#', ...)
+end
+
+local function set_elements(X, P, i, ...)
+ for k = 1, P do
+ local v = select(k, ...)
+ X:set(i, k, v)
+ end
+end
+
+local function gdt_table_linfit(t, f, jy)
+ local N, M = t:dim()
+ local name = {}
+ for k = 1, M do
+ name[k] = t:get_header(k)
+ end
+ local row = {}
+ for k = 1, M do
+ row[name[k]] = t:get(1, k)
+ end
+ local P = count_args(f(row))
+
+ local X, Y = matrix.alloc(N, P), matrix.alloc(N, 1)
+ for i = 1, N do
+ for k = 1, M do row[name[k]] = t:get(i, k) end
+ set_elements(X, P, i, f(row))
+ Y:set(i, 1, t:get(i, jy))
+ end
+
+ return num.linfit(X, Y)
+end
+
gdt.barplot = gdt_table_barplot
gdt.plot = gdt_table_lineplot
gdt.xyplot = gdt_table_xyplot
gdt.reduce = gdt_table_reduce
+gdt.lm = gdt_table_linfit
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月13日 02:49:18 +0000

AltStyle によって変換されたページ (->オリジナル) /