Skip to content

Instantly share code, notes, and snippets.

@callumvanzyl
Created October 21, 2021 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callumvanzyl/ea0512acb6f2290982e68f4f304c7292 to your computer and use it in GitHub Desktop.
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.
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