stochastic-simulator
所属分类:数值算法/人工智能
开发工具:GO
文件大小:4KB
下载次数:0
上传日期:2020-12-17 19:36:04
上 传 者:
sh-1993
说明: 随机模拟器、马尔可夫链模拟器。
(Markov chain simulator.
,)
文件列表:
main.go (709, 2020-12-18)
pkg (0, 2020-12-18)
pkg\model (0, 2020-12-18)
pkg\model\model.go (3958, 2020-12-18)
pkg\util (0, 2020-12-18)
pkg\util\float.go (157, 2020-12-18)
# 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
```
近期下载者:
相关文件:
收藏者: