Pykov icon indicating copy to clipboard operation
Pykov copied to clipboard

Choose function throws error

Open blue-note opened this issue 9 years ago • 1 comments

File "/Library/Python/2.7/site-packages/pykov.py", line 1087, in walk result.append(self.move(result[-1])) File "/Library/Python/2.7/site-packages/pykov.py", line 925, in move return self.succ(state).choose(random_func) File "/Library/Python/2.7/site-packages/pykov.py", line 314, in choose return state UnboundLocalError: local variable 'state' referenced before assignment

blue-note avatar Feb 07 '16 20:02 blue-note

I believe that the root of this error is in Chain.walk(). When called without a start state, the start state is chosen from the steady state according to the probabilities there. If there isn't a steady state, i.e. the steady Vector is empty, then .choose() throws an error after its for loop here.

This could be fixed by adding a line in .walk() to select a (uniformly) random state from the list of all states if the steady state vector is empty. That would probably be a good idea, since random walks can be performed on chains without steady states as well.

Is there any preference for another fix?

rdbliss avatar Dec 07 '16 22:12 rdbliss