Package teamwork :: Package examples :: Package Thespian :: Module ChatDynamics
[hide private]
[frames] | no frames]

Source Code for Module teamwork.examples.Thespian.ChatDynamics

  1  from teamwork.math.ProbabilityTree import * 
  2  from teamwork.math.KeyedMatrix import * 
  3  from teamwork.dynamics.pwlDynamics import * 
  4  from teamwork.dynamics.arbitraryDynamics import * 
  5  
 
  6  
 
7 -def dummyDyn(feature):
8 tree1 = ProbabilityTree(IdentityMatrix(feature)) 9 10 return {'tree':tree1}
11 12 13
14 -def InitNorm():
15 tree1 = ProbabilityTree(IdentityMatrix('init-norm')) 16 17 tree4 = ProbabilityTree(IncrementMatrix('init-norm',keyConstant,-.1)) 18 19 20 ## if I have obligations that haven't been satisfied 21 weights = {} 22 for feature in [\ 23 'being-enquired', 24 ]: 25 key = makeStateKey('self',feature) 26 weights[key] = 1 27 28 plane = KeyedPlane(KeyedVector(weights),.001) 29 30 tree5 = createBranchTree(plane,tree1,tree4) 31 32 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 33 'relationship':'equals'}]),0.5) 34 tree0 = createBranchTree(plane,tree1,tree5) 35 36 return {'tree':tree0}
37 38
39 -def RespNorm(act):
40 tree0 = ProbabilityTree(IdentityMatrix('resp-norm')) 41 42 tree4 = ProbabilityTree(IncrementMatrix('resp-norm',keyConstant,-.1)) 43 tree3 = ProbabilityTree(IdentityMatrix('resp-norm')) 44 45 varname = 'being-enquired' 46 47 weights = {makeStateKey('self',varname):1.} 48 plane = KeyedPlane(KeyedVector(weights),.001) 49 tree2 = createBranchTree(plane,tree4,tree3) 50 51 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 52 'relationship':'equals'}]),0.5) 53 tree1 = createBranchTree(plane,tree0,tree2) 54 55 return {'tree':tree1}
56 57
58 -def IntendImposeNorm(act):
59 60 varname = 'being-enquired' 61 tree0 = ProbabilityTree(IdentityMatrix(varname)) 62 tree3 = ProbabilityTree(SetToConstantMatrix(feature=varname,value=1)) 63 64 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 65 'relationship':'equals'}]),0.5) 66 67 tree1 = createBranchTree(plane,tree0,tree3) 68 69 return {'tree':tree1}
70 71
72 -def IntendFinishNorm(act):
73 varname = 'being-enquired' 74 tree0 = ProbabilityTree(IdentityMatrix(varname)) 75 tree3 = ProbabilityTree(IncrementMatrix(varname,keyConstant,-1)) 76 77 weights = {makeStateKey('self',varname):1.} 78 plane = KeyedPlane(KeyedVector(weights),.1) 79 tree2 = createBranchTree(plane,tree0,tree3) 80 81 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 82 'relationship':'equals'}]),0.5) 83 84 tree1 = createBranchTree(plane,tree0,tree2) 85 return {'tree':tree1}
86 87 88 DynFun = { 89 'noneDyn': {}, 90 'basicDyn': { 91 'init-norm':{\ 92 'enquiry':{'class':PWLDynamics, 93 'args':InitNorm()}, 94 }, 95 'resp-norm':{\ 96 'pos-inform':{'class':PWLDynamics, 97 'args':RespNorm('inform')}, 98 'neu-inform':{'class':PWLDynamics, 99 'args':RespNorm('inform')}, 100 'neg-inform':{'class':PWLDynamics, 101 'args':RespNorm('inform')}, 102 103 }, 104 105 'being-enquired':{'enquiry':{'class':PWLDynamics, 106 'args':IntendImposeNorm('enquiry')}, 107 'pos-inform':{'class':PWLDynamics, 108 'args':IntendFinishNorm('inform')}, 109 'neu-inform':{'class':PWLDynamics, 110 'args':IntendFinishNorm('inform')}, 111 'neg-inform':{'class':PWLDynamics, 112 'args':IntendFinishNorm('inform')}, 113 }, 114 115 } 116 } 117