Skip to content
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

plot.HydeNetwork() defaults for decision nets #37

Closed
jarrod-dalton opened this issue Apr 25, 2015 · 5 comments
Closed

plot.HydeNetwork() defaults for decision nets #37

jarrod-dalton opened this issue Apr 25, 2015 · 5 comments

Comments

@jarrod-dalton
Copy link
Collaborator

Here is some code that uses separate node shapes/colors depending on the type (random vs. determ vs. decision vs. utility). I didn't do anything with the edges yet. Any ideas on edge coloring? May be good to somehow gray out edges associated with deterministic nodes.

By the way, ignore the actual formulas in the setNode commands - I just did those commands so I could color the deterministic nodes.

net <- HydeNetwork(~ card1.ace | card1
                   + card2.ace | card2
                   + initialPoints | card1*card2*card1.ace*card2.ace
                   + hit1 | initialPoints*dealerUpcard
                   + card3 | hit1
                   + card3.ace | card3
                   + pointsAfterCard3 | initialPoints*card3*card3.ace
                   + hit2 | pointsAfterCard3*dealerUpcard
                   + card4 | hit2
                   + card4.ace | card4
                   + pointsAfterCard4 | pointsAfterCard3*card4*card4.ace
                   + hit3 | pointsAfterCard4*dealerUpcard
                   + card5 | hit3
                   + card5.ace | card5
                   + pointsAfterCard5 | pointsAfterCard4*card5*card5.ace
                   + playerFinalPoints | initialPoints*hit1*pointsAfterCard3
                                         *hit2*pointsAfterCard4*hit3*pointsAfterCard5
                   + dealerFinalPoints | dealerUpcard
                   + payoff | playerFinalPoints*dealerFinalPoints)

net <- setNode(net, card1.ace, "determ", define=fromFormula(), nodeFormula=card1.ace ~ ifelse(card1==1,1,0))
net <- setNode(net, card2.ace, "determ", define=fromFormula(), nodeFormula=card2.ace ~ ifelse(card2==1,1,0))
net <- setNode(net, card3.ace, "determ", define=fromFormula(), nodeFormula=card3.ace ~ ifelse(card3==1,1,0))
net <- setNode(net, card4.ace, "determ", define=fromFormula(), nodeFormula=card4.ace ~ ifelse(card4==1,1,0))
net <- setNode(net, card5.ace, "determ", define=fromFormula(), nodeFormula=card5.ace ~ ifelse(card5==1,1,0))
net <- setNode(net, initialPoints, "determ", define=fromFormula(), nodeFormula=initialPoints~card1+card2)
net <- setNode(net, pointsAfterCard3, "determ", define=fromFormula(),
               nodeFormula=pointsAfterCard3 ~ initialPoints+card3)
net <- setNode(net, pointsAfterCard4, "determ", define=fromFormula(),
               nodeFormula=pointsAfterCard4 ~ pointsAfterCard3+card4)
net <- setNode(net, pointsAfterCard5, "determ", define=fromFormula(),
               nodeFormula=pointsAfterCard5 ~ pointsAfterCard4+card5)
net <- setNode(net, playerFinalPoints, "determ", define=fromFormula(),
               nodeFormula=playerFinalPoints ~ playerFinalPoints+3)


net <- setDecisionNodes(net, hit1, hit2, hit3)
net <- setUtilityNodes(net, payoff)

decisionNodes <- names(which(unlist(net$nodeDecision)))
utilityNodes <- "payoff"  #names(which(unlist(net$nodeDecision)))
determNodes <- names(which(unlist(net$nodeType)=="determ"))

shapes <- rep("box",length(decisionNodes)+length(utilityNodes));
names(shapes) <- c(decisionNodes, utilityNodes)

fills <- c(rep("cyan",length(decisionNodes)), rep("yellow",length(utilityNodes)))
names(fills) <- c(decisionNodes, utilityNodes)

fontcols <- rep("gray70", length(determNodes))
names(fontcols) <- c(determNodes)

cols <- rep("gray70",length(determNodes));
names(cols) <- determNodes

nodeAttribs <- list(shape=shapes, fillcolor=fills, fontcolor=fontcols, color=cols)

attribs <- list(node=list(shape="ellipse", fixedsize=FALSE, fillcolor="white", style="solid"))

plot(net, attrs=attribs, nodeAttrs=nodeAttribs)

image

nutterb added a commit that referenced this issue Apr 25, 2015
Begins to address Issue #37.
@nutterb
Copy link
Owner

nutterb commented Apr 25, 2015

I added default plot settings in the options(Hyde_plotOptions), but I still need to do a little tweaking. I'll need to add a new function to modify the options that isn't as tedious as setting all the node attributes.

nutterb added a commit that referenced this issue May 1, 2015
Builds more on Issue #37 but allows the user to change the default
settings.  Next up, customizing individual nodes.
nutterb added a commit that referenced this issue May 1, 2015
Finalizes improvements for Issue #37
@nutterb nutterb closed this as completed May 1, 2015
@nutterb
Copy link
Owner

nutterb commented May 1, 2015

Given the new functionality for customizing plots with plot.HydeNetwork, do we still need to keep the plot.compiledHydeNetwork method? On the one hand, we could apply the default plotting mechanism and just alter the observed variables. On the other, it isn't hard to do that from plot.HydeNetwork anymore.

Thoughts?

@jarrod-dalton
Copy link
Collaborator Author

Good point. I guess I hadn't thought about the issue with observed vs. unobserved nodes. It's hard to think about formatting all these different node classes with only 2 shapes supported by the Rgraphviz API (I know the Graphviz software has several more shapes):

Random observed/unobserved
Decision observed/unobserved
Deterministic evaluated or not evaluated (could combine those two, i.e., keep with the gray presentation - I like it)
Utility (could keep with the present visualization)

If we were to consider observed nodes as separate formats, couldn't that be incorporated into the new functionality instead of via plot.compiledHydeNetwork? In this case, it would be nice, but probably I'd recommend we create a separate issue for this and do this on a later release.

One thing that should probably be a default is the global attribute fixedsize=FALSE.

@nutterb
Copy link
Owner

nutterb commented May 2, 2015

So, I think I'm going to go ahead and delete plot.compiledHydeNetwork for now. My reasoning is this:

I think I can build a better functionality using the DiagrammeR package. I've played with it some, and it looks an awful lot better and should be quite a bit easier to manipulate than the Rgraphviz stuff. For the moment, everything is working as expected, and even if it takes me a little while to get the DiagrammeR plotting to work, I can work all of the new stuff into the existing framework.

So, the take home message is that I will reconstruct this function when I finish plot.HydeNetwork. It will be easier to modify the plot for the compiled network using the HydeNetwork method.

@nutterb nutterb reopened this May 2, 2015
@jarrod-dalton
Copy link
Collaborator Author

DiagrammeR looks awesome!

Let's leave this issue open and revisit default node styles. Let's wait on this until after the v1.0 release.

Open to suggestions re: the default formats, but here's a possibility (based on http://www.graphviz.org/doc/info/shapes.html):

nodeType shape border text textWhenObserved font style (if it exists?)
random variable rounded black black red regular
deterministic plaintext transparent (ignored for plaintext?) gray light red italics
decision hexagon or doubleoctagon blue blue red bold
utility invhouse green (something darker than rgb(0,1,0)) green red bold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants