close_btn
로그인, 회원가입후 더 많은 혜택을 누리세요 로그인 회원가입 닫기

 

 

 

- 파이썬으로 그래피컬 모델 구현하는 라이브러리입니다.

 

https://github.com/pgmpy/pgmpy

 

example 폴더에 예제 코드와 설명도 노트북파일로 되어 있습니다. 

 

 

 

간단한 활용 예제는 다음과 같습니다.

>>> from pgmpy.models import BayesianModel
>>> from pgmpy.factors.discrete import TabularCPD
>>> student = BayesianModel()
>>> # instantiates a new Bayesian Model called 'student'

>>> student.add_nodes_from(['diff', 'intel', 'grade'])
>>> # adds nodes labelled 'diff', 'intel', 'grade' to student

>>> student.add_edges_from([('diff', 'grade'), ('intel', 'grade')])
>>> # adds directed edges from 'diff' to 'grade' and 'intel' to 'grade'

>>> """
... diff cpd:
...
... +-------+--------+
... |diff:  |        |
... +-------+--------+
... |easy   |   0.2  |
... +-------+--------+
... |hard   |   0.8  |
... +-------+--------+
... """

>>> diff_cpd = TabularCPD('diff', 2, [[0.2], [0.8]])

>>> """
... intel cpd:
...
... +-------+--------+
... |intel: |        |
... +-------+--------+
... |dumb   |   0.5  |
... +-------+--------+
... |avg    |   0.3  |
... +-------+--------+
... |smart  |   0.2  |
... +-------+--------+
... """

>>> intel_cpd = TabularCPD('intel', 3, [[0.5], [0.3], [0.2]])

>>> """
... grade cpd:
...
... +------+-----------------------+---------------------+
... |diff: |          easy         |         hard        |
... +------+------+------+---------+------+------+-------+
... |intel:| dumb |  avg |  smart  | dumb | avg  | smart |
... +------+------+------+---------+------+------+-------+
... |gradeA| 0.1  | 0.1  |   0.1   |  0.1 |  0.1 |   0.1 |
... +------+------+------+---------+------+------+-------+
... |gradeB| 0.1  | 0.1  |   0.1   |  0.1 |  0.1 |   0.1 |
... +------+------+------+---------+------+------+-------+
... |gradeC| 0.8  | 0.8  |   0.8   |  0.8 |  0.8 |   0.8 |
... +------+------+------+---------+------+------+-------+
... """

>>> grade_cpd = TabularCPD('grade', 3,
                         [[0.1,0.1,0.1,0.1,0.1,0.1],
                         [0.1,0.1,0.1,0.1,0.1,0.1], 
                         [0.8,0.8,0.8,0.8,0.8,0.8]],
                         evidence=['intel', 'diff'],
                         evidence_card=[3, 2])

>>> student.add_cpds(diff_cpd, intel_cpd, grade_cpd)

>>> # Finding active trail
>>> student.active_trail_nodes('diff')
{'diff', 'grade'}

>>> # Finding active trail with observation
>>> student.active_trail_nodes('diff', observed='grade')
{'diff', 'intel'}

 

 

 

 

 

 

- 그래피컬 모델 구현에 많이 사용되는 어플리케이션입니다.

 

http://reasoning.cs.ucla.edu/samiam/