jieunbyun / BNS-JT

Reference: Byun, J.-E. and Song, J. (2021). A general framework of Bayesian network for system reliability analysis using junction tree. Reliability Engineering & System Safety, 216, 107952.
MIT License
5 stars 4 forks source link

add cpm.py #1

Closed dynaryu closed 1 year ago

dynaryu commented 1 year ago
  1. create BNS_JT folder for python module
  2. create cpm.py
  3. create BNS_JT/tests/test_cpm.py
jieunbyun commented 1 year ago

class "variable" needs to be defined. In Matlab version, a variable is defined by "B" and "value". But to be more user friendly, "B" may be replaced by a dictionary something like "numBasicState = 3" and "compositeState = {'4':['1','2'], '5':['1','3'], '6': ['1','2','3']}" (A user does not have to enter composite states for all possible permutations but is enough define those being used). Then, the code may create a "B" matrix accordingly if it makes computation more efficient.

But this is just my suggestion, and I will leave the final decision to you. Also, please feel free to modify variable names.

jieunbyun commented 1 year ago

Oh and for the current Matlab version, "isCompatible" function is somehow misplaced.. It'd be great if it could be placed correctly in the upcoming python version.

jieunbyun commented 1 year ago

As a test example, we can use this one: image

dynaryu commented 1 year ago
dynaryu commented 1 year ago

Oh and for the current Matlab version, "isCompatible" function is somehow misplaced.. It'd be great if it could be placed correctly in the upcoming python version.

I put it under cpm.py where Cpm class is defined.

dynaryu commented 1 year ago

But to be more user friendly, "B" may be replaced by a dictionary something like "numBasicState = 3" and "compositeState = {'4':['1','2'], '5':['1','3'], '6': ['1','2','3']}" (A user does not have to enter composite states for all possible permutations but is enough define those being used).

For the time being, I will try to convert the matlab to Python as it is. Once basic implementation is done, then we can think about how to improve usability further.

dynaryu commented 1 year ago

As a test example, we can use this one: image

Given the test example, can you provide input and output for testing? For instance, isCompatible product sum etc...

jieunbyun commented 1 year ago

Oh by the way, there is a typo in the example. P(X2|H) has p=[0.95 0.05 0.85 0.15]' -- The second element needs be changed from 0.15 to 0.05.