Created
February 15, 2013 08:47
-
-
Save jeroenvandijk/4959201 to your computer and use it in GitHub Desktop.
simple example of visualizing prismatic graphs with graphviz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[plumbing.core :refer [fnk]]) | |
(require '[plumbing.graph :as graph]) | |
(defn calculate-deps [f] | |
(map (fn [parent] [parent (first f)]) (-> f second meta first second first keys))) | |
(defn print-dot [graph] | |
(println (clojure.string/join "\n" | |
(map (fn [r] (str "\""(first r) "\" -> \"" (second r) "\";")) | |
(mapcat (fn [k] (calculate-deps k)) (graph/->graph graph)))))) | |
;; Example graph | |
(def stats-graph | |
"A graph specifying the same computation as 'stats'" | |
{:n (fnk [xs] (count xs)) | |
:m (fnk [xs n] (/ (+ identity xs) n)) | |
:m2 (fnk [xs n] (/ (+ #(* % %) xs) n)) | |
:v (fnk [m m2] (- m2 (* m m)))}) | |
(print-dot stats-graph) | |
; Outputs this: | |
; | |
; digraph "example" { | |
; ":xs" -> ":n"; | |
; ":xs" -> ":m"; | |
; ":n" -> ":m"; | |
; ":xs" -> ":m2"; | |
; ":n" -> ":m2"; | |
; ":m2" -> ":v"; | |
; ":m" -> ":v"; | |
; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment