From a3a331a9a6b760304ee1530b9ed963eb7d08c64c Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Fri, 14 Apr 2023 07:26:05 -0400 Subject: [PATCH] Change AutoBone's decay function to be more standard (#630) --- .../java/dev/slimevr/autobone/AutoBone.kt | 24 +++++++++---------- .../java/dev/slimevr/config/AutoBoneConfig.kt | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/dev/slimevr/autobone/AutoBone.kt b/server/src/main/java/dev/slimevr/autobone/AutoBone.kt index 668bf1bf7..46bc524b0 100644 --- a/server/src/main/java/dev/slimevr/autobone/AutoBone.kt +++ b/server/src/main/java/dev/slimevr/autobone/AutoBone.kt @@ -415,14 +415,8 @@ class AutoBone(server: VRServer) { // Epoch loop, each epoch is one full iteration over the full dataset for (epoch in (if (calcInitError) -1 else 0) until config.numEpochs) { - val adjustRate = if (epoch >= 0) { - ( - config.initialAdjustRate - * FastMath.pow(config.adjustRateMultiplier, epoch.toFloat()) - ) - } else { - 0f - } + val adjustRate = decayFunc(config.initialAdjustRate, config.adjustRateDecay, epoch) + var randomFrameIndices: IntArray? = null if (config.randomizeFrameOrder) { randomFrameIndices = IntArray(frameCount) @@ -585,7 +579,7 @@ class AutoBone(server: VRServer) { val adjVal = stepHeightDiff * (length / stepHeight) // Scale the length to fit the target height - entry.setValue(Math.max(length + adjVal / 2f, 0.01f)) + entry.setValue((length + adjVal / 2f).coerceAtLeast(0.01f)) } } } @@ -598,7 +592,7 @@ class AutoBone(server: VRServer) { if (epoch <= 0 || epoch >= config.numEpochs - 1 || (epoch + 1) % config.printEveryNumEpochs == 0) { LogManager .info( - "[AutoBone] Epoch ${epoch + 1} average error: ${errorStats.mean} (SD ${errorStats.standardDeviation})" + "[AutoBone] Epoch: ${epoch + 1}, Mean error: ${errorStats.mean} (SD ${errorStats.standardDeviation}), Adjust rate: $adjustRate" ) } applyConfig(legacyConfigs) @@ -607,7 +601,7 @@ class AutoBone(server: VRServer) { val finalHeight = sumSelectConfigs(heightOffsets, offsets) LogManager .info( - "[AutoBone] Target height: $targetHeight New height: $finalHeight" + "[AutoBone] Target height: $targetHeight, New height: $finalHeight" ) return AutoBoneResults(finalHeight, targetHeight, errorStats, legacyConfigs) } @@ -740,7 +734,7 @@ class AutoBone(server: VRServer) { val configValues: EnumMap, ) { override fun toString(): String { - return "Epoch: $epoch, Epoch Error: $epochError" + return "Epoch: $epoch, Epoch error: $epochError" } } @@ -759,8 +753,12 @@ class AutoBone(server: VRServer) { val loadDir = File("Load AutoBone Recordings") // Mean square error function - protected fun errorFunc(errorDeriv: Float): Float { + private fun errorFunc(errorDeriv: Float): Float { return 0.5f * (errorDeriv * errorDeriv) } + + private fun decayFunc(initialAdjustRate: Float, adjustRateDecay: Float, epoch: Int): Float { + return if (epoch >= 0) initialAdjustRate / (1 + (adjustRateDecay * epoch)) else 0.0f + } } } diff --git a/server/src/main/java/dev/slimevr/config/AutoBoneConfig.kt b/server/src/main/java/dev/slimevr/config/AutoBoneConfig.kt index 9f9fdc876..8700c478f 100644 --- a/server/src/main/java/dev/slimevr/config/AutoBoneConfig.kt +++ b/server/src/main/java/dev/slimevr/config/AutoBoneConfig.kt @@ -6,8 +6,8 @@ class AutoBoneConfig { var maxDataDistance = 1 var numEpochs = 100 var printEveryNumEpochs = 25 - var initialAdjustRate = 10f - var adjustRateMultiplier = 0.995f + var initialAdjustRate = 10.0f + var adjustRateDecay = 1.0f var slideErrorFactor = 0.0f var offsetSlideErrorFactor = 2.0f var footHeightOffsetErrorFactor = 0.0f