UC-Davis-molecular-computing / ppsim

Python package for simulating population protocols
MIT License
10 stars 5 forks source link

add example to README with transition probabilities #33

Open dave-doty opened 3 years ago

dave-doty commented 3 years ago

It would be good to have an example on the main README of how to specify probabilities in a transition dictionary, and also how to specify it in a Python function.

EricESeverson commented 3 years ago

There really isn't a good way to specify transition probabilities in a function, as you have to output the entire dictionary of all possible pairs of states and their probabilities. This really doesn't jive well with trying to write a pseudocode-style function where you modify the fields of agents a / b and would ideally like to write conditional probabilistic statements (like "with probability 0.5, a.minute += 1").

I never settled on a good way around this issue.

dave-doty commented 2 years ago

There really isn't a good way to specify transition probabilities in a function, as you have to output the entire dictionary of all possible pairs of states and their probabilities.

What I mean is that you can do this:

def transition(s: int, r: int):
    if s == r and s < 10:
        return { (s,s+1): 0.01 }
    else:
        return max(s,r), max(s,r)

to specify that if s and r are equal, then with probability 1% one of them increments, i.e., although you have to return a dictionary, you can "localize" it to only the part of the protocol that's randomized and just return pairs of states elsewhere. There's currently no examples like this in the README. Note the example also shows that you can make the probabilities sum to less than 1, with the interpretation that the remaining probability is assigned to the null reaction.