-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graphical visualization of Categoricals using Spark Notebook #23
Comments
error on cell 11: :17: error: not found: value dk In [6]: :local-repo /tmp/snb/repo res10: String = Repo changed to /tmp/snb/repo! Out[6]: :remote-repo sonasnap % default % res11: String = Remote repo added: sonasnap % default % Out[7]: :dp com.github.danielkorzekwa % bayes-scala_2.11 % 0.5-SNAPSHOT warning: there were 2 feature warning(s); re-run with -feature for details Out[10]: In [11]: import notebook.front.third.d3._ import notebook., front., widgets._ import notebook.JsonCodec._ import play.api.libs.json._ import dk.bayes.dsl.variable.Categorical import dk.bayes.dsl.infer type CategoricalWithInfo = (String, Categorical, Seq[String]) val loadedCode = { val source = scala.io.Source.fromURL(" val res = source.mkString source.close() res } import play.api.libs.json._ import play.api.libs.functional.syntax._ import dk.bayes.dsl.variable.Categorical import dk.bayes.dsl.infer case class ConditionalProbabilityTable(node: BnNode, parents: Seq[BnNode], case class BnNode(name: String, states: Seq[String], currentState: case class BnEdge(source: Int, target: Int) def categoricalsToNetwork(marginalizer: Categorical => Seq[Double], import breeze.linalg._ import breeze.numerics._ val nodes = categoricalsWithNames.map { case(name, categorical, states) =>
} val categoricals = categoricalsWithNames.map(_._2) val nodeMap = categoricals.zip(nodes).toMap val cpts = categoricals.zip(nodes).map { case(cat, node) =>
ConditionalProbabilityTable(node, Seq(), inferredCpd.toArray)) } val edges = nodeMap.flatMap { case(cat, node) =>
}.toSeq (nodes.zip(cpts).map { case(n, (c, m)) => (n, c, m)}, edges) } object ConditionalProbabilityTable { implicit val conditionalProbabilityTableWrites: } object BnNode { implicit val nodeWrites: Writes[BnNode] = Json.writes[BnNode] } object BnEdge { implicit val edgeWrites: Writes[BnEdge] = Json.writes[BnEdge] } def networkToJson(nodesWithCpts: Seq[(BnNode, ConditionalProbabilityTable, val nodeJs = nodesWithCpts.map { case(node, cpt, marginalized) =>
("marginalized", Json.toJson(marginalized)) } Json.obj("nodes" -> Json.toJson(nodeJs), "edges" -> Json.toJson(edges)) } val convertCategoricals: Seq[CategoricalWithInfo] => JsObject = implicit val categoricalsCodec = new Codec[JsValue, def encode(x:JsValue):Seq[CategoricalWithInfo] = Seq() def decode(x:Seq[CategoricalWithInfo]):JsValue = convertCategoricals(x) } val playgroundCode = s""" function(dataPipe, e) { $loadedCode var bnGraph = BayesianNetworkGraph(e) bnGraph(this.dataInit[0]) dataPipe.subscribe(function(d) {
}) } """ () :17: error: not found: value dk On 9 April 2015 at 21:44, Martin Mauch [email protected] wrote:
Daniel Korzekwa |
Ah, you're probably using the Scala 2.10 download of spark-notebook, right? |
@nightscape you're right man, @danielkorzekwa if you want you can also clone the current master branch and use it right away. |
Works for me, graphs are generated. |
Hi Daniel,
I've finally managed to create a visualization for Bayesian Networks constructed from Categoricals.
Check out the README of the Gist here:
https://gist.github.com/nightscape/c2fcccac859b3ae34c99#file-readme-md
Could you check if it runs on your machine?
If so we can think about how to maybe integrate this into bayes-scala :)
Best and thanks again for your help!
Martin
The text was updated successfully, but these errors were encountered: