-
Notifications
You must be signed in to change notification settings - Fork 23
scratch of structure learning for discrete bn #128
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
base: 2.0.0
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR lays the groundwork for structure learning for discrete Bayesian networks by updating several constructors, method signatures, and import paths throughout the codebase. Key changes include:
- Changes to method signatures for node and optimizer classes to include a mandatory name parameter.
- Transition from str to repr in several classes to standardize object representations.
- Updates to import paths for improved package structure and relative imports.
Reviewed Changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| bamt/dag_optimizers/dag_optimizer.py | Updated the abstract optimize method signature to include additional parameters. |
| bamt/core/nodes/root_nodes/root_node.py | Modified constructor to require a name and changed str to repr. |
| bamt/core/nodes/root_nodes/discrete_node.py | Adjusted constructor signature, updated super().init usage, and modified string representation. |
| bamt/core/nodes/root_nodes/continuous_node.py | Revised import statements to relative imports. |
| bamt/core/nodes/node.py | Updated Node constructor to accept a name and initialized parent and children lists. |
| bamt/core/nodes/child_nodes/* | Modified constructors to include a name parameter and added repr methods. |
| bamt/core/node_models/* | Adjusted str to repr across distribution classes and fixed import paths. |
| bamt/core/graph/* | Updated the Graph and DAG classes with additional methods and revised node/edge handling. |
| bamt/checkers/* | Implemented or updated node and network checkers with new node type validations and error handling. |
Comments suppressed due to low confidence (3)
bamt/dag_optimizers/dag_optimizer.py:9
- The optimize method signature was updated to include data, scorer, and an optional formatter. Ensure that all subclass implementations and corresponding documentation are updated accordingly.
def optimize(self, data, scorer, formatter=None):
bamt/core/nodes/root_nodes/root_node.py:19
- The method has been renamed from str to repr. Make sure that both documentation and any external calls to the string representation are updated to use repr.
def __repr__(self):
bamt/core/nodes/root_nodes/discrete_node.py:9
- Typo in 'DisscreteNode'; consider correcting it to 'DiscreteNode'.
Initialize the DisscreteNode with an optional EmpiricalDistribution.
| return True if self.node_type in [RawNodeType, RawNodeType.disc_num] else False | ||
|
|
Copilot
AI
Apr 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for discrete node appears incorrect by including the entire RawNodeType enum; consider using a specific member (e.g., RawNodeType.disc) instead of RawNodeType.
| return True if self.node_type in [RawNodeType, RawNodeType.disc_num] else False | |
| return True if self.node_type in [RawNodeType.disc, RawNodeType.disc_num] else False |
| if isinstance(arg, str): | ||
| arg = enumerator(arg) | ||
| if arg not in self.node_type.__class__: | ||
| assert TypeError("Wrong type of argument.") |
Copilot
AI
Apr 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 'assert' with an exception instance is incorrect; replace it with 'raise TypeError("Wrong type of argument.")' to properly signal the error.
| assert TypeError("Wrong type of argument.") | |
| raise TypeError("Wrong type of argument.") |
This pull request introduces several significant changes to the
bamtpackage, focusing on enhancing the functionality and structure of the checker classes, graph classes, and node models. The most important changes include the creation of new checker classes, updates to the graph structure, and improvements to the node models.Checker Classes Enhancements:
bamt/checkers/base.py: Introduced theCheckerclass, which includes methods for validating arguments and initializing node types.bamt/checkers/network_checker.py: Added theNetworkCheckerclass, which extendsCheckerand includes methods for checking network restrictions, validating loads, and determining node types.bamt/checkers/node_checkers.py: CreatedRawNodeCheckerandNodeCheckerclasses to handle raw and evolved node types, respectively. These classes include properties for checking node types and validation methods.Graph Structure Updates:
bamt/core/graph/dag.py: Modified theDirectedAcyclicGraphclass to usepgmpyfor directed acyclic graphs, added methods for topological sorting, and removed the oldnetworkxgraph references.bamt/core/graph/graph.py: Updated theGraphclass to includenodesandedgesattributes and added a__repr__method for better representation.Node Models Improvements:
bamt/core/node_models/__init__.py: Corrected the import statements to use relative imports for better modularity.bamt/core/node_models/distribution.py: Added an abstract__repr__method to theDistributionclass for consistent representation across different distributions.bamt/core/node_models/empirical_distribution.py: Implemented the__repr__method in theEmpiricalDistributionclass and added anis_fittedmethod. [1] [2] [3] [4]Node Classes Adjustments:
bamt/core/nodes/__init__.py: Updated import statements to use relative imports for better modularity.bamt/core/nodes/child_nodes/child_node.py: Modified theChildNodeclass to accept anameparameter in the constructor.bamt/core/nodes/child_nodes/conditional_discrete_node.py: Added a__repr__method and placeholder methods forget_children,get_parents, andfitin theConditionalDiscreteNodeclass.bamt/core/nodes/node.py: Updated theNodeclass to includename,disc_parents,cont_parents, andchildrenattributes.bamt/core/nodes/root_nodes/continuous_node.py: Corrected the import statement forContinuousDistribution.bamt/core/nodes/root_nodes/discrete_node.py: Modified theDiscreteNodeclass to accept anameparameter and updated the__repr__method.bamt/core/nodes/root_nodes/root_node.py: Updated theRootNodeclass to accept anameparameter and added a__repr__method.Additional Changes:
bamt/dag_optimizers/dag_optimizer.py: Updated theoptimizemethod signature to acceptdata,scorer, and an optionalformatterparameter.