Exemplo n.º 1
0
"""
Author: Sari Haj Hussein
"""
from pyds import MassFunction
from pyuds import pyuds

m = MassFunction({
    "a": 0.26,
    "b": 0.26,
    "c": 0.26,
    "ab": 0.07,
    "ac": 0.01,
    "ad": 0.01,
    "bc": 0.01,
    "bd": 0.01,
    "cd": 0.01,
    "abcd": 0.1
})

print(pyuds.GH(m))
print(pyuds.GS(m))
print(pyuds.AU(m, False))

m = MassFunction([({'a'}, 0.26), ({'b'}, 0.26), ({'c'}, 0.26),
                  ({'a', 'b'}, 0.07), ({'a', 'c'}, 0.01), ({'a', 'd'}, 0.01),
                  ({'b', 'c'}, 0.01), ({'b', 'd'}, 0.01), ({'c', 'd'}, 0.01),
                  ({'a', 'b', 'c', 'd'}, 0.1)])

print(pyuds.GH(m))
print(pyuds.GS(m))
print(pyuds.AU(m, False))
Exemplo n.º 2
0
def time_q():
    return measure_time(
        MassFunction({(s, ): 1.0
                      for s in range(12)}).normalize().q)
Exemplo n.º 3
0
# Combinations

from pyds import MassFunction

# For Discourse "put it down"

m1 = MassFunction({'k': 0.25, 'kt': 0.75})
m2 = MassFunction({'k': 1.0})
m3 = MassFunction({'k': 0.5, 't': 0.5})

m_dcr_putdown = m1.combine_conjunctive(m2, m3)
print("Putdown", m_dcr_putdown.bel())

# For Discourse put it in the bowl

m4 = MassFunction({'k': 0.5, 't': 0.21, 'kt': 0.27})
m5 = MassFunction({'t': 1.0})
m6 = MassFunction({'t': 1.0})
m_dcr_putin = m4.combine_conjunctive(m5, m6)
print("putin", m_dcr_putin)

# For Discoure pass it to me

#In washing dishes context
m7 = MassFunction({'k': 0.4, 't': 0.3, 'kt': 0.3})
m8_w = MassFunction({'k': 1.0})
m9_w = MassFunction({'k': 1.0})
m_dcr_pass_w = m7.combine_conjunctive(m8_w, m9_w)
print("pass -wash", m_dcr_pass_w)

#In cooking context
Exemplo n.º 4
0
def time_from_bel():
    bel = MassFunction({(s, ): 1.0 for s in range(10)}).normalize().bel()
    return measure_time(MassFunction.from_bel, bel)
Exemplo n.º 5
0
def time_from_pl():
    pl = MassFunction({(s, ): 1.0 for s in range(10)}).normalize().pl()
    return measure_time(MassFunction.from_pl, pl)
Exemplo n.º 6
0
    #n_bits = ecg_signal[3]
    #ecg_signal = ecg_signal[4:]

    return ev_dist


# Read prob distribution from MLII
ev_dist_MLII = read_ev_dist('ev_dist_MLII_Shanon')
# Read prob distribution from RR
ev_dist_RR = read_ev_dist('ev_dist_RR_Shanon')
# for each instance

final_output = list()
for i in range(0, len(ev_dist_RR)):
    # Make the mass asignation
    m1 = MassFunction(ev_dist_MLII[i])
    m2 = MassFunction(ev_dist_RR[i])

    # compute the combination with DS
    #m1_2_disj = m1.combine_disjunctive(m2)
    m1_2 = m1.combine_conjunctive(m2)

    # Pignistic to make a decision
    output = m1_2.pignistic()

    # Keep output
    output_array = [output['N'], output['S'], output['V'], output['F']]
    #print(output_array)
    max_val = max(output_array)
    decision = output_array.index(max_val)
    #print('Class: ' + str(decision) + ' val = ' +  str(max_val))
Exemplo n.º 7
0
def time_from_q():
    q = MassFunction({(s, ): 1.0 for s in range(10)}).normalize().q()
    return measure_time(MassFunction.from_q, q)
Exemplo n.º 8
0
"""
Author: Sari Haj Hussein
"""
from pyds import MassFunction
from pyuds import pyuds
import cgi
import cgitb

formhtml = """Content-Type: text/html\n\n
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pyuds Web Interface</title>
<script type="text/javascript">
function MM_uncertaintyMenu(targ,selObj,restore){
  var verboseCheckBox = document.getElementById("verbose");
  if (selObj.selectedIndex == 2)
    verboseCheckBox.disabled = false;
  else
    verboseCheckBox.disabled = true;
}
</script>
</head>

<body>
<center>
<table>
  <tr>
    <td>
<p style="font-size:72px;font-weight:bold;margin:auto"><a href="https://sourceforge.net/projects/pyuds/" target="_blank" style="text-decoration:none;color:#000;outline:none">pyuds</a>
Exemplo n.º 9
0
    df = pd.DataFrame({
        "m": ms,
        "Bel": beliefs,
        "Pl": plausibilities
    },
                      index=hypotheses)

    return df


########### EXERCICE 1
''' OMEGA = {Setosa (S), Versicolor (V), Virginica (I) } '''

# 1/ Modélisation des connaissances
m1 = MassFunction({'V': 0.6, 'SVI': 0.4})
m2 = MassFunction({'S': 0.1, 'SI': 0.5, 'SVI': 0.4})
m3 = MassFunction({'SVI': 1})

print("1/ Modélisation des connaissances :\n")
print('M1 : ' + str(m1))
print('M2 : ' + str(m2))
print('M3 : ' + str(m3) + "\n\n\n")

# 2/ Calcul des degrés de croyance et des degrés de plausibilité du premier expert
df_m1 = calcul_degres_croyances_plausibilite(m1)

print(
    "2/ Calcul des degrés de croyance et des degrés de plausibilité du premier expert\n"
)
print(df_m1.to_markdown())
Exemplo n.º 10
0
 def test_frame(self):
     self.assertEqual({'a', 'b', 'c', 'd'}, self.m1.frame())
     self.assertEqual({'a', 'b', 'c'}, self.m2.frame())
     self.assertEqual(set(), MassFunction().frame())
Exemplo n.º 11
0
 def test_norm(self):
     self.assertEqual(0, self.m1.norm(self.m1))
     self.assertEqual(0, self.m1.norm(self.m1, p=1))
     m3 = MassFunction({'e': 1.0})
     len_m1 = sum([v**2 for v in self.m1.values()])
     self.assertEqual((1 + len_m1)**0.5, self.m1.norm(m3))
Exemplo n.º 12
0
 def test_multiple_dimensions(self):
     md1 = MassFunction({(('a', 1), ('b', 2)): 0.8, (('a', 1), ): 0.2})
     md2 = MassFunction({(('a', 1), ('b', 2), ('c', 1)): 1.0})
     md12 = md1 & md2
     self.assertAlmostEqual(0.2, md12[{('a', 1)}])
     self.assertAlmostEqual(0.8, md12[{('a', 1), ('b', 2)}])