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

Check for edge cases and eventually handle them #3

Open
ricor07 opened this issue Dec 22, 2024 · 4 comments
Open

Check for edge cases and eventually handle them #3

ricor07 opened this issue Dec 22, 2024 · 4 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ricor07
Copy link
Owner

ricor07 commented Dec 22, 2024

No description provided.

@ricor07 ricor07 added help wanted Extra attention is needed good first issue Good for newcomers labels Dec 22, 2024
@Anshu-bhatt
Copy link

I am new to contributing. so can you brief it out the issue?

@ricor07
Copy link
Owner Author

ricor07 commented Dec 22, 2024

I am new to contributing. so can you brief it out the issue?

I suggest you check for the other two issues if you're new. The task here is to try many times the class BayesianNetwork with different inputs and check whether it fails somewhere.

@gmottajr
Copy link

gmottajr commented Jan 2, 2025

Request for Additional Details

Hi @ricor07,
I’m currently reviewing this issue and would appreciate some additional context to ensure I address it effectively. Could you please provide more information on the following?

  1. Issue Context

    • Could you describe the background and the current behavior you're encountering?
  2. Specific Goals

    • What is the desired behavior or outcome once the issue is resolved?
  3. Environment Details

    • Application version/build
    • Relevant configurations
    • Any third-party services or integrations involved
  4. Edge Cases

    • Are there any specific scenarios or conditions you’d like me to test or consider?
  5. Test Cases

    • Do you have particular test cases that should be created or executed to validate the fix?
  6. Acceptance Criteria

    • What criteria would define this issue as successfully resolved?
  7. Returned Values

    • When I ran the class, the following values were returned:
      • 0, 0, 0, 0, 0, 0, 0 : 2.1600e-05 0, 0, 0, 0, 0, 0, 1 : 5.0400e-05 0, 0, 0, 0, 0, 1, 0 : 1.9440e-04 0, 0, 0, 0, 0, 1, 1 : 4.5360e-04 0, 0, 0, 0, 1, 0, 0 : 5.7600e-05 0, 0, 0, 0, 1, 0, 1 : 2.3040e-04 0, 0, 0, 0, 1, 1, 0 : 5.1840e-04 0, 0, 0, 0, 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3548e-01 1, 1, 0, 1, 1, 1, 0 : 8.4672e-03 1, 1, 0, 1, 1, 1, 1 : 3.3869e-02 1, 1, 1, 0, 0, 0, 0 : 8.0640e-04 1, 1, 1, 0, 0, 0, 1 : 1.8816e-03 1, 1, 1, 0, 0, 1, 0 : 1.2096e-03 1, 1, 1, 0, 0, 1, 1 : 2.8224e-03 1, 1, 1, 0, 1, 0, 0 : 4.8384e-03 1, 1, 1, 0, 1, 0, 1 : 1.9354e-02 1, 1, 1, 0, 1, 1, 0 : 7.2576e-03 1, 1, 1, 0, 1, 1, 1 : 2.9030e-02 1, 1, 1, 1, 0, 0, 0 : 1.4112e-03 1, 1, 1, 1, 0, 0, 1 : 3.2928e-03 1, 1, 1, 1, 0, 1, 0 : 3.2928e-03 1, 1, 1, 1, 0, 1, 1 : 7.6832e-03 1, 1, 1, 1, 1, 0, 0 : 8.4672e-03 1, 1, 1, 1, 1, 0, 1 : 3.3869e-02 1, 1, 1, 1, 1, 1, 0 : 1.9757e-02 1, 1, 1, 1, 1, 1, 1 : 7.9027e-02 2, 0, 0, 0, 0, 0, 0 : 1.2960e-04 2, 0, 0, 0, 0, 0, 1 : 3.0240e-04 2, 0, 0, 0, 0, 1, 0 : 1.1664e-03 2, 0, 0, 0, 0, 1, 1 : 2.7216e-03 2, 0, 0, 0, 1, 0, 0 : 5.7600e-05 2, 0, 0, 0, 1, 0, 1 : 2.3040e-04 2, 0, 0, 0, 1, 1, 0 : 5.1840e-04 2, 0, 0, 0, 1, 1, 1 : 2.0736e-03 2, 0, 0, 1, 0, 0, 0 : 2.4192e-03 2, 0, 0, 1, 0, 0, 1 : 5.6448e-03 2, 0, 0, 1, 0, 1, 0 : 6.0480e-04 2, 0, 0, 1, 0, 1, 1 : 1.4112e-03 2, 0, 0, 1, 1, 0, 0 : 1.0752e-03 2, 0, 0, 1, 1, 0, 1 : 4.3008e-03 2, 0, 0, 1, 1, 1, 0 : 2.6880e-04 2, 0, 0, 1, 1, 1, 1 : 1.0752e-03 2, 0, 1, 0, 0, 0, 0 : 3.4560e-04 2, 0, 1, 0, 0, 0, 1 : 8.0640e-04 2, 0, 1, 0, 0, 1, 0 : 5.1840e-04 2, 0, 1, 0, 0, 1, 1 : 1.2096e-03 2, 0, 1, 0, 1, 0, 0 : 1.5360e-04 2, 0, 1, 0, 1, 0, 1 : 6.1440e-04 2, 0, 1, 0, 1, 1, 0 : 2.3040e-04 2, 0, 1, 0, 1, 1, 1 : 9.2160e-04 2, 0, 1, 1, 0, 0, 0 : 6.0480e-04 2, 0, 1, 1, 0, 0, 1 : 1.4112e-03 2, 0, 1, 1, 0, 1, 0 : 1.4112e-03 2, 0, 1, 1, 0, 1, 1 : 3.2928e-03 2, 0, 1, 1, 1, 0, 0 : 2.6880e-04 2, 0, 1, 1, 1, 0, 1 : 1.0752e-03 2, 0, 1, 1, 1, 1, 0 : 6.2720e-04 2, 0, 1, 1, 1, 1, 1 : 2.5088e-03 2, 1, 0, 0, 0, 0, 0 : 3.8880e-04 2, 1, 0, 0, 0, 0, 1 : 9.0720e-04 2, 1, 0, 0, 0, 1, 0 : 3.4992e-03 2, 1, 0, 0, 0, 1, 1 : 8.1648e-03 2, 1, 0, 0, 1, 0, 0 : 3.1680e-04 2, 1, 0, 0, 1, 0, 1 : 1.2672e-03 2, 1, 0, 0, 1, 1, 0 : 2.8512e-03 2, 1, 0, 0, 1, 1, 1 : 1.1405e-02 2, 1, 0, 1, 0, 0, 0 : 7.2576e-03 2, 1, 0, 1, 0, 0, 1 : 1.6934e-02 2, 1, 0, 1, 0, 1, 0 : 1.8144e-03 2, 1, 0, 1, 0, 1, 1 : 4.2336e-03 2, 1, 0, 1, 1, 0, 0 : 5.9136e-03 2, 1, 0, 1, 1, 0, 1 : 2.3654e-02 2, 1, 0, 1, 1, 1, 0 : 1.4784e-03 2, 1, 0, 1, 1, 1, 1 : 5.9136e-03 2, 1, 1, 0, 0, 0, 0 : 1.0368e-03 2, 1, 1, 0, 0, 0, 1 : 2.4192e-03 2, 1, 1, 0, 0, 1, 0 : 1.5552e-03 2, 1, 1, 0, 0, 1, 1 : 3.6288e-03 2, 1, 1, 0, 1, 0, 0 : 8.4480e-04 2, 1, 1, 0, 1, 0, 1 : 3.3792e-03 2, 1, 1, 0, 1, 1, 0 : 1.2672e-03 2, 1, 1, 0, 1, 1, 1 : 5.0688e-03 2, 1, 1, 1, 0, 0, 0 : 1.8144e-03 2, 1, 1, 1, 0, 0, 1 : 4.2336e-03 2, 1, 1, 1, 0, 1, 0 : 4.2336e-03 2, 1, 1, 1, 0, 1, 1 : 9.8784e-03 2, 1, 1, 1, 1, 0, 0 : 1.4784e-03 2, 1, 1, 1, 1, 0, 1 : 5.9136e-03 2, 1, 1, 1, 1, 1, 0 : 3.4496e-03 2, 1, 1, 1, 1, 1, 1 : 1.3798e-02
    • Are these the expected results, or should I anticipate different outputs?
    • Could you clarify what the correct return values should look like for each scenario?

