diff --git a/main.py b/main.py new file mode 100644 index 0000000000000000000000000000000000000000..5d17ad7b0734c5cbee8e04f7cf707dfa246c1481 --- /dev/null +++ b/main.py @@ -0,0 +1,37 @@ +import bnlearn +import numpy as np + +#df = bnlearn.import_example() +model = bnlearn.import_DAG('persona_model_3.bif') +#q_1 = bnlearn.inference.fit(model, variables=['Rain'], evidence={'Cloudy':1, 'Sprinkler':0, 'Wet_Grass':1}) +#q_2 = bnlearn.inference.fit(model, variables=['Rain'], evidence={'Cloudy':1}) +df = bnlearn.sampling(model, n=1000) +print(df) +q_1 = bnlearn.inference.fit(model, variables=['user_action'], evidence={'robot_assistance':0, + 'attempt':2, + 'game_state':0, + 'robot_feedback':0, + 'memory':1, + 'reactivity':1, + 'attention':1 + }) +print(q_1) +# update = np.arange(9).reshape(3, 3) +# model['model'].cpds[4].values[0][0] = update +# print(model['model'].cpds[4].values[0][0]) +#print("model 0") +#print(model["model"].cpds[0].values) +#print("model 1") +#print(model["model"].cpds[1].values) +#print("model 2") +#print(model["model"].cpds[2].values) +#print("model 3") +#print(model["model"].cpds[3].values) +#print("model 4") +#print(model["model"].cpds[4].values) +#print("model 5") +#print(model["model"].cpds[5].values) +#print("model 6") +#print(model["model"].cpds[6].values) +#print("model 7") +#print(model["model"].cpds[7].values) diff --git a/persona_model_3.bif b/persona_model_3.bif new file mode 100644 index 0000000000000000000000000000000000000000..06c85dfec93ce7152cb3a17c51112d3682aecab0 --- /dev/null +++ b/persona_model_3.bif @@ -0,0 +1,132 @@ +network persona_model_3 { +} + +%definition of the variables +variable reactivity { + type discrete [3] {slow, medium, fast}; +} +variable memory { + type discrete[3] {low, medium, high}; +} +variable attention { + type discrete[3] {low, medium, high}; +} + +variable robot_assistance { + type discrete [ 5 ] { lev_0, lev_1, lev_2, lev_3, lev_4 }; +} + +variable attempt { + type discrete [ 4 ] { att_1, att_2, att_3, att_4 }; +} + +variable game_state { + type discrete [ 3 ] { beg, mid, end }; +} + +variable robot_feedback { + type discrete [ 2 ] { yes, no }; +} + +variable user_action { + type discrete [ 3 ] { correct, wrong, timeout }; +} + +%definition of individual probabilities + +probability ( robot_assistance ) { + table 0.2, 0.2, 0.2, 0.2, 0.2; +} +probability ( game_state ) { + table 0.34, 0.33, 0.33; +} +probability ( attempt ) { + table 0.25, 0.25, 0.25, 0.25; +} +probability ( user_action ) { + table 0.33, 0.33, 0.34; +} +#cpds 4 +probability ( reactivity ) { + table 0.33, 0.33, 0.34; +} +#cpds 3 +probability ( memory ) { + table 0.33, 0.33, 0.34; +} +#cpds 1 +probability ( attention ) { + table 0.33, 0.33, 0.34; +} +probability ( robot_feedback ) { + table 0.5, 0.5; +} + + +#cpds 7 +probability (user_action | reactivity, memory, attention) { + +(slow, low, low) 0.1, 0.4, 0.5; +(slow, low, medium) 0.3, 0.5, 0.2; +(slow, low, high) 0.4, 0.5, 0.1; +(slow, medium, low) 0.5, 0.3, 0.2; +(slow, medium, medium) 0.4, 0.3, 0.3; +(slow, medium, high) 0.5, 0.4, 0.1; +(slow, high, low) 0.3, 0.4, 0.3; +(slow, high, medium) 0.6, 0.3, 0.1; +(slow, high, high) 0.7, 0.2, 0.1; + +(medium, low, low) 0.3, 0.4, 0.3; +(medium, low, medium) 0.3, 0.5, 0.2; +(medium, low, high) 0.4, 0.3, 0.3; +(medium, medium, low) 0.33, 0.33, 0.34; +(medium, medium, medium) 0.6, 0.3, 0.1; +(medium, medium, high) 0.6, 0.4, 0.0; +(medium, high, low) 0.34, 0.33, 0.33; +(medium, high, medium) 0.7, 0.2, 0.1; +(medium, high, high) 0.75, 0.25, 0.0; + +(fast, low, low) 0.5, 0.2, 0.3; +(fast, low, medium) 0.6, 0.2, 0.2; +(fast, low, high) 0.7, 0.3, 0.0; +(fast, medium, low) 0.5, 0.2, 0.3; +(fast, medium, medium) 0.6, 0.2, 0.2; +(fast, medium, high) 0.8, 0.2, 0.0; +(fast, high, low) 0.5, 0.2, 0.3; +(fast, high, medium) 0.6, 0.2, 0.2; +(fast, high, high) 0.9, 0.1, 0.0; + +} + +#cpds 5 +probability (robot_feedback | user_action) { + (correct) 0.8, 0.2; + (wrong) 0.5, 0.5; + (timeout) 0.2, 0.8; +} + +#cpds 6 +probability (robot_assistance | user_action) { + (correct) 0.05 0.1 0.15 0.3 0.4; + (wrong) 0.1 0.2 0.4 0.2 0.1; + (timeout) 0.2 0.4 0.2 0.1 0.1; +} + +#cpds 2 +probability (game_state | user_action) { + (correct) 0.2, 0.4, 0.4; + (wrong) 0.4, 0.4, 0.2; + (timeout) 0.6, 0.3, 0.1; +} + +#cpds 0 +probability (attempt | user_action) { + (correct) 0.1, 0.2, 0.3, 0.4; + (wrong) 0.5, 0.3, 0.15, 0.05; + (timeout) 0.4, 0.3, 0.2, 0.1; +} + +probability (robot_assistance | robot_feedback) { + (yes) 0.5 0.3 0.1 0.1 0.0; + (no) 0.0 0.1 0.1 0.3 0.5; +} \ No newline at end of file