-
Notifications
You must be signed in to change notification settings - Fork 0
/
ne_actions.py
executable file
·119 lines (89 loc) · 3.18 KB
/
ne_actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import pickle
import neat
import pandas as pd
import os
import numpy as np
import random
# local_dir = os.path.dirname(__file__)
dir_path = os.path.dirname(os.path.realpath(__file__))
config_path = os.path.join(dir_path, 'config.txt')
data = pd.read_csv(dir_path + '/auto_files/ne_input.csv')
MAX_BET_SIZE = 10
MIN_ODDS_SIZE = 0
MAX_ODDS_SIZE = 1000
bet_sizes = []
bet_direction = []
no_bets_list = []
# Bet dictionary
bet_dict = {
0: 'True',
1: 'False',
2: 'No Bet'
}
def set_vars():
dir_path = os.path.dirname(os.path.realpath(__file__))
config_path = os.path.join(dir_path, 'config.txt')
data = pd.read_csv(dir_path + '/auto_files/ne_input.csv')
MAX_BET_SIZE = 10
MIN_ODDS_SIZE = 0
MAX_ODDS_SIZE = 1000
bet_sizes = []
bet_direction = []
no_bets_list = []
# Bet dictionary
bet_dict = {
0: 'True',
1: 'False',
2: 'No Bet'
}
return dir_path, data, MAX_BET_SIZE, MAX_ODDS_SIZE, MIN_ODDS_SIZE, bet_sizes, bet_direction, no_bets_list, bet_dict, config_path
def get_questions(data):
questions_df = data[['Home Odds', 'Vis Odds', 'Predictions']]
questions_df['P2'] = questions_df['Predictions']
questions_df['P3'] = questions_df['Predictions']
questions = questions_df.values.tolist()
return questions, questions_df
def make_bet(genomes, question, bet_sizes, bet_direction):
guess = genomes.activate(question[-5:])
bets = guess[:2]
bet = int(bets.index(max(bets)))
bet = bet_dict[bet]
bet_size = round((guess[3] * 10), 2)
# Check for upper and lower limit of bet sizes
bet_size = MAX_BET_SIZE if bet_size > MAX_BET_SIZE else 0 if bet_size < 0 else bet_size
# Quiz logic
if (bet == 'True') and (question[0] > MIN_ODDS_SIZE) and (question[0] < MAX_ODDS_SIZE):
bet = 'True'
elif (bet == 'False') and (question[1] > MIN_ODDS_SIZE) and (question[1] < MAX_ODDS_SIZE):
bet = 'False'
else:
bet = 'No Bet'
bet_direction.append(bet)
bet_sizes.append(float(bet_size))
def make_bets(genomes, config, questions):
for i in range(len(questions)):
make_bet(genomes, questions[i], bet_sizes, bet_direction)
# Print DF
def print_bets(data, bet_sizes, bet_direction):
data['Bet Direction'] = bet_direction
data['Bet Sizes'] = bet_sizes
data.to_csv(dir_path + '/auto_files/betting_actions.csv', index=False)
# Make bets
def replay_genome(config_path, genome_path="winner.pkl"):
# Load requried NEAT config
config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation, config_path)
# Unpickle saved winner
with open(genome_path, "rb") as f:
genome = pickle.load(f)
# Convert loaded genome into required data structure
genomes = [(1, genome)]
net = neat.nn.FeedForwardNetwork.create(genome, config)
# Call game with only the loaded genome
questions, questions_df = get_questions(data)
make_bets(net, config, questions)
print_bets(data, bet_sizes, bet_direction)
if __name__=='__main__':
# Path to config file
config_path = os.path.join(dir_path, 'config.txt')
# Run multiple times
replay_genome(config_path)