This simulator lets us generate dots and make them move. It's especially useful in keeping entitled cats occupied, but instead of feline neurons, we use this for fake ones. Specifically, this generates a grid for each timestep, where a specified number of points have values of
| 41 | |
| 42 | |
| 43 | class DotSimulator: |
| 44 | """ |
| 45 | This simulator lets us generate dots and make them move. |
| 46 | It's especially useful in keeping entitled cats occupied, |
| 47 | but instead of feline neurons, we use this for fake ones. |
| 48 | |
| 49 | Specifically, this generates a grid for each timestep, where a specified |
| 50 | number of points have values of 1 with fading tails ("decay"), designating |
| 51 | the current positions and movements of their corresponding dots. All other |
| 52 | points are set to 0. From timestep to timestep, the dots either remain |
| 53 | where they are or move one space. |
| 54 | |
| 55 | The 2D observation of the current state is provided every step, as well as |
| 56 | the reward, completion flag, and sucessful interception flag. It may be |
| 57 | helpful to amplify the grid values when encoding them as spike trains. |
| 58 | |
| 59 | :param t: int: number of timesteps/samples of grids with dot movements |
| 60 | :param height: int: height dimension of the grid (rows) |
| 61 | :param width: int: width dimension of the grid (columns) |
| 62 | :param decay: int: length of decaying tail behind a dot (its path history) |
| 63 | :param dots: int: number of target dots |
| 64 | :param herrs: number of distraction dots (red herrings) |
| 65 | :param pandas: Bool: print as pandas dataframe versus graphical plots |
| 66 | :param write: Bool: write grids to file to be plotted later. |
| 67 | :param mute: Bool: mute graphical rendering (can write to file or print pandas) |
| 68 | :param speed: int: set movement speed of dots. |
| 69 | :param randr: float: set the randomization rate of target movements. |
| 70 | :param allow_stay: bool: allow a dot to remain in place as a movement choice. |
| 71 | :param seed: int: optional seed for RNG in movement generation. |
| 72 | :param fname: string: optional filename for saving grids to file |
| 73 | :param fpath: string: optional file path for saving grids to file |
| 74 | :param diag: Bool: allow diagonal movement. |
| 75 | :param bound_hand: str: bounds handling when a dot reaches the world's end. |
| 76 | 'stay': dots will simply be prevented from crossing the edges. |
| 77 | 'bounce': dot positions and directions will be reflected. |
| 78 | 'trans': dot positions will be mirrored to the opposite edge. |
| 79 | :param fit_func: str: Fitness function. |
| 80 | 'euc': Single Euclidean (Pythagorean) distance value |
| 81 | 'disp': Tuple of x,y displacement values |
| 82 | 'rng' : Range rings--the closer the ring, the lower the number |
| 83 | 'dir' : directional--+1 if moving in the right direction |
| 84 | -1 if moving in the wrong direction |
| 85 | 0 if neither. |
| 86 | :param ring_size: int: set range ring size for range ring fitness function. |
| 87 | :param bullseye: int: set reward for successful intercept; default = 10.0 |
| 88 | :param teleport: Bool: teleport network dot after intercept; default = true |
| 89 | """ |
| 90 | |
| 91 | def __init__(self, t: int, **kwargs) -> None: |
| 92 | self.timesteps = t # total timesteps |
| 93 | self.ts = 0 # initialize current timestep to 0 |
| 94 | |
| 95 | """ Keyword arguments """ |
| 96 | self.h = kwargs.get("height", 28) # height dimension |
| 97 | self.w = kwargs.get("width", 28) # width dimension |
| 98 | self.decay = kwargs.get("decay", 1) # length of a dot's tail (path history) |
| 99 | self.ndots = kwargs.get("dots", 1) # Number of dots |
| 100 | self.herrs = kwargs.get("herrs", 0) # Red herrings (distractions) |