Skip to content

Instantly share code, notes, and snippets.

View drauschenbach's full-sized avatar

David Rauschenbach drauschenbach

View GitHub Profile
$ redis-cli --eval train-kmeans-with-dependencies.lua 0,0
$ tail /usr/local/var/log/redis.log
22385:M 23 Feb 2019 12:48:23.898 - Accepted 127.0.0.1:49901
INFO Running Stuart (Embedded Spark 2.2.0)
INFO Local KMeans++ reached the max number of iterations: 30
INFO Local KMeans++ reached the max number of iterations: 30
INFO KMeans converged in 4 iterations.
INFO The cost is 320.460000
$ redis-cli --eval test1-with-dependencies.lua 0,0
"5,6,7,8,9,10,11"
$ amalg-redis.lua -s test1.lua -o test1-with-dependencies.lua -c
$ wc -l test1-with-dependencies.lua
2913 test1-with-dependencies.lua
$ lua -lamalg-redis test1.lua
5,6,7,8,9,10,11
$ cat amalg.cache
return {
[ "moses" ] = "L",
}
local moses = require 'moses'
local acc = {}
for _, i in ipairs(moses.range(5,11)) do
acc[#acc+1] = i
end
local result = table.concat(acc, ',')
print(result)
return result
$ luarocks install amalg-redis
print(collectgarbage('count'))
5.30859375
Matrices = require 'stuart-ml.linalg.Matrices'
local dm = Matrices.dense(3, 2, {1.0, 3.0, 5.0, 2.0, 4.0, 6.0})
print(collectgarbage('count'))
6.177734375
eLua# lua /rom/test/ml/Matrices.luo
Press CTRL+Z to exit Lua
Begin test
✓ dense matrix construction
✓ dense matrix construction with wrong dimension
✓ sparse matrix construction
✓ sparse matrix construction with wrong number of elements
✓ index in matrices incorrect input
✓ matrix indexing and updating
✓ toSparse, toDense
<html>
<body>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/fengari-web@0.1.2/dist/fengari-web.js"></script>
<script type="application/lua" src="https://cdn.jsdelivr.net/npm/lua-stuart@2.0.0-0/stuart.lua"></script>
<script type="application/lua" src="https://cdn.jsdelivr.net/npm/lua-stuart-ml@2.0.1-0/stuart-ml.lua"></script>
<script type="application/lua">
local Matrices = require 'stuart-ml.linalg.Matrices'
local denseMatrix = Matrices.dense(3, 2, {1.0, 3.0, 5.0, 2.0, 4.0, 6.0})
...
Matrices = require 'stuart-ml.linalg.Matrices'
-- Create a dense matrix ((1.0, 2.0), (3.0, 4.0), (5.0, 6.0))
local dm = Matrices.dense(3, 2, {1.0, 3.0, 5.0, 2.0, 4.0, 6.0})
-- Create a sparse matrix ((9.0, 0.0), (0.0, 8.0), (0.0, 6.0))
local sm = Matrices.sparse(3, 2, {0, 1, 3}, {0, 2, 1}, {9, 6, 8})