Created
October 21, 2021 19:37
-
-
Save callumvanzyl/ea0512acb6f2290982e68f4f304c7292 to your computer and use it in GitHub Desktop.
A simple Lua class that can generate a Sigmoid function and transform input based on its parameters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local e = 2.7182818284590 | |
local SigmoidFunction = {} | |
SigmoidFunction.__index = SigmoidFunction | |
function SigmoidFunction:transform(x) | |
return (1 / (1 + (e ^ ((x * self.steepness) + self.offset)))) | |
end | |
function SigmoidFunction:calculateOdds(difficulty, luck) | |
local rawOdds = (1 + luck) / ((1 + luck) + (1 + difficulty)) | |
local adjustedOdds = self:transform(rawOdds) | |
return adjustedOdds | |
end | |
function SigmoidFunction.new(steepness, offset) | |
local newSigmoidFunction = {} | |
setmetatable(newSigmoidFunction, SigmoidFunction) | |
newSigmoidFunction.steepness = steepness | |
newSigmoidFunction.offset = offset | |
return newSigmoidFunction | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment