Skip to content

Conversation

@Roman223
Copy link
Collaborator

@Roman223 Roman223 commented Apr 3, 2025

This pull request introduces several significant changes to the bamt package, 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 the Checker class, which includes methods for validating arguments and initializing node types.
  • bamt/checkers/network_checker.py: Added the NetworkChecker class, which extends Checker and includes methods for checking network restrictions, validating loads, and determining node types.
  • bamt/checkers/node_checkers.py: Created RawNodeChecker and NodeChecker classes 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 the DirectedAcyclicGraph class to use pgmpy for directed acyclic graphs, added methods for topological sorting, and removed the old networkx graph references.
  • bamt/core/graph/graph.py: Updated the Graph class to include nodes and edges attributes and added a __repr__ method for better representation.

Node Models Improvements:

Node Classes Adjustments:

Additional Changes:

@Roman223 Roman223 added the enhancement New feature or request label Apr 3, 2025
@Roman223 Roman223 added this to the BAMT 2.0.0 milestone Apr 3, 2025
@Roman223 Roman223 requested review from Copilot and jrzkaminski April 3, 2025 11:18
@Roman223 Roman223 self-assigned this Apr 3, 2025
Copy link

Copilot AI left a 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.

Comment on lines +25 to +26
return True if self.node_type in [RawNodeType, RawNodeType.disc_num] else False

Copy link

Copilot AI Apr 3, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
if isinstance(arg, str):
arg = enumerator(arg)
if arg not in self.node_type.__class__:
assert TypeError("Wrong type of argument.")
Copy link

Copilot AI Apr 3, 2025

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.

Suggested change
assert TypeError("Wrong type of argument.")
raise TypeError("Wrong type of argument.")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant