preliminary fixes/removed typos, etc.
This commit is contained in:
25
bn_sim.py
25
bn_sim.py
@@ -1,4 +1,5 @@
|
||||
from itertools import product
|
||||
from random import random
|
||||
|
||||
funcs = [
|
||||
lambda x1, x2, x3, x4: not x2,
|
||||
@@ -14,6 +15,13 @@ sequential_sync_funcs = [
|
||||
lambda x1, x2, x3, x4: (not x2) ^ x4,
|
||||
]
|
||||
|
||||
probabilistic_funcs = [
|
||||
(1, funcs[0], None),
|
||||
(1, funcs[1], None),
|
||||
(1, funcs[2], None),
|
||||
(0.5, funcs[3], lambda x1, x2, x3, x4: not x3),
|
||||
]
|
||||
|
||||
|
||||
nodes = []
|
||||
|
||||
@@ -39,6 +47,17 @@ def sequential_update(order):
|
||||
nodes[i] = funcs[i](*nodes)
|
||||
|
||||
|
||||
def probabilistic_update():
|
||||
global nodes, probabilistic_funcs
|
||||
funcs = probabilistic_funcs
|
||||
temp = nodes.copy()
|
||||
for i in range(len(funcs)):
|
||||
probability, *nodeFuncs = funcs[i]
|
||||
func = nodeFuncs[0] if probability >= random() else nodeFuncs[1]
|
||||
temp[i] = func(*nodes)
|
||||
nodes = temp
|
||||
|
||||
|
||||
def state_to_str():
|
||||
return "".join(str(int(i)) for i in nodes)
|
||||
|
||||
@@ -61,14 +80,16 @@ def get_table():
|
||||
|
||||
|
||||
def update():
|
||||
return synchronous_update()
|
||||
return sequential_update([0, 1, 2, 3])
|
||||
# return synchronous_update()
|
||||
# return sequential_update([0, 1, 2, 3])
|
||||
return probabilistic_update()
|
||||
# return block_sequential_update(...)
|
||||
# return asynchronous_deterministic_update(...)
|
||||
|
||||
|
||||
def main():
|
||||
get_table()
|
||||
# simulate([0,0,0,0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user