-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract.lua
More file actions
41 lines (35 loc) · 893 Bytes
/
contract.lua
File metadata and controls
41 lines (35 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- handler.lua
local AOlearn = require("@berry/AOlearn")
local json = require("json")
-- Initialize state
if not Handlers then Handlers = { } end
-- Add Lasso regression handler
Handlers.add("train", function(msg)
-- Parse incoming data
local data = json.decode(msg.Data)
-- Validate input
if not data or not data.X or not data.y then
return { error = "Missing required data fields" }
end
-- Run Lasso regression
local ok, weights, bias = pcall(function()
return AOlearn.lasso.fit_lasso(data.X, data.y, data.alpha or 0.1)
end)
-- Handle computation result
if not ok then
return {
ok = false,
error = "Computation failed: " .. tostring(weights)
}
end
-- Return success response
return {
ok = true,
model = {
coefficients = weights,
intercept = bias,
type = "lasso"
},
timestamp = os.time()
}
end)