-
Notifications
You must be signed in to change notification settings - Fork 0
Make two node example graph #16
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
03a751f
start working on node that store distributions
mscroggs ddb7d52
refactor graph, add add_node and add_edge methods
mscroggs e8a4592
get multiple samples at onde
mscroggs d7c5a60
parametrise test
mscroggs bd50473
make two distribution example
mscroggs 02695eb
Merge branch 'main' into mscroggs/normal-example
mscroggs e78a06c
Merge branch 'main' into mscroggs/normal-example
mscroggs bbe9284
| None
mscroggs 0a9a7b2
remove irrelevant nodes from test
mscroggs 711ca46
add stdev to test
mscroggs e460f4f
Update src/causalprog/graph/graph.py
mscroggs ef667db
Update src/causalprog/graph/graph.py
mscroggs 87fa819
make roots_down_to_outcome a method of the graph
mscroggs df339e7
Merge branch 'mscroggs/normal-example' of github.com:UCL/causalprog i…
mscroggs 4b457fc
Update src/causalprog/graph/graph.py
mscroggs b222449
default false
mscroggs ac5dbdc
Merge branch 'mscroggs/normal-example' of github.com:UCL/causalprog i…
mscroggs fa7bfe7
don't allow temporary None labels
mscroggs ed93108
simpler test
mscroggs ed02c31
improve tests, and simplify iteration code
mscroggs cc2f1ec
reduce number of tests
mscroggs 8c01b7d
number of samples must be int, don't use 0 for mean so that relative …
mscroggs 6797f4e
Update src/causalprog/graph/graph.py
mscroggs 874d100
Update src/causalprog/graph/graph.py
mscroggs df45fea
Update tests/test_graph.py
mscroggs dbc481e
Update src/causalprog/_abc/labelled.py
mscroggs d5cc428
indentation
mscroggs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""causalprog package.""" | ||
|
||
from . import graph | ||
from . import algorithms, distribution, graph, utils | ||
from ._version import __version__ |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""Algorithms.""" | ||
|
||
from .expectation import expectation, standard_deviation |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Algorithms for estimating the expectation and standard deviation.""" | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
from causalprog.graph import Graph | ||
|
||
|
||
def sample( | ||
graph: Graph, | ||
outcome_node_label: str | None = None, | ||
samples: int = 1000, | ||
) -> npt.NDArray[float]: | ||
"""Sample data from a graph.""" | ||
if outcome_node_label is None: | ||
outcome_node_label = graph.outcome.label | ||
|
||
nodes = graph.roots_down_to_outcome(outcome_node_label) | ||
|
||
values: dict[str, npt.NDArray[float]] = {} | ||
for node in nodes: | ||
values[node.label] = node.sample(values, samples) | ||
return values[outcome_node_label] | ||
|
||
|
||
def expectation( | ||
graph: Graph, | ||
outcome_node_label: str | None = None, | ||
samples: int = 1000, | ||
) -> float: | ||
"""Estimate the expectation of a graph.""" | ||
return sample(graph, outcome_node_label, samples).mean() | ||
|
||
|
||
def standard_deviation( | ||
graph: Graph, | ||
outcome_node_label: str | None = None, | ||
samples: int = 1000, | ||
) -> float: | ||
"""Estimate the standard deviation of a graph.""" | ||
return np.std(sample(graph, outcome_node_label, samples)) |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Creation and storage of graphs.""" | ||
|
||
from .graph import Graph | ||
from .node import DistributionNode, RootDistributionNode | ||
from .node import DistributionNode, Node |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.