aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2021-01-16 01:11:22 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit0983031d914d5fc391805bdb1034429c2be07383 (patch)
treecdce20a03c2d4f2743d0368b9c1576179296f4d9
parent87d8665b6615c5c572ac0c23d20d26b448eaf483 (diff)
Quick sketch of non-determinism
-rw-r--r--Makefile3
-rw-r--r--include/ct1986.c11
2 files changed, 12 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 1f472ed..1dfb930 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
IDIR=include
TPDIR=3rd-party
-CFLAGS=-O3 -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -I$(IDIR) -I$(TPDIR)
+DEFINES=-DDETERMINISTIC
+CFLAGS=-O3 -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE $(DEFINES) -I$(IDIR) -I$(TPDIR)
LIBS=
SRCS=$(wildcard include/*.c) $(wildcard 3rd-party/*.c)
diff --git a/include/ct1986.c b/include/ct1986.c
index c80e32a..a3b089e 100644
--- a/include/ct1986.c
+++ b/include/ct1986.c
@@ -16,6 +16,12 @@ static float flattened[CONV_NUM+2];
static float dense1[DENSE1_NUM];
static float dense2[DENSE2_NUM];
+#ifndef DETERMINISTIC
+static uint32_t x = 1;
+#define DOXORSHIFT { x ^= x << 13; x ^= x >> 17; x ^= x << 5; }
+#define FUDGE (((float)(x&255))/255.0-0.5)*0.2
+#endif
+
#define RELU(x) ((x) = ((x)<0)?0:(x))
float
@@ -91,9 +97,12 @@ ct1986_evaluate_black_win(void) {
for (uint8_t d2 = 0; d2 < DENSE2_NUM; d2++) {
output += dense2[d2]*output_weights[d2];
}
-
// Truncated Pade approximant of logistic function
output = (12.0+output+50.0*output/(output*output+10.0))/24.0;
+#ifndef DETERMINISTIC
+ DOXORSHIFT;
+ output += FUDGE;
+#endif
if (output > 1.0) return 1.0;
else if (output < 0.0) return 0.0;