summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pptdb.c17
-rw-r--r--src/train5.py38
2 files changed, 29 insertions, 26 deletions
diff --git a/src/pptdb.c b/src/pptdb.c
index 712aabc..7a26ffd 100644
--- a/src/pptdb.c
+++ b/src/pptdb.c
@@ -19,28 +19,29 @@ write_input(void) {
// Two layers of board_size * board_size:
float t; int h; uint16_t mask;
for (int k = 0; k < board_size * board_size; k++) {
- // stacks encoded as balanced ternary, without caps and walls
+ // stacks encoded as balanced ternary
t = 0;
h = COUNT_AT(k);
+
if (h>0) {
mask = 1<<(h-1);
- /* if (STONE_AT(k) != STONE_FLAT) h--; */
while (h-->0) {
- t += (colours[k] & mask) ? +1.0 : -1.0;
- t /= 3;
+ t += (colours[k] & mask) ? +1 : -1;
+ t/=3;
mask >>= 1;
}
}
fprintf(training_fh,"%.6f,",t);
}
- int val;
+ float val;
for (int k = 0; k < board_size * board_size; k++) {
val = 0;
if (COUNT_AT(k)) {
- if (STONE_AT(k) == STONE_STANDING) val = (colours[k] & 1) ? +1 : -1;
- else if (STONE_AT(k) == STONE_CAPSTONE) val = (colours[k] & 1) ? +2 : -2;
+ if (STONE_AT(k) == STONE_STANDING) val = (colours[k] & 1) ? +1/3 : -1/3;
+ else if (STONE_AT(k) == STONE_CAPSTONE) val = (colours[k] & 1) ? +1.0 : -1.0;
+ else val = (colours[k] & 1) ? +2/3 : -2/3;
}
- fprintf(training_fh,"%d,",val);
+ fprintf(training_fh,"%.6f,",val);
}
}
diff --git a/src/train5.py b/src/train5.py
index 225068b..3718fd0 100644
--- a/src/train5.py
+++ b/src/train5.py
@@ -12,40 +12,42 @@ from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Dense
model = Sequential([
- Conv2D(5, kernel_size=3, padding='same', input_shape=(5, 5, 2)),
- MaxPooling2D(pool_size=(2, 2), strides=None),
- Activation("relu"),
- Flatten(),
- Dense(10, activation="relu"),
- Dense(8, activation="relu"),
- Dense(1, activation="sigmoid")
-
- # Dense(40, activation="relu", input_shape=(52,)),
+ # Conv2D(5, kernel_size=5, padding='same', input_shape=(5, 5, 2)),
+ # MaxPooling2D(pool_size=2, strides=2),
+ # Activation("relu"),
+ # Flatten(),
+ # Dense(25, activation="relu"),
# Dense(10, activation="relu"),
- # Dense(5, activation="relu"),
# Dense(1, activation="sigmoid")
+
+ Dense(30, activation="relu", input_shape=(52,)), # 30
+ Dense(10, activation="relu"), # 10
+ Dense(8, activation="relu"), # 8
+ Dense(1, activation="sigmoid")
])
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
-csv = pd.read_csv("data/test.csv")
+csv = pd.read_csv("data/train5.csv")
-training_data = csv.copy().head(5000)
+training_data = csv.copy().head(40000)
training_outcome = training_data.pop('Outcome')
training_input = training_data.copy()
-training_input = training_input.drop(columns=training_data.keys()[0:2])
+# training_input = training_input.drop(columns=training_data.keys()[0:2])
train = np.array(training_input)
-train = train.reshape((training_input.shape[0], 5, 5, 2))
+# train = train.reshape((training_input.shape[0], 5, 5, 2))
-model.fit(train, training_outcome, epochs=20)
+model.fit(train, training_outcome, epochs=100)
-test_data = csv.copy().head(10000)
-test_data = test_data.drop(columns=test_data.keys()[0:2])
+test_data = csv.copy().tail(50000)
+# test_data = test_data.drop(columns=test_data.keys()[0:2])
test_outcome = test_data.pop('Outcome')
test_input = np.array(test_data)
-test_input.reshape((test_data.shape[0], 5, 5, 2))
+# test_input = test_input.reshape((test_data.shape[0], 5, 5, 2))
test_loss, test_acc = model.evaluate(test_input, test_outcome, verbose=2)
print('\nTest accuracy:', test_acc)
+
+# Test accuracy: 0.67448