remove markov related checks

This commit is contained in:
filifa 2025-05-06 21:54:25 -04:00
parent cb61cd30c7
commit 6cc1de4d05
2 changed files with 0 additions and 63 deletions

View File

@ -20,7 +20,6 @@ import (
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/multi"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/topo"
"gonum.org/v1/gonum/mat"
)
@ -37,31 +36,6 @@ func NewAbsorbingMarkovChain() *AbsorbingMarkovChain {
return &AbsorbingMarkovChain{WeightedDirectedGraph: multi.NewWeightedDirectedGraph()}
}
// IsValid returns true if the graph is a valid Markov chain.
func (g *AbsorbingMarkovChain) IsValid() bool {
for nodes := g.Nodes(); nodes.Next(); {
u := nodes.Node()
if g.outWeightSum(u) != 1 {
return false
}
}
return true
}
func (g *AbsorbingMarkovChain) outWeightSum(u graph.Node) float64 {
sum := 0.0
for nodes := g.From(u.ID()); nodes.Next(); {
v := nodes.Node()
e := g.WeightedEdge(u.ID(), v.ID())
if e != nil {
sum += e.Weight()
}
}
return sum
}
// AbsorbingNodes returns all the nodes in the Markov chain identified as
// absorbing nodes.
func (g *AbsorbingMarkovChain) AbsorbingNodes() []graph.Node {
@ -83,35 +57,6 @@ func (g *AbsorbingMarkovChain) AbsorbingNodes() []graph.Node {
return absorbingNodes
}
// IsAbsorbing returns true if the Markov chain is an absorbing chain. This
// means at least one node is an absorbing node and that every node can reach
// an absorbing node.
func (g *AbsorbingMarkovChain) IsAbsorbing() bool {
absorbingNodes := g.AbsorbingNodes()
if len(absorbingNodes) == 0 {
return false
}
for nodes := g.Nodes(); nodes.Next(); {
u := nodes.Node()
if !g.canBeAbsorbed(u, absorbingNodes) {
return false
}
}
return true
}
func (g *AbsorbingMarkovChain) canBeAbsorbed(u graph.Node, absorbingNodes []graph.Node) bool {
for _, v := range absorbingNodes {
if topo.PathExistsIn(g, u, v) {
return true
}
}
return false
}
// AdjacencyMatrix returns the graph's adjacency matrix.
func (g *AbsorbingMarkovChain) AdjacencyMatrix() *mat.Dense {
adj := simple.NewDirectedMatrix(g.Nodes().Len(), 0, 0, 0)

View File

@ -64,14 +64,6 @@ func parse(cmd *cobra.Command, args []string) {
panic(err)
}
if !graph.IsValid() {
panic("not a Markov chain!")
}
if !graph.IsAbsorbing() {
panic("not an absorbing Markov chain!")
}
matrix, err := orderedAdjMatrix(graph)
if err != nil {
panic(err)