def TransformData(data, bits=12, conv=False, startingplayer=False, startingplayerbits=False): transformed = [] #print("length:",len(data)) #for i in range(len(data[0])): for entry in data: #print(i) bitboard = entry[0] if conv: if not startingplayer: bitboard = TL.FENtoBits(bitboard, numberOfBits=bits, startingplayerbits=startingplayer) else: bitboard = TL.FENtoBitsWStartingPlayer(bitboard, numberOfBits=bits) bitboard = np.array(bitboard).reshape((8, 8, bits)) else: if not startingplayer: bitboard = TL.FENtoBits(bitboard, numberOfBits=bits, startingplayerbits=startingplayer) else: bitboard = TL.FENtoBitsWStartingPlayer(bitboard, numberOfBits=bits) bitboard = np.array(bitboard) transformed.append([bitboard, entry[1]]) return transformed
def DataForm(self, data): winOther = [] lossDraw = [] #draw = [] convolutional = True X = 8 if self.double_bits: X = X * 2 for entry in data: reshaped = TL.FENtoBits(entry[0], self.bits, startingplayerbits=self.double_bits) if convolutional: reshaped = np.reshape(reshaped, (X, 8, self.bits)) if entry[1] == 0: lossDraw.append([reshaped, 0]) winOther.append([reshaped, 0]) elif entry[1] == 1: winOther.append([reshaped, 1]) else: winOther.append([reshaped, 0]) lossDraw.append([reshaped, 1]) return (winOther, lossDraw)
def MassPredict(self, inp): score = 0 tData = [] #TestData = [[],[]] #train = data[0] #test = data[1] X = 8 if self.double_bits: X = X * 2 for entry in inp: #print(entry) reshaped = np.array( TL.FENtoBits(entry, self.bits, True, startingplayerbits=self.double_bits)) #print(len(reshaped)) reshaped = np.reshape(reshaped, (X, 8, self.bits)) tData.append(reshaped) #print(TrainData) #score = self.Machine[0].Score(inp) #return [self.Machine[0].Pred(inp)[0], score] return self.Machine[0].MassScore(tData)
def LoadData(): Data = DL.GetData(transform=False, includeDraw=False) TData = [] bits = 7 for entry in Data: reshaped = TL.FENtoBits(entry[0], bits, True) reshaped = np.reshape(reshaped, (8, 8, bits)) TData.append([reshaped, entry[1]]) TData = DL.StartifiedData(TData) return TData
def Predict(self, inp): score = 0 X = 8 if self.double_bits: X = X * 2 bit_board = np.array( TL.FENtoBits(inp, self.Machine[0].bits, True, startingplayerbits=self.double_bits)) inp = np.reshape(bit_board, (1, X, 8, self.Machine[0].bits)) #print(inp) #print(self.Machine[0].Pred(inp)) score = self.Machine[0].Score(inp) return [self.Machine[0].Pred(inp)[0], score]
def MassPredict(self, inp): data = [] win = [] winIndex = [] other = [] otherIndex = [] convolutional = True X = 8 if self.double_bits: X = X * 2 for entry in inp: reshaped = TL.FENtoBits(entry[0], self.bits, startingplayerbits=self.double_bits) if convolutional: reshaped = np.reshape(reshaped, (X, 8, self.bits)) data.append(reshaped) results = self.Machine[0].MassScore(data) for i in range(len(results)): if results[i][0] == 1: win.append(results[i]) winIndex.append(i) else: other.append(results[i]) otherIndex.append(i) otherres = aelf.Machine[1].MassScore(other) indecies = winIndex + otherIndex res = win + otherres def sorter(inp1): return inp1[1] sorting = [] for i in range(len(res)): sorting.append((res[i], indecies[i])) sorting.sort(key=sorter) return [i[0] for i in sorting]
def Predict(self, inp): if not len(self.Machine) == 1: print("Not correct predict. Amount of machines found:", str(len(self.Machine)), "expected 1") return machine = self.Machine[0] bit_board = np.array( TL.FENtoBits(inp, machine.bits, startingplayerbits=self.double_bits)) if machine.convolutional: bit_board = np.reshape(bit_board, (1, 8, 8, machine.bits)) else: bit_board = np.reshape(bit_board, (1, 1)) score = machine.Score(bit_board) return [machine.Pred(bit_board)[0], score]
def Predict(self, inp): X = 8 if self.double_bits: X = X * 2 bit_board = np.array( TL.FENtoBits(inp, self.Machine[0].bits, True, startingplayerbits=self.double_bits)) inp = np.reshape(bit_board, (1, X, 8, self.Machine[0].bits)) pred = self.Machine[0].Pred(inp)[0] score = self.Machine[0].Score(inp) if pred == 0: pred2 = self.Machine[1].Pred(inp)[0] score = self.Machine[1].Score(inp) if pred2 == 0: return [0, score] return [2, score] else: return [1, score]
def DataForm(self, data): tData = [] #TestData = [[],[]] #train = data[0] #test = data[1] X = 8 if self.double_bits: X = X * 2 for entry in data: reshaped = np.array( TL.FENtoBits(entry[0], self.bits, True, startingplayerbits=self.double_bits)) #print(len(reshaped)) reshaped = np.reshape(reshaped, (X, 8, self.bits)) tData.append([reshaped, entry[1]]) #print(TrainData) return tData