Skip to content

Commit 7aa2bc3

Browse files
committed
add graphviz output
1 parent d582133 commit 7aa2bc3

File tree

6 files changed

+52
-12
lines changed

6 files changed

+52
-12
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ addons:
1515
env:
1616
- ARGS="--resolver lts"
1717
- ARGS="--resolver nightly"
18-
## - ARGS="--resolver lts-11.5"
1918
- ARGS="--resolver lts-12.14"
2019
- ARGS="--resolver nightly-2019-08-04"
2120

app/Main.hs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{-# language OverloadedStrings #-}
2+
module Main where
3+
4+
import Numeric.Statistics.Inference.Bayes.Exact.VariableElimination (student)
5+
6+
import Algebra.Graph.Export (Doc, literal, render, export)
7+
import Algebra.Graph (Graph)
8+
9+
import qualified Data.Text as T
10+
import qualified Data.Text.IO as T (writeFile)
11+
12+
13+
-- vDoc x = literal (show x) <> "\n"
14+
-- eDoc x y = literal (show x) <> " -> " <> literal (show y) <> "\n"
15+
16+
vDoc x = literal [x] <> ";\n"
17+
eDoc x y = literal [x] <> " -> " <> literal [y] <> ";\n"
18+
19+
withDigraph :: String -> Doc String -> Doc String
20+
withDigraph name body =
21+
literal (unwords ["digraph", name, "{\n"]) <>
22+
body <>
23+
literal "}\n"
24+
25+
main :: IO ()
26+
main = T.writeFile "graph.example.student.dot" $
27+
T.pack $ render $ withDigraph "student" $ export vDoc eDoc student

bayesian-inference.cabal

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ library
4646
, hspec
4747
, QuickCheck
4848

49+
executable graph-export
50+
default-language: Haskell2010
51+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
52+
hs-source-dirs: app
53+
main-is: Main.hs
54+
build-depends: base
55+
, bayesian-inference
56+
, algebraic-graphs
57+
, text
58+
4959
test-suite spec
5060
default-language: Haskell2010
5161
ghc-options: -Wall
@@ -70,14 +80,14 @@ test-suite doctest
7080
, doctest
7181
, exceptions
7282

73-
test-suite property
74-
default-language: Haskell2010
75-
ghc-options: -Wall
76-
type: exitcode-stdio-1.0
77-
hs-source-dirs: test
78-
main-is: Property.hs
79-
build-depends: base
80-
, bayesian-inference
83+
-- test-suite property
84+
-- default-language: Haskell2010
85+
-- ghc-options: -Wall
86+
-- type: exitcode-stdio-1.0
87+
-- hs-source-dirs: test
88+
-- main-is: Property.hs
89+
-- build-depends: base
90+
-- , bayesian-inference
8191

8292
source-repository head
8393
type: git

makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
graph-render:
2+
stack build
3+
stack exec -- graph-export
4+
dot -Tps graph.example.student.dot -o graph.example.student.ps

src/Numeric/Statistics/Inference/Bayes/Exact/VariableElimination.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fromList :: (Foldable t, Monad m) => t a -> Lex m (IM.IntMap a)
7777
fromList xs = foldlM (flip insert) IM.empty xs
7878

7979
-- | sequential sum-product elimination of graph factors
80-
--
80+
--
8181
-- >>> elims student "cdihg"
8282
-- fromList [(5,{ 'j' 'l' 's' }),(12,{ 'j' 'l' 's' })]
8383
elims :: (Monad m, TG.ToGraph g, Foldable t, Ord (TG.ToVertex g)) =>

test/DocTest.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module Main where
22

33
import Test.DocTest (doctest)
44

5-
5+
main :: IO ()
66
main = doctest [
7-
"test/Bayes/Exact/VariableElimination.hs"
7+
"src/Numeric/Statistics/Inference/Bayes/Exact/VariableElimination.hs"
88

99
]

0 commit comments

Comments
 (0)