Skip to content

Commit

Permalink
#330 frontend: simplify sigmoid function
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolkenfarmer committed Oct 31, 2024
1 parent d16e7f8 commit 448894a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frontend/src/stores/ContinuousVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ function sigmoid(variable: ContinuousVariableInternal, timeUntilPhaseChange: num

const t = variable.tDelta - timeUntilPhaseChange
const tMid = variable.tDelta / 2
const tStretchFactor = 1 / ((Math.pow(variable.tDelta, 2)) / Math.pow(steepness, 2))
const tStretchCorrector = variable.tDelta / steepness
const tStretchFactor = Math.pow(steepness, 2) / Math.pow(variable.tDelta, 2)
const tStretchCorrector = steepness / variable.tDelta

const xDelta = variable.xTarget - variable.xStart
const xStretcher = xDelta / (2 * Math.atan(steepness / 2))

const atanDerivative = (1 / (Math.pow(t - tMid, 2) * tStretchFactor + 1))

return (atanDerivative * xStretcher / tStretchCorrector)
return (atanDerivative * xStretcher * tStretchCorrector)
}

function sigmoidDelayed(variable: ContinuousVariableInternal, timeUntilPhaseChange: number): number {
Expand All @@ -136,8 +136,8 @@ function sigmoidDelayed(variable: ContinuousVariableInternal, timeUntilPhaseChan
const tDeltaShifted = variable.tDelta - t0Shifted
const tShiftedMid = tMid + (variable.tDelta - tMid) / tShiftFrac // Shifted midpoint

const tStretchFactor = 1 / ((Math.pow(tDeltaShifted, 2)) / Math.pow(steepness, 2))
const tStretchCorrector = tDeltaShifted / steepness
const tStretchFactor = Math.pow(steepness, 2) / Math.pow(tDeltaShifted, 2)
const tStretchCorrector = steepness / tDeltaShifted

const xDelta = variable.xTarget - variable.xStart
const xStretcher = xDelta / (2 * Math.atan(steepness / 2))
Expand All @@ -147,5 +147,5 @@ function sigmoidDelayed(variable: ContinuousVariableInternal, timeUntilPhaseChan
if (t < t0Shifted) {
console.log("straight")
return 0
} else return atanDerivative * xStretcher / tStretchCorrector
} else return atanDerivative * xStretcher * tStretchCorrector
}

0 comments on commit 448894a

Please sign in to comment.