Exemple #1
0
 def name_cpd(aid):
     from pgmpy.factors import TabularCPD
     cpd = TabularCPD(
         variable='N' + aid,
         variable_card=num_names,
         values=[[1.0 / num_names] * num_names])
     cpd.semtype = 'name'
     return cpd
Exemple #2
0
 def name_cpd(aid):
     from pgmpy.factors import TabularCPD
     cpd = TabularCPD(
         variable='N' + aid,
         variable_card=num_names,
         values=[[1.0 / num_names] * num_names])
     cpd.semtype = 'name'
     return cpd
Exemple #3
0
 def score_cpd(aid1, aid2):
     cpd = TabularCPD(
         variable='S' + aid1 + aid2,
         variable_card=num_scores,
         values=score_values,
         evidence=['N' + aid1, 'N' + aid2],
         evidence_card=[num_names, num_names])
     cpd.semtype = 'score'
     return cpd
Exemple #4
0
 def score_cpd(aid1, aid2):
     cpd = TabularCPD(
         variable='S' + aid1 + aid2,
         variable_card=num_scores,
         values=score_values,
         evidence=['A' + aid1 + aid2],  # [::-1],
         evidence_card=[num_same_diff])  # [::-1])
     cpd.semtype = 'score'
     return cpd
Exemple #5
0
 def samediff_cpd(aid1, aid2):
     cpd = TabularCPD(
         variable='A' + aid1 + aid2,
         variable_card=num_same_diff,
         values=samediff_vals,
         evidence=['N' + aid1, 'N' + aid2],  # [::-1],
         evidence_card=[num_names, num_names])  # [::-1])
     cpd.semtype = 'match'
     return cpd
Exemple #6
0
 def score_cpd(aid1, aid2):
     cpd = TabularCPD(
         variable='S' + aid1 + aid2,
         variable_card=num_scores,
         values=score_values,
         evidence=['N' + aid1, 'N' + aid2],
         evidence_card=[num_names, num_names])
     cpd.semtype = 'score'
     return cpd
Exemple #7
0
 def score_cpd(aid1, aid2):
     cpd = TabularCPD(
         variable='S' + aid1 + aid2,
         variable_card=num_scores,
         values=score_values,
         evidence=['A' + aid1 + aid2],  # [::-1],
         evidence_card=[num_same_diff])  # [::-1])
     cpd.semtype = 'score'
     return cpd
Exemple #8
0
 def samediff_cpd(aid1, aid2):
     cpd = TabularCPD(
         variable='A' + aid1 + aid2,
         variable_card=num_same_diff,
         values=samediff_vals,
         evidence=['N' + aid1, 'N' + aid2],  # [::-1],
         evidence_card=[num_names, num_names])  # [::-1])
     cpd.semtype = 'match'
     return cpd
Exemple #9
0
            def score_cpd(aid1, aid2):
                semtype = 'score'
                evidence = ['A' + aid1 + aid2, 'N' + aid1, 'N' + aid2]
                evidence_cpds = [var2_cpd[key] for key in evidence]
                evidence_nice = [semtype2_nice[cpd.semtype] for cpd in evidence_cpds]
                evidence_card = list(map(len, evidence_nice))
                evidence_states = list(ut.iprod(*evidence_nice))
                variable_basis = semtype2_nice[semtype]

                variable_values = []
                for mystate in variable_basis:
                    row = []
                    for state in evidence_states:
                        if state[0] == state[1]:
                            if state[2] == 'same':
                                val = .2 if mystate == 'low' else .8
                            else:
                                val = 1
                                # val = .5 if mystate == 'low' else .5
                        elif state[0] != state[1]:
                            if state[2] == 'same':
                                val = .5 if mystate == 'low' else .5
                            else:
                                val = 1
                                # val = .9 if mystate == 'low' else .1
                        row.append(val)
                    variable_values.append(row)

                cpd = TabularCPD(
                    variable='S' + aid1 + aid2,
                    variable_card=len(variable_basis),
                    values=variable_values,
                    evidence=evidence,  # [::-1],
                    evidence_card=evidence_card)  # [::-1])
                cpd.semtype = semtype
                return cpd
Exemple #10
0
            def score_cpd(aid1, aid2):
                semtype = 'score'
                evidence = ['A' + aid1 + aid2, 'N' + aid1, 'N' + aid2]
                evidence_cpds = [var2_cpd[key] for key in evidence]
                evidence_nice = [semtype2_nice[cpd.semtype] for cpd in evidence_cpds]
                evidence_card = list(map(len, evidence_nice))
                evidence_states = list(ut.iprod(*evidence_nice))
                variable_basis = semtype2_nice[semtype]

                variable_values = []
                for mystate in variable_basis:
                    row = []
                    for state in evidence_states:
                        if state[0] == state[1]:
                            if state[2] == 'same':
                                val = .2 if mystate == 'low' else .8
                            else:
                                val = 1
                                # val = .5 if mystate == 'low' else .5
                        elif state[0] != state[1]:
                            if state[2] == 'same':
                                val = .5 if mystate == 'low' else .5
                            else:
                                val = 1
                                # val = .9 if mystate == 'low' else .1
                        row.append(val)
                    variable_values.append(row)

                cpd = TabularCPD(
                    variable='S' + aid1 + aid2,
                    variable_card=len(variable_basis),
                    values=variable_values,
                    evidence=evidence,  # [::-1],
                    evidence_card=evidence_card)  # [::-1])
                cpd.semtype = semtype
                return cpd