This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from enum import Enum | |
def strip_C_comments(code: str) -> str: | |
""" | |
This function strips out C style /* comments */ from code | |
It is Pythonic and 100x faster than strip_by_char | |
:param code: the code to be parsed for comments | |
:return: code without comments | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NeuralNet: | |
"""edited for brevity """ | |
def feedforward(self): | |
prev_a = self.inputs | |
for layer in self.layers: | |
layer.z = layer.W.dot(prev_a) + layer.b | |
if layer is not self.layers[-1]: # don't apply relu to last layer | |
layer.a = self.ReLU(layer.z) | |
prev_a = layer.a | |
else: # last layer is a prob distribution + a value in [-1, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MCTS: | |
def __init__(self, c=1.0): | |
self.c = c # level of exploration. Higher for self-play | |
# "Each edge stores a set of statistics" | |
# We will use a defaultdict for the mappings | |
self.Nsa = defaultdict(int) # visit count | |
self.Wsa = defaultdict(float) # total action value | |
self.Qsa = defaultdict(float) # mean action value |