add function for getting absorbing states

This commit is contained in:
filifa 2025-05-02 20:24:35 -04:00
parent 241cf1a9d0
commit 0dac9efc78
1 changed files with 19 additions and 0 deletions

View File

@ -60,6 +60,25 @@ func (g *AbsorbingMarkovChain) outWeightSum(u graph.Node) float64 {
return sum 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 { func (g *AbsorbingMarkovChain) AdjacencyMatrix() mat.Matrix {
adj := simple.NewDirectedMatrix(g.Nodes().Len(), 0, 0, 0) adj := simple.NewDirectedMatrix(g.Nodes().Len(), 0, 0, 0)
for edges := g.WeightedEdges(); edges.Next(); { for edges := g.WeightedEdges(); edges.Next(); {