From 6cc1de4d05b340f98972e818ce8e909a820ade9e Mon Sep 17 00:00:00 2001 From: filifa Date: Tue, 6 May 2025 21:54:25 -0400 Subject: [PATCH] remove markov related checks --- cmd/internal/markov/absorbing.go | 55 -------------------------------- cmd/root.go | 8 ----- 2 files changed, 63 deletions(-) diff --git a/cmd/internal/markov/absorbing.go b/cmd/internal/markov/absorbing.go index f730c0c..eaa1c57 100644 --- a/cmd/internal/markov/absorbing.go +++ b/cmd/internal/markov/absorbing.go @@ -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) diff --git a/cmd/root.go b/cmd/root.go index ae3db71..290f86c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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)