add function for getting absorbing states
This commit is contained in:
parent
241cf1a9d0
commit
0dac9efc78
|
@ -60,6 +60,25 @@ func (g *AbsorbingMarkovChain) outWeightSum(u graph.Node) float64 {
|
|||
return sum
|
||||
}
|
||||
|
||||
func (g *AbsorbingMarkovChain) AbsorbingNodes() []graph.Node {
|
||||
absorbingNodes := make([]graph.Node, 0)
|
||||
for nodes := g.Nodes(); nodes.Next(); {
|
||||
u := nodes.Node()
|
||||
successors := g.From(u.ID())
|
||||
if successors.Len() != 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
successors.Next()
|
||||
v := successors.Node()
|
||||
if u == v {
|
||||
absorbingNodes = append(absorbingNodes, u)
|
||||
}
|
||||
}
|
||||
|
||||
return absorbingNodes
|
||||
}
|
||||
|
||||
func (g *AbsorbingMarkovChain) AdjacencyMatrix() mat.Matrix {
|
||||
adj := simple.NewDirectedMatrix(g.Nodes().Len(), 0, 0, 0)
|
||||
for edges := g.WeightedEdges(); edges.Next(); {
|
||||
|
|
Loading…
Reference in New Issue