Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sleitnick/rbxpolyreg
Polynomial Regression for Lua/Roblox
https://github.com/sleitnick/rbxpolyreg
Last synced: 4 days ago
JSON representation
Polynomial Regression for Lua/Roblox
- Host: GitHub
- URL: https://github.com/sleitnick/rbxpolyreg
- Owner: Sleitnick
- License: gpl-3.0
- Created: 2020-01-16T00:11:00.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-16T01:23:34.000Z (almost 5 years ago)
- Last Synced: 2024-11-02T13:21:15.328Z (about 2 months ago)
- Language: Lua
- Homepage: https://www.roblox.com/library/4602247366/RbxPolyReg
- Size: 27.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# RbxPolyReg
Polynomial regression solver.
Full credit to the original author, Paul Lutus, and his [PolySolve](https://arachnoid.com/polysolve/) site. This is simply a port of his JavaScript code into Lua, which is covered under the GNU General Public License.
The Roblox ModuleScript is available [here](https://www.roblox.com/library/4602247366/RbxPolyReg).
---------------
## Usage
```lua
local RbxPolyReg = require(rbxPolyRegModuleScript)-- Get matrix functions:
local matFuncs = RbxPolyReg.MatFunctions.new()-- Each data entry can be 1 of 3 different types:
-- 1) {Number, Number}
-- 2) {X = Number; Y = Number} OR {x = Number; Y = Number}
-- 3) Vector2
local data = {
{-1, -1},
{0, 3},
{1, 2.5},
{2, 5},
{3, 4},
{5, 2},
{7, 5},
{9, 4}
}-- Degrees can be between 0 and 18:
local degrees = 2-- Solve polynomial regression:
local result = matFuncs:ProcessData(data, degrees)
-- result[1]: Table of terms
-- result[2]: Correlation coefficient
-- result[3]: Standard error-- List terms:
local terms = result[1]
for i,v in ipairs(terms) do
print(("%.16e * x^%i"):format(v, i - 1))
end-- Create source code for the polynomial regression:
local clampMin, clampMax = 0, 1000
local funcSrcCode = RbxPolyReg.ToFunctionSourceCode(terms, clampMin, clampMax)
print(funcSrcCode)```