def fitModel(self, plus_one, plus_two): y = 0 #weights are updated in regard to final game result if self.done: #and average of estimation two nodes after them in an y = self.true_eval #attempt to smoothen the graph of estimated values else: #during the game y = f64( plus_one + plus_two ) / 2 #weights are also updated based on true eval when possible self.data_in.append(self.b.getNumpyArray()) self.exp_data.append([y]) if self.father == None: self.model.fit(array(self.data_in), array(self.exp_data), epochs=1, verbose=0) self.exp_data = [] self.data_in = [] print('weights updated') return for brother in self.father.sons: #also, weights are trained to minimize the difference between if brother is not self: #estimated probabilities and probabilities calculated by mtcs self.data_in.append(brother.b.getNumpyArray()) self.exp_data.append([brother.prob01()]) self.father.fitModel(self.estimate, y)
def show(self): #visual representation of a node print('visits: ', end='') print(self.visits, end=' ') print('chances: ', end='') print(f64(self.score) / self.visits, end=' ') print('done: ', end='') print(self.done, end=' ') print('estimate: ', end='') print(self.estimate)
def chose(self): #basicaly min/max chances = [] for son in self.sons: if son.visits == 0: son.monte() if son.done: chances.append(son.true_eval) else: chances.append(f64(son.score) / son.visits) if self.b.side == 1: return argmax(chances) else: return argmin(chances)
def fill_center(self, shape, hex_radius=250, ang_offset=0, center=None, radius=None, auto=min): """Fills an array with circular hexagons""" self.logger.log("Filling the array with hexagons") try: w, h = shape if center is None: center = [int(w / 2), int(h / 2)] if radius is None: radius = auto(center[0], center[1], w - center[0], h - center[1]) each_dist = hex_radius * sqrt(3) / 2 ring_number = ceil(radius / (2 * hex_radius)) number_of_hexs = ar(range(0, ring_number + 1)) * 6 number_of_hexs[0] = 1 for it, number_of_hex in enumerate(number_of_hexs): angle = f64((360 / number_of_hex) % 360) R = it * 2 * each_dist for the_hex in range(number_of_hex): each_ang = the_hex * angle + ang_offset if each_ang % 60 == 0: r = R else: r = ((sqrt(3) / 2) * R) / cos( deg2rad(30 - each_ang % 60)) x = r * cos(deg2rad(each_ang)) y = r * sin(deg2rad(each_ang)) hpoints = self.__hexagon_creator__( [center[0] + x, center[1] + y], hex_radius, ang_offset=0) yield tuple(map(tuple, hpoints)) except Exception as excpt: self.logger.log(excpt)
def usb1(self): #how you pick which path to pay a visit if self.visits == 0: #state of art balance between exploration and exploitation return inf * self.father.b.side return (f64(self.score) / self.visits) + self.father.b.side * e * sqrt( 2 * f64(log(self.father.visits)) / self.visits)
def prob01(self): #return probability of winning based on mcts return f64(self.score) / self.visits
import collections from numpy import float64 as f64 from dataclasses import dataclass from reggae.utilities import inverse_positivity, logit import numpy as np GenericResults = collections.namedtuple('GenericResults', [ 'target_log_prob', 'is_accepted', 'acc_iter', ], defaults=[(f64(0), f64(0))]) MixedKernelResults = collections.namedtuple( 'MixedKernelResults', [ 'inner_results', # 'grads_target_log_prob', # 'step_size', # 'log_accept_ratio', 'is_accepted', 'iteration', ]) @dataclass class SampleResults: options: object fbar: object kbar: object k_fbar: object