diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ctaklm.c | 2 | ||||
| -rw-r--r-- | src/pptdb.c | 14 | ||||
| -rw-r--r-- | src/train5.py | 22 |
3 files changed, 22 insertions, 16 deletions
diff --git a/src/ctaklm.c b/src/ctaklm.c index 4060911..9d0f867 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -366,7 +366,7 @@ main(int argc, char **argv) { int r = handle_turn(line); if (r == EXIT_SUCCESS && won == 0xFF) { fputs("Thinking [", stdout); - float minimax = ct1986_minimax(0, 2, 0); + float minimax = ct1986_minimax(0, 1, 0); printf("] Result: %s (%.3f)\n", ct1986_ptn, minimax*100.0); diff --git a/src/pptdb.c b/src/pptdb.c index a67be1d..dbadfdf 100644 --- a/src/pptdb.c +++ b/src/pptdb.c @@ -4,10 +4,10 @@ #include <tak.h> -int generate; +float max_flats; uint64_t heights[16]; -float max_flats, outcome_black; FILE *training_fh = NULL; +int generate, outcome_black; const int max_depth = 8; @@ -107,11 +107,7 @@ parse_line(const char *pt, const ssize_t read) { // Generate training data, not too early in the game if (generate && ply + 5 > total_plies) { write_input(); - if (ply >= total_plies) { - if (outcome_black > 0.5) outcome_black = 1.0; - else outcome_black = 0.0; - } - fprintf(training_fh,"%.2f\n", outcome_black); + fprintf(training_fh,"%df\n", outcome_black); } // Parse next action while (idx<read && pt[idx++]!=','); @@ -164,8 +160,8 @@ main(int argc, char **argv) { // Reset everything reset_state(size); // Store the outcome of this game. Black win = 1 - if (line[read-4] == '0') outcome_black = 0.99; - else outcome_black = 0.01; + if (line[read-4] == '0') outcome_black = 1; + else outcome_black = 0; // Parse the line r = parse_line(line,read-4); // Adjust counts if we're not generating training data diff --git a/src/train5.py b/src/train5.py index 71a8652..c3fec82 100644 --- a/src/train5.py +++ b/src/train5.py @@ -31,6 +31,17 @@ def truncated_pade_logistic(x): divide(x, add(square(x), k(10.0)))))) return minimum(k(1.0), maximum(k(0.0), divide(val, k(24.0)))) + +# A cheaper version of tanh, x/6+25*x/(6*(2*x*x+5)), +# clamped between -1 and 1. +def truncated_pade_tanh(x): + val = add(divide(x, k(6.0)), + multiply(k(25.0), + divide(x, multiply(k(6.0), add(k(5.0), + multiply(k(2.0), square(x))))))) + return minimum(k(1.0), maximum(k(-1.0), val)) + + def make_model(size, magic=[12, 9, 9]): # Our model for the stacks, a small CNN stack_shape = (size, size, 8) @@ -59,7 +70,7 @@ def make_model(size, magic=[12, 9, 9]): def load_data(size): shape = (-1, size, size, 8) - + # Load training data tr_fn = "training-"+str(size)+".csv" training_csv = pd.read_csv(tr_fn) #.head(100000) training_data = training_csv @@ -67,14 +78,13 @@ def load_data(size): training_flats_input = np.array(training_data.iloc[:, 0:2]) training_input = [training_stack_input, training_flats_input] training_outcome = training_data.iloc[:, -1:] - + # Load validation data val_fn = "validation-"+str(size)+".csv" - val_data = pd.read_csv(val_fn) #.tail(20000) + val_data = pd.read_csv(val_fn).tail(20000) val_stack_input = np.array(val_data.iloc[:, 2:-1]).reshape(shape, order='F') val_flats_input = np.array(val_data.iloc[:, 0:2]) val_input = [val_stack_input, val_flats_input] val_outcome = val_data.iloc[:, -1:] - return [(training_input, training_outcome), (val_input, val_outcome)] def train(size, model, data, iterations=1, epochs=10): @@ -150,8 +160,8 @@ def write_weights(model): data = load_data(5) -model = make_model(5, [12, 9, 9]) -results, model = train(5, model, data, iterations=10, epochs=20) +model = make_model(5, [12, 9, 10]) +results, model = train(5, model, data, iterations=1, epochs=10) print("\nScores") for i in range(len(results)): print("Iteration {0}: {1}".format(i+1, results[i])) |
