Gen AI Library
Gradient descent optimization library for the gen editor's experimental tools.
Gradient descent optimization library for the gen editor's experimental tools.
Overview
The ai library module provides numerical optimization via gradient descent. It offers two variants: a basic gradient descent (go) with ratio-based convergence, and an advanced version (go2) with configurable step functions and epoch limits. Used by experimental gen editor tools for inverse kinematics, body simulation, and parameter fitting.
Functions
| Function | Signature | Description |
|---|---|---|
M.go2(ac, loss, step, epo, s) | (table, function, function, number?, number?) → number, number, table | Advanced gradient descent with custom step function. step(ac, k, s) returns perturbed copy. Returns (finalLoss, initialLoss, coefficients) |
M.line(set, ac) | (table, table?) → number, table, table | Fits a line to a point set using gradient descent. Returns (ratio, finalCoeffs, initialCoeffs) where coefficients are {ax,ay,az,bx,by,bz} |
Parameters
M.go2(ac, loss, step, epo, s)
| Parameter | Type | Default | Description |
|---|---|---|---|
ac | table | - | Coefficient array (modified in-place) |
loss | function | - | Loss function |
step | function | - | Step function: step(ac, k, s) → perturbed_ac |
epo | number | 1000 | Maximum epochs |
s | number | 0.02 | Perturbation step size |
Algorithm
Both functions use finite-difference gradient estimation:
- For each coefficient
k, perturbac[k]by step size - Evaluate
loss()to estimate gradient direction - Update all coefficients proportionally to gradient
- Repeat until convergence or max iterations
Usage Example
local AI = require('/lua/ge/extensions/editor/gen/lib/ai')
-- Simple optimization
local coeffs = {0.5, 0.3, 0.7}
local function myLoss(ac)
return (ac[1] - 1)^2 + (ac[2] - 2)^2 + (ac[3] - 3)^2
end
local finalLoss, initialLoss = AI.go(coeffs, myLoss, 0.1)
-- Advanced with custom step
local final, initial = AI.go2(coeffs, myLoss, function(ac, k, s)
local copy = deepcopy(ac)
copy[k] = copy[k] + s
return copy
end, 500, 0.01)Note on Local Functions
go(ac, loss, rat)- Local (not exported). Basic gradient descent without custom step function. Used internally.
See Also
- Gen Frame Editor - Uses AI for IK solving
- Gen SolidFlex - Uses AI for physics optimization
Editor Gen World
Central world/scene management module for the Building Architect Tool (BAT). Manages the full lifecycle of procedural buildings: creation, editing, material assignment, forest item placement, DAE expo
Gen JBeam Library
JBeam file parsing library for the gen editor's mesh and vehicle inspection tools.