Issue: Bayesian Network - Probability Calculation

Description:

The Bayesian Network class calculates probabilities based on given variables and their relationships. Upon running the code, the following output was produced:

0, 0, 0, 0, 0, 0, 0 : 5.0000e-02  
0, 0, 0, 0, 0, 0, 1 : 1.2000e-01  
0, 0, 0, 0, 0, 1, 0 : 7.0000e-02  
... (truncated)  
Total: 1.0000000000

Code Analysis:

Upon reviewing the code, the following key points were observed:

  • Variable Representation: Each variable consists of a name, a 2D array representing probabilities, and lists for children and parents.
  • Outcome Calculation: The multiply_outcome method recursively calculates the probability of variables, accounting for parent dependencies.
  • Traversal Logic: The return_probability method iterates over all possible states, updating statuses and accumulating probabilities.
  • Normalization: The summation of all calculated outcomes totals 1, suggesting normalization is handled correctly.

Questions and Clarifications:

  1. Output Values:

    • The produced values appear reasonable, but can you confirm that the output aligns with the expected probabilities for the given network structure?
    • Specifically, should the total probability always equal 1, or is this a coincidence based on the current configuration?
  2. Variable Array Sizes:

    • The array sizes for Variable e and Variable f differ (8 rows vs. 4 rows). Is this intentional, or should the sizes be consistent across all dependent variables?
  3. Traversal Order:

    • The multiply_outcome method processes variables without children first. Should this order be reversed to prioritize parents, or is the current bottom-up traversal correct for the use case?

Let me know if there’s anything else you’d like to add. I appreciate your help in clarifying these points!

Best regards,
Jr.

@ricor07
Copy link
Owner Author

ricor07 commented Jan 4, 2025

Hello, the values you posted are correct. Adding test cases and some proper file would be good. I don't have any suggestions in particular. I just posted the network here on GitHub, I didn't spend much time in properly adding the files. The algorithm, however, is correct. If you wish to change it, raise an issue or a PR. I'm glad to welcome suggestions. I don't think there is a specific build script. It's just copy-pasted c++ from my compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants