Skip to content

Instantly share code, notes, and snippets.

@ptn
Created January 23, 2012 13:47
Show Gist options
  • Save ptn/1663209 to your computer and use it in GitHub Desktop.
Save ptn/1663209 to your computer and use it in GitHub Desktop.
class MarkovChain
def initialize(states, transitions=nil)
@states = states
@graph = empty_graph
@transitions = build_transitions(transitions) if transitions
end
def transitions=(transitions)
@graph = empty_graph
@transitions = build_transitions(transitions) if transitions
end
private
def build_transitions(transitions)
count_transitions transitions
normalize transitions
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment