Skip to content

epswartz/stochastic-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

stochastic-simulator

A really basic markov chain simulator. For understanding, rather than for efficient processing.

Usage

    // Seed the random number gen
	rand.Seed(time.Now().UTC().UnixNano())

    // Create end states
	endState1 := model.State{
		Name: "End1",
	}
	endState2 := model.State{
		Name: "End2",
	}

    // Create probabilistic transition list for the start state
    // (end states have no transitions)
	tl := []model.Transition{
		model.Transition{
			Probability: 0.5,
			Destination: &endState1,
		},
		model.Transition{
			Probability: 0.5,
			Destination: &endState2,
		},
	}

    // Create start state
	startState := model.State{
		Name:        "Start",
		Transitions: tl,
	}

    // Create a model object, give it the start state
	m := model.Model{
		StartState: &startState,
	}

    // Run the model 10 times
    // Each run is limited to 5 steps before failure
	responses := m.RunToEnd(10, 5)
	for _, r := range responses {
		fmt.Println(r.EndState.Name, r.Err)
	}

    // If you wanted stats on where the model would end, you could then count the end states from responses

About

Markov chain simulator.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages