ELM: pluggable hidden activation (tanh / relu / step)
ActivationKind (atanTanh default, atanRelu, atanStep) on ElmConfig, plus applyActivation, activationName and parseActivation. The hidden units stay pure additive nodes: every activation sees the same pre-activation s = a.x + b and differs only in the scalar nonlinearity g. tanh is unchanged and bit-identical to the previous version, so existing callers cannot regress. Two init details are activation-aware, because relu and step are dead for s <= 0: they get bias U[0,1] instead of U[-1,1], and hidden weight scale 8/sqrt(inputDim) instead of 1/sqrt(inputDim) (at the tanh scale the pre-activations barely straddle 0, the Gram matrix loses rank and Thm 2.2 interpolation fails outright). No RBF option: g(b*||x - a||) reads the distance to a centre in input space, which is a different node architecture (extra centre + width parameters, its own init and its own Thm 2.2 validation), not a different g. Adds tests/test_elm.nim (9 suites) and a `nimble test` task. All pass.
This commit is contained in:
@@ -79,6 +79,18 @@ done
|
||||
# direct `nimble runBot`) means release. Release is the quiet default.
|
||||
BUILD_MODE="${DEVCONTROLBOT_DEBUG:-release}"
|
||||
|
||||
# Compile-time Nim defines, stripped from the caller's argv by DevControlBot.sh
|
||||
# and handed over here as a space-separated string. They MUST be stripped: this
|
||||
# task forwards its own argv to the BOT BINARY, so a -d: arg left there would be
|
||||
# consumed as the bot's argv and never reach the compiler. Applied to BOTH build
|
||||
# modes on purpose: defines are independent of optimisation level, so -d:tfilDebug
|
||||
# debug graphics are wanted in a release build too. Empty when the caller passed
|
||||
# none, which leaves the compile lines exactly as they were.
|
||||
DEFINES="${DEVCONTROLBOT_DEFINES:-}"
|
||||
if [ -n "$DEFINES" ]; then
|
||||
echo "[devcontrolbot] compile-time defines: $DEFINES"
|
||||
fi
|
||||
|
||||
BUILD_DIR="$(mktemp -d "${TMPDIR:-/tmp}/devcontrolbot.XXXXXX")"
|
||||
BINARY="$BUILD_DIR/DevControlBot"
|
||||
|
||||
@@ -171,16 +183,18 @@ trap 'exit 143' TERM
|
||||
LOG="$BUILD_DIR/build.log"
|
||||
if [ "$BUILD_MODE" = "debug" ]; then
|
||||
echo "[devcontrolbot] compiling DevControlBot.nim (DEBUG BUILD) -> $BINARY"
|
||||
# `eval` re-parses $DEPS so the embedded quotes do the word splitting: the
|
||||
# dependency paths survive spaces, without relying on glob or brace expansion.
|
||||
# `eval` re-parses $DEPS and $DEFINES so the embedded quotes do the word
|
||||
# splitting: the dependency paths survive spaces, without relying on glob or
|
||||
# brace expansion. $DEFINES holds only whole -d:name[=value] words (the wrapper
|
||||
# rejects whitespace and shell metacharacters).
|
||||
# No pipe: POSIX sh has no PIPESTATUS, and `nim | tee` would report tee's
|
||||
# status, not the compiler's. Buffer first, then replay the log verbatim.
|
||||
eval nim c $DEPS --out:"$BINARY" DevControlBot.nim >"$LOG" 2>&1
|
||||
eval nim c $DEFINES $DEPS --out:"$BINARY" DevControlBot.nim >"$LOG" 2>&1
|
||||
compile_rc=$?
|
||||
cat "$LOG"
|
||||
else
|
||||
echo "[devcontrolbot] compiling DevControlBot.nim -> $BINARY"
|
||||
eval nim c -d:release --hints:off $DEPS --out:"$BINARY" DevControlBot.nim >"$LOG" 2>&1
|
||||
eval nim c -d:release $DEFINES --hints:off $DEPS --out:"$BINARY" DevControlBot.nim >"$LOG" 2>&1
|
||||
compile_rc=$?
|
||||
fi
|
||||
if [ $compile_rc -ne 0 ]; then
|
||||
@@ -236,3 +250,6 @@ task runBot, "Compile, run and clean up the bot":
|
||||
elif a == "runBot":
|
||||
seen = true
|
||||
exec "sh -c " & quoteShell(runScript) & " devcontrolbot " & args
|
||||
|
||||
task test, "Run unit tests":
|
||||
exec "nim c -r --hints:off ../tests/test_elm.nim"
|
||||
|
||||
Reference in New Issue
Block a user