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

Feature edge_info=none #147

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

JackStorrorCarter
Copy link
Collaborator

Added the option to include no edge info when drawing et, st or ceg (so that event description is displayed, but edge counts are not). Tested the change locally and all works well.

Also updated the parameter lists to reflect this change to appear in the documentation (and made the edge_info description uniform over different functions).

Updated _generate_dot_graph with edge_info == "none"
Updated _generate_dot_graph with edge_info == "none"
Update parameter description for documentation
Updated parameter description for documentation
Update parameter description for documentation
Update parameter description for documentation
Copy link
Collaborator

@ashenvi10 ashenvi10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope the comments make sense. If not, please let me know :)

@@ -190,11 +190,9 @@ def _merge_nodes(self, nodes_to_merge: List[Tuple[str]]):

def dot_graph(self, edge_info: str = "probability") -> pdp.Dot:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def dot_graph(self, edge_info: str = "probability") -> pdp.Dot:
def dot_graph(self, edge_info: Literal["count", "prior", "posterior", "probability"] | None = "probability") -> pdp.Dot:

Literal["count", "prior", "posterior", "probability"] -- this says that only "count", "prior", "posterior" or "probability" are acceptable input parameters.

| -- this means "or"

None -- None is its own type in Python, and so we shouldn't be using "none" as a string.

With the above setting, the user will need to explicitly pass None for no information to be displayed.
Alternatively, we can make None the default, so the user needs to explicitly pass one of the acceptable string entries for any information to be displayed.

What do you think?

Comment on lines 207 to 213
for (src, dst, label), attribute in edge_info_dict.items():
if edge_info == "count":
edge_details = str(label) + "\n" + str(attribute)
elif edge_info == "none":
edge_details = str(label)
else:
edge_details = f"{label}\n{float(attribute):.2f}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (src, dst, label), attribute in edge_info_dict.items():
if edge_info == "count":
edge_details = str(label) + "\n" + str(attribute)
elif edge_info == "none":
edge_details = str(label)
else:
edge_details = f"{label}\n{float(attribute):.2f}"
for (src, dst, label), attribute in edge_info_dict.items():
if not edge_info:
edge_details = str(label)
elif edge_info == "count":
edge_details = str(label) + "\n" + str(attribute)
else:
edge_details = f"{label}\n{float(attribute):.2f}"

These are the changes we'd need to make if using None. The truth value of a None type is always False and for a non-None type will be True. So checking it as if not edge_info will only be True when edge_info is None. Let me know if doesn't make sense and I'll give a better example

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to do this:

        edge_details = str(label)        
        for (src, dst, label), attribute in edge_info_dict.items():

            if edge_info == "count":
                edge_details = edge_details + "\n" + str(attribute)
            else:
                edge_details = f"{edge_details}\n{float(attribute):.2f}"

Since edge_details always include str(label), you can add initialise the edge_details variable with the label and then don't need to explicitly check for the None case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as in src/cegpy/graphs/_ceg.py

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as in src/cegpy/graphs/_ceg.py

@JackStorrorCarter
Copy link
Collaborator Author

Good point about not using 'none'. How about changing to 'no info' instead? I think keeping the edge counts/probabilities as default is best - I just wanted the 'no info' option as a niche case where you display a CEG without referencing a specific dataset

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

Successfully merging this pull request may close these issues.

2 participants