-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from kcelebi/dev
Reinforcement Learning for CA implemented
- Loading branch information
Showing
10 changed files
with
640 additions
and
115 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ pytest | |
numpy | ||
pandas | ||
matplotlib | ||
pathlib | ||
pathlib | ||
tqdm |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import numpy as np | ||
|
||
import sys | ||
sys.path.append('../') | ||
|
||
from path_handler import PathHandler as PH | ||
import sim.automata as atm | ||
from sim.rules import Rules | ||
|
||
class State: | ||
|
||
def __init__(self, state, rule): | ||
self.values = state | ||
self.rule = rule | ||
|
||
self._shape = self.values.shape | ||
|
||
# fix this dogshit hash function | ||
def __hash__(self): | ||
return hash(self.values.tostring()) | ||
|
||
def __repr__(self): | ||
return self.values.__repr__() | ||
|
||
def copy(self): | ||
return State(self.values, self.rule) | ||
|
||
@property | ||
def shape(self): | ||
return self.values.shape | ||
|
||
@property | ||
def flat(self): | ||
return self.values.flat | ||
|
||
|
||
''' | ||
Generate successor states based on given action | ||
''' | ||
def get_successor(self, action): | ||
new_state = self.values.copy() | ||
new_state[action // self.values.shape[1], action % self.values.shape[1]] = 1 | ||
new_state = atm.update(new_state, rule = self.rule) | ||
|
||
return State(new_state, rule = self.rule) |
Oops, something went wrong.