SciLuaページ(私のテストファイルをtest.lua
命名された)から、次の例の実行:SciLua:近くに予期しない記号 ']'
-- No global key is set:
local alg = require "sci.alg" -- Load sci.alg module.
local dist = require "sci.dist" -- Load sci.dist module.
local function randmatstat(t)
local n = 5
local v, w = alg.vec(t), alg.vec(t)
for i=1,t do
local a, b, c, d = randn(n, n), randn(n, n), randn(n, n), randn(n, n)
local P = alg.join(a..b..c..d)
local Q = alg.join(a..b, c..d)
v[i] = alg.trace((P[]`**P[])^^4) -- Matrix transpose, product and power.
w[i] = alg.trace((Q[]`**Q[])^^4) -- Matrix transpose, product and power.
end
return sqrt(stat.var(v))/stat.mean(v), sqrt(stat.var(w))/stat.mean(w)
end
を私はエラーを取得しておいてください。
test.lua:13: unexpected symbol near ']'
他のほとんどのモジュールは正常に動作しますが、行列を使用する場合にのみ問題が発生します。私はあなたの助けに感謝します。
更新
:@stepeluによって役に立つ答えをが、私は彼に非常に感謝して、以下の完全な例は今、正常に動作します:期待される出力と
local alg = require 'sci.alg'
local prng = require 'sci.prng'
local stat = require 'sci.stat'
local dist = require 'sci.dist'
local min, sqrt, random, abs = math.min, math.sqrt, math.random, math.abs
local rng = prng.std()
local vec, mat, join = alg.vec, alg.mat, alg.join
local function randn(r, c)
local x = mat(r, c)
for i=1,#x do
x[i] = dist.normal(0, 1):sample(rng)
end
return x
end
local function randmatstat(t)
local n = 5
local v, w = alg.vec(t), alg.vec(t)
for i=1,t do
local a, b, c, d = randn(n, n), randn(n, n), randn(n, n), randn(n, n)
local P = alg.join(a..b..c..d)
local Q = alg.join(a..b, c..d)
v[i] = alg.trace((P[]`**P[])^^4) -- Matrix transpose, product and power.
w[i] = alg.trace((Q[]`**Q[])^^4) -- Matrix transpose, product and power.
end
return sqrt(stat.var(v))/stat.mean(v), sqrt(stat.var(w))/stat.mean(w)
end
print(randmatstat(1000))
:
0.75865001347735 0.74932678346271
[Finished in 0.2s]
これはバックティックが気に入らないのです –
私はdownvoteを見ますが、これは私の1日ルアを学んでいます、私は何か愚かなことをしているかもしれません。下降者は代わりに私にヒントを与えて、よりポジティブになれますか? – AboAmmar
@MarcinOrlowski - バッククォートは、ページが示すように、行列の転置のためのものです。 – AboAmmar