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

Source Code for Module teamwork.examples.Thespian.RedRidingHoodDynamics

   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 thresholdDecrease(feature):
8 tree0 = ProbabilityTree(IdentityMatrix(feature)) 9 tree1 = ProbabilityTree(IncrementMatrix(feature,keyConstant,-.1)) 10 weights = {makeStateKey('self',feature): 1.} 11 plane = KeyedPlane(KeyedVector(weights),.001) 12 13 tree = createBranchTree(plane,tree1,tree0) 14 return {'tree':tree}
15
16 -def thresholdObjectSetDyn(thresholdF,fea,val):
17 tree0 = ProbabilityTree(IdentityMatrix(fea)) 18 tree1 = ProbabilityTree(SetToConstantMatrix(source=fea,value=val)) 19 weights = {makeStateKey('self',thresholdF): 1.} 20 plane = KeyedPlane(KeyedVector(weights),.001) 21 22 tree2 = createBranchTree(plane,tree0,tree1) 23 24 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 25 'relationship':'equals'}]),0.5) 26 27 tree3 = createBranchTree(plane,tree0,tree2) 28 29 return {'tree':tree3}
30 31 32
33 -def deltaDyn(feature,delta):
34 tree = ProbabilityTree(IncrementMatrix(feature,keyConstant,delta)) 35 return {'tree':tree}
36
37 -def deltaActorOrObjectDyn(feature,delta):
38 tree0 = ProbabilityTree(IdentityMatrix(feature)) 39 tree1 = ProbabilityTree(IncrementMatrix(feature,keyConstant,delta)) 40 41 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 42 'relationship':'equals'}]),0.5) 43 44 tree2 = createBranchTree(plane,tree0,tree1) 45 46 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 47 'relationship':'equals'}]),0.5) 48 49 tree3 = createBranchTree(plane,tree2,tree1) 50 51 return {'tree':tree3}
52 53
54 -def deltaActorDyn(feature,delta):
55 56 tree0 = ProbabilityTree(IdentityMatrix(feature)) 57 tree1 = ProbabilityTree(IncrementMatrix(feature,keyConstant,delta)) 58 59 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 60 'relationship':'equals'}]),0.5) 61 62 tree3 = createBranchTree(plane,tree0,tree1) 63 64 return {'tree':tree3}
65 66
67 -def dummyDyn(feature):
68 tree1 = ProbabilityTree(IdentityMatrix(feature)) 69 70 return {'tree':tree1}
71
72 -def ActorSetDyn(fea, val):
73 tree0 = ProbabilityTree(IdentityMatrix(fea)) 74 tree1 = ProbabilityTree(SetToConstantMatrix(source=fea,value=val)) 75 76 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 77 'relationship':'equals'}]),0.5) 78 79 tree3 = createBranchTree(plane,tree0,tree1) 80 81 return {'tree':tree3}
82 83
84 -def ObjectSetDyn(fea, val):
85 tree0 = ProbabilityTree(IdentityMatrix(fea)) 86 tree1 = ProbabilityTree(SetToConstantMatrix(source=fea,value=val)) 87 88 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 89 'relationship':'equals'}]),0.5) 90 91 tree3 = createBranchTree(plane,tree0,tree1) 92 93 return {'tree':tree3}
94 95 96 ##def InitNorm(act): 97 ## tree1 = ProbabilityTree(IdentityMatrix('norm')) 98 ## 99 ## tree4 = ProbabilityTree(IncrementMatrix('norm',keyConstant,-.1)) 100 ## tree7 = ProbabilityTree(IncrementMatrix('norm',keyConstant,.1)) 101 ## 102 #### action shouldn't happen after closed conversation, or before conversation opened 103 ## 104 ## if not act in ['greet-init','bye-resp']: 105 ## weights = {makeStateKey('self','conversation'): 1.} 106 ## plane = KeyedPlane(KeyedVector(weights),.001) 107 ## tree6 = createBranchTree(plane,tree4,tree1) 108 ## else: 109 ## weights = {makeStateKey('self','conversation'): 1.} 110 ## plane = KeyedPlane(KeyedVector(weights),.001) 111 ## tree6 = createBranchTree(plane,tree7,tree4) 112 ## 113 #### if I have obligations that haven't been satisfied 114 ## weights = {} 115 ## for feature in [\ 116 ## 'being-greeted', 117 ## 'being-byed', 118 ## 'being-enquired', 119 ## 'being-informed', 120 ## 'being-enquired-about-granny', 121 ## ]: 122 ## key = makeStateKey('self',feature) 123 ## weights[key] = 1 124 ## 125 ## plane = KeyedPlane(KeyedVector(weights),.001) 126 ## 127 ## tree5 = createBranchTree(plane,tree6,tree4) 128 ## 129 ## 130 #### if I have already did this action 131 ## if act in ['greet','bye']: 132 ## if act[len(act)-1] == 'e': 133 ## varname = act+'d' 134 ## else: 135 ## varname = act+'ed' 136 ## 137 ## weights = {makeStateKey('self',varname):1.} 138 ## plane = KeyedPlane(KeyedVector(weights),.001) 139 ## tree2 = createBranchTree(plane,tree5,tree4) 140 ## else: 141 ## tree2 = tree5 142 ## 143 ## plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 144 ## 'relationship':'equals'}]),0.5) 145 ## tree0 = createBranchTree(plane,tree1,tree2) 146 ## 147 ## return {'tree':tree0} 148 149
150 -def conversationFlowNorm(act):
151 tree1 = ProbabilityTree(IdentityMatrix('conversation-flow-norm')) 152 tree4 = ProbabilityTree(IncrementMatrix('conversation-flow-norm',keyConstant,-.1)) 153 154 ## action shouldn't happen after closed conversation, or before conversation opened 155 156 if not act in ['greet-init','bye-resp']: 157 weights = {makeStateKey('self','conversation'): 1.} 158 plane = KeyedPlane(KeyedVector(weights),.001) 159 tree2 = createBranchTree(plane,tree4,tree1) 160 else: 161 weights = {makeStateKey('self','conversation'): 1.} 162 plane = KeyedPlane(KeyedVector(weights),.001) 163 tree2 = createBranchTree(plane,tree1,tree4) 164 165 166 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 167 'relationship':'equals'}]),0.5) 168 tree0 = createBranchTree(plane,tree1,tree2) 169 170 return {'tree':tree0}
171 172
173 -def InitNorm():
174 tree1 = ProbabilityTree(IdentityMatrix('init-norm')) 175 176 tree4 = ProbabilityTree(IncrementMatrix('init-norm',keyConstant,-.1)) 177 178 179 ## if I have obligations that haven't been satisfied 180 weights = {} 181 for feature in [\ 182 'being-greeted', 183 'being-byed', 184 'being-enquired', 185 'being-informed', 186 'being-enquired-about-granny', 187 ]: 188 key = makeStateKey('self',feature) 189 weights[key] = 1 190 191 plane = KeyedPlane(KeyedVector(weights),.001) 192 193 tree5 = createBranchTree(plane,tree1,tree4) 194 195 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 196 'relationship':'equals'}]),0.5) 197 tree0 = createBranchTree(plane,tree1,tree5) 198 199 return {'tree':tree0}
200 201
202 -def RespNorm(act):
203 tree0 = ProbabilityTree(IdentityMatrix('resp-norm')) 204 205 tree4 = ProbabilityTree(IncrementMatrix('resp-norm',keyConstant,-.1)) 206 tree3 = ProbabilityTree(IdentityMatrix('resp-norm')) 207 208 ## tree3 = ProbabilityTree(IncrementMatrix('resp-norm',keyConstant,.1)) 209 210 if act == 'inform': 211 varname = 'being-enquired' 212 elif act in ['accept','reject']: 213 varname = 'being-requested' 214 elif act in ['OK']: 215 varname = 'being-informed' 216 elif act == 'enquiry-about-granny': 217 varname = 'being-enquired-about-granny' 218 else: 219 varname = 'being-'+act 220 if act[len(act)-1] == 'e': 221 varname += 'd' 222 else: 223 varname += 'ed' 224 225 weights = {makeStateKey('self',varname):1.} 226 plane = KeyedPlane(KeyedVector(weights),.001) 227 tree2 = createBranchTree(plane,tree4,tree3) 228 229 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 230 'relationship':'equals'}]),0.5) 231 tree1 = createBranchTree(plane,tree0,tree2) 232 233 return {'tree':tree1}
234
235 -def MakeRespNorm(act):
236 tree0 = ProbabilityTree(IdentityMatrix('makeResp-norm')) 237 238 tree4 = ProbabilityTree(IdentityMatrix('makeResp-norm')) 239 tree3 = ProbabilityTree(IncrementMatrix('makeResp-norm',keyConstant,.1)) 240 241 ## tree3 = ProbabilityTree(IncrementMatrix('resp-norm',keyConstant,.1)) 242 243 if act == 'inform': 244 varname = 'being-enquired' 245 elif act in ['accept','reject']: 246 varname = 'being-requested' 247 elif act in ['OK']: 248 varname = 'being-informed' 249 elif act == 'enquiry-about-granny': 250 varname = 'being-enquired-about-granny' 251 else: 252 varname = 'being-'+act 253 if act[len(act)-1] == 'e': 254 varname += 'd' 255 else: 256 varname += 'ed' 257 258 weights = {makeStateKey('self',varname):1.} 259 plane = KeyedPlane(KeyedVector(weights),.001) 260 tree2 = createBranchTree(plane,tree4,tree3) 261 262 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 263 'relationship':'equals'}]),0.5) 264 tree1 = createBranchTree(plane,tree0,tree2) 265 266 267 return {'tree':tree1}
268 269
270 -def IntendImposeNorm(act):
271 272 if act == 'enquiry': 273 varname = 'being-enquired' 274 elif act == 'inform-info': 275 varname = 'being-informed' 276 elif act == 'enquiry-about-granny': 277 varname = 'being-enquired-about-granny' 278 else: 279 varname = 'being-'+act 280 if act[len(act)-1] == 'e': 281 varname += 'd' 282 else: 283 varname += 'ed' 284 tree0 = ProbabilityTree(IdentityMatrix(varname)) 285 tree3 = ProbabilityTree(SetToConstantMatrix(source=varname,value=1)) 286 287 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 288 'relationship':'equals'}]),0.5) 289 290 tree1 = createBranchTree(plane,tree0,tree3) 291 292 return {'tree':tree1}
293 294
295 -def IntendFinishNorm(act):
296 297 if act == 'inform': 298 varname = 'being-enquired' 299 elif act in ['accept','reject']: 300 varname = 'being-requested' 301 elif act in ['OK']: 302 varname = 'being-informed' 303 elif act == 'enquiry-about-granny': 304 varname = 'being-enquired-about-granny' 305 else: 306 varname = 'being-'+act 307 if act[len(act)-1] == 'e': 308 varname += 'd' 309 else: 310 varname += 'ed' 311 tree0 = ProbabilityTree(IdentityMatrix(varname)) 312 tree3 = ProbabilityTree(IncrementMatrix(varname,keyConstant,-1)) 313 314 weights = {makeStateKey('self',varname):1.} 315 plane = KeyedPlane(KeyedVector(weights),.1) 316 tree2 = createBranchTree(plane,tree0,tree3) 317 318 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 319 'relationship':'equals'}]),0.5) 320 321 tree1 = createBranchTree(plane,tree0,tree2) 322 return {'tree':tree1}
323
324 -def conversationDyn(intend):
325 tree0 = ProbabilityTree(IdentityMatrix('conversation')) 326 if intend == 'greet': 327 tree1 = ProbabilityTree(SetToConstantMatrix(source='conversation',value=1)) 328 elif intend == 'bye': 329 tree1 = ProbabilityTree(SetToConstantMatrix(source='conversation',value=0)) 330 331 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 332 'relationship':'equals'}]),0.5) 333 334 tree2 = createBranchTree(plane,tree0,tree1) 335 336 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 337 'relationship':'equals'}]),0.5) 338 339 tree3 = createBranchTree(plane,tree2,tree1) 340 341 return {'tree':tree3}
342
343 -def aliveDyn():
344 tree0 = ProbabilityTree(IdentityMatrix('alive')) 345 tree1 = ProbabilityTree(SetToConstantMatrix(source='alive',value=0)) 346 347 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 348 'relationship':'equals'}]),0.5) 349 350 tree3 = createBranchTree(plane,tree0,tree1) 351 352 return {'tree':tree3}
353
354 -def aliveProbDyn():
355 tree0 = ProbabilityTree(IdentityMatrix('alive')) 356 tree1 = ProbabilityTree(SetToConstantMatrix(source='alive',value=0)) 357 358 tree4 = ProbabilityTree() 359 tree4.branch(Distribution({tree0:0.8,tree1:0.2})) 360 361 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 362 'relationship':'equals'}]),0.5) 363 364 tree3 = createBranchTree(plane,tree0,tree4) 365 366 return {'tree':tree3}
367 368 369 ##def eatenDyn(): 370 ## tree0 = ProbabilityTree(IdentityMatrix('eaten')) 371 ## tree1 = ProbabilityTree(SetToConstantMatrix(source='eaten',value=1)) 372 ## 373 ## plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 374 ## 'relationship':'equals'}]),0.5) 375 ## 376 ## tree3 = createBranchTree(plane,tree0,tree1) 377 ## 378 ## return {'tree':tree3} 379 380
381 -def escapeDyn():
382 tree0 = ProbabilityTree(IdentityMatrix('alive')) 383 tree1 = ProbabilityTree(SetToConstantMatrix(source='alive',value=1)) 384 385 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 386 'relationship':'equals'}]),0.5) 387 388 tree3 = createBranchTree(plane,tree0,tree1) 389 390 return {'tree':tree3}
391
392 -def eatFullDyn():
393 tree0 = ProbabilityTree(IdentityMatrix('full')) 394 tree1 = ProbabilityTree(IncrementMatrix('full',keyConstant,.5)) 395 396 weights = {makeStateKey('actor','full'):1.} 397 plane = KeyedPlane(KeyedVector(weights),.9) 398 tree2 = createBranchTree(plane,tree1,tree0) 399 400 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 401 'relationship':'equals'}]),0.5) 402 403 tree3 = createBranchTree(plane,tree0,tree2) 404 405 return {'tree':tree3}
406
407 -def eatCakeFullDyn():
408 tree0 = ProbabilityTree(IdentityMatrix('full')) 409 tree1 = ProbabilityTree(IncrementMatrix('full',keyConstant,.2)) 410 411 weights = {makeStateKey('object','full'):1.} 412 plane = KeyedPlane(KeyedVector(weights),.9) 413 tree2 = createBranchTree(plane,tree1,tree0) 414 415 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 416 'relationship':'equals'}]),0.5) 417 418 tree3 = createBranchTree(plane,tree0,tree2) 419 420 return {'tree':tree3}
421 422
423 -def cakeDyn():
424 tree0 = ProbabilityTree(IdentityMatrix('has-cake')) 425 tree1 = ProbabilityTree(SetToConstantMatrix(source='has-cake',value=1)) 426 tree2 = ProbabilityTree(SetToConstantMatrix(source='has-cake',value=0)) 427 428 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 429 'relationship':'equals'}]),0.5) 430 431 tree3 = createBranchTree(plane,tree0,tree1) 432 433 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 434 'relationship':'equals'}]),0.5) 435 436 tree4 = createBranchTree(plane,tree3,tree2) 437 438 return {'tree':tree4}
439 440
441 -def knowPersonDyn(name):
442 tree0 = ProbabilityTree(IdentityMatrix(name)) 443 tree1 = ProbabilityTree(SetToConstantMatrix(source=name,value=1)) 444 445 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 446 'relationship':'equals'}]),0.5) 447 448 tree3 = createBranchTree(plane,tree0,tree1) 449 450 return {'tree':tree3}
451 452
453 -def moveDyn(dis):
454 if dis == 1: 455 val1=.1 456 val2=-.1 457 else: 458 val1=.2 459 val2=-.2 460 461 tree0 = ProbabilityTree(IdentityMatrix('location')) 462 tree1 = ProbabilityTree(IncrementMatrix('location',keyConstant,val1)) 463 tree2 = ProbabilityTree(IncrementMatrix('location',keyConstant,val2)) 464 465 weights = {makeStateKey('actor','location'):1.} 466 plane = KeyedPlane(KeyedVector(weights),.9) 467 tree3 = createBranchTree(plane,tree1,tree2) 468 469 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 470 'relationship':'equals'}]),0.5) 471 472 tree4 = createBranchTree(plane,tree0,tree3) 473 return {'tree':tree4}
474 475
476 -def likeActDyn(feature):
477 478 tree0 = ProbabilityTree(IdentityMatrix(feature)) 479 tree1 = ProbabilityTree(IncrementMatrix(feature,keyConstant,.1)) 480 481 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 482 'relationship':'equals'}]),0.5) 483 484 tree3 = createBranchTree(plane,tree0,tree1) 485 486 return {'tree':tree3}
487 488
489 -def locationDyn():
490 491 tree0 = ProbabilityTree(IdentityMatrix('sameLocation')) 492 tree1 = ProbabilityTree(IncrementMatrix('sameLocation',keyConstant,-.1)) 493 494 495 plane = KeyedPlane(DifferenceRow(keys=[makeStateKey('actor','location'),makeStateKey('object','location')]),0.001) 496 497 tree2 = createBranchTree(plane,tree0,tree1) 498 499 plane = KeyedPlane(DifferenceRow(keys=[makeStateKey('object','location'),makeStateKey('actor','location')]),0.001) 500 501 tree3 = createBranchTree(plane,tree2,tree1) 502 503 504 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 505 'relationship':'equals'}]),0.5) 506 507 tree4 = createBranchTree(plane,tree0,tree3) 508 509 return {'tree':tree4}
510
511 -def actBothAliveDyn():
512 513 tree0 = ProbabilityTree(IdentityMatrix('actAlive')) 514 tree1 = ProbabilityTree(IncrementMatrix('actAlive',keyConstant,-.1)) 515 516 weights = {makeStateKey('actor','alive'):1.} 517 plane = KeyedPlane(KeyedVector(weights),.001) 518 519 tree2 = createBranchTree(plane,tree1,tree0) 520 521 weights = {makeStateKey('object','alive'):1.} 522 plane = KeyedPlane(KeyedVector(weights),.001) 523 524 tree3 = createBranchTree(plane,tree1,tree2) 525 526 527 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 528 'relationship':'equals'}]),0.5) 529 530 tree4 = createBranchTree(plane,tree0,tree3) 531 532 return {'tree':tree4}
533 534
535 -def actActorAliveDyn():
536 537 tree0 = ProbabilityTree(IdentityMatrix('actAlive')) 538 tree1 = ProbabilityTree(IncrementMatrix('actAlive',keyConstant,-.1)) 539 540 weights = {makeStateKey('actor','alive'):1.} 541 plane = KeyedPlane(KeyedVector(weights),.001) 542 543 tree2 = createBranchTree(plane,tree1,tree0) 544 545 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 546 'relationship':'equals'}]),0.5) 547 548 tree4 = createBranchTree(plane,tree0,tree2) 549 550 return {'tree':tree4}
551
552 -def actActorAliveOnlyDyn():
553 554 tree0 = ProbabilityTree(IdentityMatrix('actAlive')) 555 tree1 = ProbabilityTree(IncrementMatrix('actAlive',keyConstant,-.1)) 556 557 weights = {makeStateKey('actor','alive'):1.} 558 plane = KeyedPlane(KeyedVector(weights),.001) 559 560 tree2 = createBranchTree(plane,tree1,tree0) 561 562 weights = {makeStateKey('object','alive'):1.} 563 plane = KeyedPlane(KeyedVector(weights),.001) 564 565 tree3 = createBranchTree(plane,tree2,tree1) 566 567 568 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 569 'relationship':'equals'}]),0.5) 570 571 tree4 = createBranchTree(plane,tree0,tree3) 572 573 return {'tree':tree4}
574 575
576 -def actBothNotAliveDyn():
577 578 tree0 = ProbabilityTree(IdentityMatrix('actAlive')) 579 tree1 = ProbabilityTree(IncrementMatrix('actAlive',keyConstant,-.1)) 580 581 weights = {makeStateKey('actor','alive'):1.} 582 plane = KeyedPlane(KeyedVector(weights),.001) 583 584 tree2 = createBranchTree(plane,tree0,tree1) 585 586 weights = {makeStateKey('object','alive'):1.} 587 plane = KeyedPlane(KeyedVector(weights),.001) 588 589 tree3 = createBranchTree(plane,tree2,tree1) 590 591 592 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 593 'relationship':'equals'}]),0.5) 594 595 tree4 = createBranchTree(plane,tree0,tree3) 596 597 return {'tree':tree4}
598
599 -def specialRuleEatDyn():
600 tree0 = ProbabilityTree(IdentityMatrix('specialRule')) 601 tree1 = ProbabilityTree(IncrementMatrix('specialRule',keyConstant,-.1)) 602 603 ## if want to eat granny, must know granny 604 weights = {makeStateKey('actor','know-granny'):1.} 605 plane = KeyedPlane(KeyedVector(weights),0) 606 607 tree5 = createBranchTree(plane,tree1,tree0) 608 609 plane = KeyedPlane(ClassRow(keys=[{'entity':'object','value':'granny'}]),0) 610 611 tree6 = createBranchTree(plane,tree0,tree5) 612 613 614 ## can not eat at the location when wolf first meet red 615 weights = {makeStateKey('actor','location'):1.} 616 plane = KeyedPlane(KeyedVector(weights),0) 617 618 tree2 = createBranchTree(plane,tree1,tree6) 619 620 weights = {makeStateKey('actor','location'):1.} 621 plane = KeyedPlane(KeyedVector(weights),-.9) 622 623 tree3 = createBranchTree(plane,tree0,tree2) 624 625 626 ## the actor's identity must be wolf 627 weights = {makeStateKey('actor','identity'):1.} 628 plane = KeyedPlane(KeyedVector(weights),0) 629 630 tree7 = createBranchTree(plane,tree3,tree1) 631 632 633 ## the actor can not eat if it is already full 634 weights = {makeStateKey('actor','full'):1.} 635 plane = KeyedPlane(KeyedVector(weights),0.9) 636 637 tree8 = createBranchTree(plane,tree7,tree1) 638 639 640 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 641 'relationship':'equals'}]),0.5) 642 643 tree4 = createBranchTree(plane,tree0,tree8) 644 645 return {'tree':tree4}
646 647
648 -def preferWaitWolfDyn():
649 tree0 = ProbabilityTree(IdentityMatrix('preferWait')) 650 tree2 = ProbabilityTree(IncrementMatrix('preferWait',keyConstant,.1)) 651 652 weights = {makeStateKey('self','full'):1.} 653 plane = KeyedPlane(KeyedVector(weights),.8) 654 655 tree4 = createBranchTree(plane,tree0,tree2) 656 657 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 658 'relationship':'equals'}]),0.5) 659 660 tree3 = createBranchTree(plane,tree0,tree4) 661 662 return {'tree':tree3}
663 664 ##def preferWaitDyn(): 665 ## tree0 = ProbabilityTree(IdentityMatrix('preferWait')) 666 ## tree1 = ProbabilityTree(IncrementMatrix('preferWait',keyConstant,-.01)) 667 ## tree2 = ProbabilityTree(IncrementMatrix('preferWait',keyConstant,-.1)) 668 ## 669 ## weights = {} 670 ## for feature in [\ 671 ## 'being-greeted', 672 ## 'being-byed', 673 ## 'being-enquired', 674 ## 'being-informed', 675 ## ]: 676 ## key = makeStateKey('self',feature) 677 ## weights[key] = 1 678 ## 679 ## plane = KeyedPlane(KeyedVector(weights),.001) 680 ## 681 ## tree4 = createBranchTree(plane,tree1,tree2) 682 ## 683 ## plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 684 ## 'relationship':'equals'}]),0.5) 685 ## 686 ## tree3 = createBranchTree(plane,tree0,tree4) 687 ## 688 ## return {'tree':tree3} 689
690 -def noRepeatDyn(feature):
691 692 tree0 = ProbabilityTree(IdentityMatrix('noRepeat-norm')) 693 tree1 = ProbabilityTree(IncrementMatrix('noRepeat-norm',keyConstant,-.1)) 694 695 696 weights = {makeStateKey('actor',feature):1.} 697 plane = KeyedPlane(KeyedVector(weights),0) 698 tree3 = createBranchTree(plane,tree0,tree1) 699 700 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 701 'relationship':'equals'}]),0.5) 702 703 tree4 = createBranchTree(plane,tree0,tree3) 704 return {'tree':tree4}
705 706
707 -def specialRuleEnquiryDyn():
708 709 tree0 = ProbabilityTree(IdentityMatrix('specialRule')) 710 tree1 = ProbabilityTree(IncrementMatrix('specialRule',keyConstant,-.1)) 711 712 713 weights = {makeStateKey('actor','know-granny'):1.} 714 plane = KeyedPlane(KeyedVector(weights),0) 715 tree3 = createBranchTree(plane,tree0,tree1) 716 717 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 718 'relationship':'equals'}]),0.5) 719 720 tree4 = createBranchTree(plane,tree0,tree3) 721 return {'tree':tree4}
722 723
724 -def specialRuleCakeDyn():
725 726 tree0 = ProbabilityTree(IdentityMatrix('specialRule')) 727 tree1 = ProbabilityTree(IncrementMatrix('specialRule',keyConstant,-.1)) 728 729 730 weights = {makeStateKey('actor','has-cake'):1.} 731 plane = KeyedPlane(KeyedVector(weights),.5) 732 tree3 = createBranchTree(plane,tree1,tree0) 733 734 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 735 'relationship':'equals'}]),0.5) 736 737 tree4 = createBranchTree(plane,tree0,tree3) 738 return {'tree':tree4}
739 740
741 -def SDDyn(feature):
742 tree0 = ProbabilityTree(IdentityMatrix(feature)) 743 tree1 = ProbabilityTree(IncrementMatrix(feature,keyConstant,.05)) 744 745 name = feature.strip('SDwith') 746 if name == 'Wolf': 747 name = 'wolf' 748 749 plane = KeyedPlane(ClassRow(keys=[{'entity':'object','value':name}]),0) 750 751 tree3 = createBranchTree(plane,tree0,tree1) 752 753 plane = KeyedPlane(ClassRow(keys=[{'entity':'actor','value':name}]),0) 754 755 tree2 = createBranchTree(plane,tree0,tree1) 756 757 plane = KeyedPlane(IdentityRow(keys=[{'entity':'object', 758 'relationship':'equals'}]),0.5) 759 760 tree5 = createBranchTree(plane,tree0,tree2) 761 762 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 763 'relationship':'equals'}]),0.5) 764 765 tree4 = createBranchTree(plane,tree5,tree3) 766 return {'tree':tree4}
767 768
769 -def SDnormDyn(act):
770 tree0 = ProbabilityTree(IdentityMatrix('SDnorm')) 771 tree1 = ProbabilityTree(IncrementMatrix('SDnorm',keyConstant,-.1)) 772 773 774 weights = {makeStateKey('object','SDwithWolf'):1.} 775 plane = KeyedPlane(KeyedVector(weights),0) 776 tree3 = createBranchTree(plane,tree1,tree0) 777 778 plane = KeyedPlane(IdentityRow(keys=[{'entity':'actor', 779 'relationship':'equals'}]),0.5) 780 781 tree4 = createBranchTree(plane,tree0,tree3) 782 return {'tree':tree4}
783 784 785 DynFun = { 786 'noneDyn': {}, 787 'basicDyn': { 788 ## 'norm':{'greet-init':{'class':PWLDynamics, 789 ## 'args':InitNorm('greet-init')}, 790 ## 'greet-resp':{'class':PWLDynamics, 791 ## 'args':RespNorm('greet')}, 792 ## 'bye-init':{'class':PWLDynamics, 793 ## 'args':InitNorm('bye')}, 794 ## 'bye-resp':{'class':PWLDynamics, 795 ## 'args':RespNorm('bye')}, 796 ## 'enquiry':{'class':PWLDynamics, 797 ## 'args':InitNorm('enquiry')}, 798 ## 'inform':{'class':PWLDynamics, 799 ## 'args':RespNorm('inform')}, 800 ## 'inform-info':{'class':PWLDynamics, 801 ## 'args':InitNorm('inform-info')}, 802 ## 'OK':{'class':PWLDynamics, 803 ## 'args':RespNorm('OK')}, 804 ## 'enquiry-about-granny':{'class':PWLDynamics, 805 ## 'args':InitNorm('enquiry-about-granny')}, 806 ## 'inform-about-granny':{'class':PWLDynamics, 807 ## 'args':RespNorm('enquiry-about-granny')}, 808 ## 809 ## }, 810 'resp-norm':{\ 811 'greet-resp':{'class':PWLDynamics, 812 'args':RespNorm('greet')}, 813 814 'bye-resp':{'class':PWLDynamics, 815 'args':RespNorm('bye')}, 816 817 'inform':{'class':PWLDynamics, 818 'args':RespNorm('inform')}, 819 820 'inform-about-granny':{'class':PWLDynamics, 821 'args':RespNorm('enquiry-about-granny')}, 822 823 }, 824 'makeResp-norm':{\ 825 'greet-resp':{'class':PWLDynamics, 826 'args':MakeRespNorm('greet')}, 827 828 'bye-resp':{'class':PWLDynamics, 829 'args':MakeRespNorm('bye')}, 830 831 'inform':{'class':PWLDynamics, 832 'args':MakeRespNorm('inform')}, 833 834 'inform-about-granny':{'class':PWLDynamics, 835 'args':MakeRespNorm('enquiry-about-granny')}, 836 837 }, 838 'init-norm':{'greet-init':{'class':PWLDynamics, 839 'args':InitNorm()}, 840 841 'bye-init':{'class':PWLDynamics, 842 'args':InitNorm()}, 843 844 'enquiry':{'class':PWLDynamics, 845 'args':InitNorm()}, 846 847 'enquiry-about-granny':{'class':PWLDynamics, 848 'args':InitNorm()}, 849 850 'tell-about-granny':{'class':PWLDynamics, 851 'args':InitNorm()}, 852 'move1':{'class':PWLDynamics, 853 'args':InitNorm()}, 854 'move2':{'class':PWLDynamics, 855 'args':InitNorm()}, 856 'wait':{'class':PWLDynamics, 857 'args':InitNorm()}, 858 859 }, 860 861 'conversation-flow-norm':{'greet-init':{'class':PWLDynamics, 862 'args':conversationFlowNorm('greet-init')}, 863 'greet-resp':{'class':PWLDynamics, 864 'args':conversationFlowNorm('greet')}, 865 'bye-init':{'class':PWLDynamics, 866 'args':conversationFlowNorm('bye-init')}, 867 'bye-resp':{'class':PWLDynamics, 868 'args':conversationFlowNorm('bye-resp')}, 869 'enquiry':{'class':PWLDynamics, 870 'args':conversationFlowNorm('enquiry')}, 871 'inform':{'class':PWLDynamics, 872 'args':conversationFlowNorm('inform')}, 873 'inform-info':{'class':PWLDynamics, 874 'args':conversationFlowNorm('inform-info')}, 875 'OK':{'class':PWLDynamics, 876 'args':conversationFlowNorm('OK')}, 877 'enquiry-about-granny':{'class':PWLDynamics, 878 'args':conversationFlowNorm('enquiry-about-granny')}, 879 'inform-about-granny':{'class':PWLDynamics, 880 'args':conversationFlowNorm('enquiry-about-granny')}, 881 'tell-about-granny':{'class':PWLDynamics, 882 'args':conversationFlowNorm('enquiry-about-granny')}, 883 884 }, 885 886 'noRepeat-norm':{\ 887 ## 'enquiry':{'class':PWLDynamics, 888 ## 'args':noRepeatDyn('enquired')}, 889 'tell-about-granny':{'class':PWLDynamics, 890 'args':noRepeatDyn('told-about-granny')}, 891 'give-cake':{'class':PWLDynamics, 892 'args':noRepeatDyn('given-cake')}, 893 'greet-init':{'class':PWLDynamics, 894 'args':noRepeatDyn('greeted')}, 895 'bye-init':{'class':PWLDynamics, 896 'args':noRepeatDyn('byed')}, 897 }, 898 899 900 901 'greeted':{'greet-init':{'class':PWLDynamics, 902 'args':deltaActorOrObjectDyn('greeted', 1)}, 903 'greet-resp':{'class':PWLDynamics, 904 'args':deltaActorOrObjectDyn('greeted', 1)}, 905 'bye-init':{'class':PWLDynamics, 906 'args':deltaActorOrObjectDyn('greeted', 1)}, 907 'bye-resp':{'class':PWLDynamics, 908 'args':deltaActorOrObjectDyn('greeted', 1)}, 909 'enquiry':{'class':PWLDynamics, 910 'args':deltaActorOrObjectDyn('greeted', 1)}, 911 'inform':{'class':PWLDynamics, 912 'args':deltaActorOrObjectDyn('greeted', 1)}, 913 'enquiry-about-granny':{'class':PWLDynamics, 914 'args':deltaActorOrObjectDyn('greeted', 1)}, 915 'inform-about-granny':{'class':PWLDynamics, 916 'args':deltaActorOrObjectDyn('greeted', 1)}, 917 'tell-about-granny':{'class':PWLDynamics, 918 'args':deltaActorOrObjectDyn('greeted', 1)}, 919 }, 920 921 'byed':{'bye-init':{'class':PWLDynamics, 922 'args':deltaActorOrObjectDyn('byed', 1)}, 923 'bye-resp':{'class':PWLDynamics, 924 'args':deltaActorOrObjectDyn('byed', 1)}, 925 }, 926 927 'enquired':{'enquiry':{'class':PWLDynamics, 928 'args':deltaActorDyn('enquired', 1)}, 929 }, 930 931 'given-cake':{'give-cake':{'class':PWLDynamics, 932 'args':deltaActorDyn('given-cake', 1)}, 933 }, 934 'told-about-granny':{'tell-about-granny':{'class':PWLDynamics, 935 'args':deltaActorDyn('told-about-granny', 1)}, 936 'inform-about-granny':{'class':PWLDynamics, 937 'args':deltaActorDyn('told-about-granny', 1)}, 938 }, 939 940 'being-greeted':{'greet-init':{'class':PWLDynamics, 941 'args':IntendImposeNorm('greet')}, 942 'greet-resp':{'class':PWLDynamics, 943 'args':IntendFinishNorm('greet')}, 944 }, 945 'being-byed':{'bye-init':{'class':PWLDynamics, 946 'args':IntendImposeNorm('bye')}, 947 'bye-resp':{'class':PWLDynamics, 948 'args':IntendFinishNorm('bye')}, 949 }, 950 951 'being-enquired':{'enquiry':{'class':PWLDynamics, 952 'args':IntendImposeNorm('enquiry')}, 953 'inform':{'class':PWLDynamics, 954 'args':IntendFinishNorm('inform')}, 955 }, 956 'being-informed':{'inform-info':{'class':PWLDynamics, 957 'args':IntendImposeNorm('inform-info')}, 958 'OK':{'class':PWLDynamics, 959 'args':IntendFinishNorm('OK')}, 960 }, 961 962 'conversation':{\ 963 'eat':{'class':PWLDynamics, 964 'args':conversationDyn('bye')}, 965 966 'kill':{'class':PWLDynamics, 967 'args':conversationDyn('bye')}, 968 969 'escape':{'class':PWLDynamics, 970 'args':dummyDyn('conversation')}, 971 972 'resurrect':{'class':PWLDynamics, 973 'args':dummyDyn('conversation')}, 974 975 'wait':{'class':PWLDynamics, 976 'args':dummyDyn('conversation')}, 977 'move1':{'class':PWLDynamics, 978 'args':conversationDyn('bye')}, 979 'move2':{'class':PWLDynamics, 980 'args':conversationDyn('bye')}, 981 982 'bye-resp':{'class':PWLDynamics, 983 'args':dummyDyn('conversation')}, 984 'give-cake':{'class':PWLDynamics, 985 'args':dummyDyn('conversation')}, 986 987 None:{'class':PWLDynamics, 988 'args':conversationDyn('greet')}, 989 'bye-init':{'class':PWLDynamics, 990 'args':conversationDyn('bye')}, 991 }, 992 993 }, 994 'RedDyn': { 995 'alive':{\ 996 'hunter-kill-wolf':{'class':PWLDynamics, 997 'args':aliveDyn()}, 998 'fairy-kill-wolf':{'class':PWLDynamics, 999 'args':aliveDyn()}, 1000 'red-kill-wolf':{'class':PWLDynamics, 1001 'args':aliveProbDyn()}, 1002 'eat':{'class':PWLDynamics, 1003 'args':aliveDyn()}, 1004 'escape':{'class':PWLDynamics, 1005 'args':escapeDyn()}, 1006 'resurrect':{'class':PWLDynamics, 1007 'args':ObjectSetDyn('alive',1.0)}, 1008 }, 1009 'full':{'eat':{'class':PWLDynamics, 1010 'args':eatFullDyn()}, 1011 'give-cake':{'class':PWLDynamics, 1012 'args':eatCakeFullDyn()}, 1013 }, 1014 ## 'eaten':{'eat':{'class':PWLDynamics, 1015 ## 'args':eatenDyn()}, 1016 ## }, 1017 'has-cake':{'give-cake':{'class':PWLDynamics, 1018 'args':cakeDyn()}, 1019 }, 1020 'location':{\ 1021 'move1':{'class':PWLDynamics, 1022 'args':moveDyn(1)}, 1023 'move2':{'class':PWLDynamics, 1024 'args':moveDyn(2)}, 1025 }, 1026 'know-granny':{\ 1027 'tell-about-granny':{'class':PWLDynamics, 1028 'args':knowPersonDyn('know-granny')}, 1029 'inform-about-granny':{'class':PWLDynamics, 1030 'args':knowPersonDyn('know-granny')}, 1031 }, 1032 'likeMove':{'move1':{'class':PWLDynamics, 1033 'args':likeActDyn('likeMove')}, 1034 'move2':{'class':PWLDynamics, 1035 'args':likeActDyn('likeMove')}, 1036 1037 }, 1038 'likeTalk':{'greet-init':{'class':PWLDynamics, 1039 'args':likeActDyn('likeTalk')}, 1040 'greet-resp':{'class':PWLDynamics, 1041 'args':likeActDyn('likeTalk')}, 1042 'bye-init':{'class':PWLDynamics, 1043 'args':likeActDyn('likeTalk')}, 1044 'bye-resp':{'class':PWLDynamics, 1045 'args':likeActDyn('likeTalk')}, 1046 'tell-about-granny':{'class':PWLDynamics, 1047 'args':likeActDyn('likeTalk')}, 1048 'inform-about-granny':{'class':PWLDynamics, 1049 'args':likeActDyn('likeTalk')}, 1050 'inform':{'class':PWLDynamics, 1051 'args':likeActDyn('likeTalk')}, 1052 'enquiry':{'class':PWLDynamics, 1053 'args':likeActDyn('likeTalk')}, 1054 'inform-about-granny':{'class':PWLDynamics, 1055 'args':likeActDyn('likeTalk')}, 1056 'enquiry-about-granny':{'class':PWLDynamics, 1057 'args':likeActDyn('likeTalk')}, 1058 }, 1059 'sameLocation':{'wait':{'class':PWLDynamics, 1060 'args':dummyDyn('sameLocation')}, 1061 'move1':{'class':PWLDynamics, 1062 'args':dummyDyn('sameLocation')}, 1063 'move2':{'class':PWLDynamics, 1064 'args':dummyDyn('sameLocation')}, 1065 'changeIdentity':{'class':PWLDynamics, 1066 'args':dummyDyn('sameLocation')}, 1067 None:{'class':PWLDynamics, 1068 'args':locationDyn()}, 1069 }, 1070 'actAlive':{'wait':{'class':PWLDynamics, 1071 'args':dummyDyn('actAlive')}, 1072 'move1':{'class':PWLDynamics, 1073 'args':actActorAliveDyn()}, 1074 'move2':{'class':PWLDynamics, 1075 'args':actActorAliveDyn()}, 1076 'changeIdentity':{'class':PWLDynamics, 1077 'args':actActorAliveDyn()}, 1078 'escape':{'class':PWLDynamics, 1079 'args':actBothNotAliveDyn()}, 1080 None:{'class':PWLDynamics, 1081 'args':actBothAliveDyn()}, 1082 }, 1083 'specialRule':{'eat':{'class':PWLDynamics, 1084 'args':specialRuleEatDyn(),}, 1085 'enquiry-about-granny':{'class':PWLDynamics, 1086 'args':specialRuleEnquiryDyn()}, 1087 'enquiry':{'class':PWLDynamics, 1088 'args':specialRuleEnquiryDyn()}, 1089 'give-cake':{'class':PWLDynamics, 1090 'args':specialRuleCakeDyn()}, 1091 }, 1092 1093 'preferWait':{'wait':{'class':PWLDynamics, 1094 'args':preferWaitWolfDyn()}, 1095 }, 1096 'being-enquired-about-granny':{\ 1097 'enquiry-about-granny':{'class':PWLDynamics, 1098 'args':thresholdObjectSetDyn('SDwithWolf','being-enquired-about-granny',1)}, 1099 'inform-about-granny':{'class':PWLDynamics, 1100 'args':ActorSetDyn('being-enquired-about-granny',0)}, 1101 }, 1102 'SDwithWolf':{None:{'class':PWLDynamics, 1103 'args':SDDyn('SDwithWolf')}, 1104 'wait':{'class':PWLDynamics, 1105 'args':dummyDyn('SDwithWolf')}, 1106 'move1':{'class':PWLDynamics, 1107 'args':dummyDyn('SDwithWolf')}, 1108 'move2':{'class':PWLDynamics, 1109 'args':dummyDyn('SDwithWolf')}, 1110 'escape':{'class':PWLDynamics, 1111 'args':dummyDyn('SDwithWolf')}, 1112 'enquiry-about-granny':{'class':PWLDynamics, 1113 'args':thresholdDecrease('SDwithWolf')}, 1114 }, 1115 'SDnorm':{'enquiry-about-granny':{'class':PWLDynamics, 1116 'args':SDnormDyn('enquiry-about-granny')}, 1117 }, 1118 'identity':{'changeIdentity':{'class':PWLDynamics, 1119 'args':deltaActorDyn('identity',2.0)}, 1120 }, 1121 1122 } 1123 } 1124