You selected gbayes01b.pl


title(A):-
A=[
'% A Prolog Modeling of Bayesian Perfect Equilibria '
,'% created: 22--23 Dec 2003.'
,'% modified: 25,26 Dec 2003.'
,'% modified: 21 Jun 2004. (bugfix for rational_choice_of_entrant/3, display_consistency_result/1, and their demos.)'
,'% modified: 13 Jul 2004. (position of dynamic for SWI later versions. )'
,'% main: consistency_test/0.'
,'% display_consistency_results(yes).'
,'% display_consistency_results(all).'
].



%=====================================
% Two stage entry-deterrence game
%=====================================
% descriptive modeling.

player(entrant).
player(monopolist).

possible_type_of_entrant(weak).
possible_type_of_entrant(tough).


% decision rule of entrant which hypothesized by monopolist. 

:- dynamic strategy_of_entrant/3.
% modified: 13 Jul 2004

strategy_of_entrant(T,exit,Q):-
   strategy_of_entrant(T,enter,P),
   Q is 1 - P.

strategy_of_entrant(weak,enter,0).
strategy_of_entrant(tough,enter,1).

possible_strategy_of_entrant(weak,enter,P):-
%   member(P,[0,1]).
%alternatives:
%   member(P,[0,0.5,1]).
   probability(0.1,P).
%   probabilities(2,[W,_]),P is W/100.

possible_strategy_of_entrant(tough,enter,P):-
%   member(P,[0,1]).
%   member(P,[0,0.5,1]).
   probability(0.1,P).

possible_strategy_of_monopolist(deter,P):-
%   member(P,[0,1]).
%   member(P,[0,0.5,1]).
   probability(0.1,P).


%=====================================
% beliefs and the updating rule
%=====================================

%prior_belief_of_monopolist(weak,0.5).
%prior_belief_of_monopolist(weak,0.75).
prior_belief_of_monopolist(weak,1/3).
%prior_belief_of_monopolist(weak,0.999999999999).
%prior_belief_of_monopolist(weak,1).
prior_belief_of_monopolist(tough,Q):-
   prior_belief_of_monopolist(weak,P),
   Q is 1 - P.

knowledge(upper_node->monopolist is weak).
knowledge(lower_node->monopolist is tough).

updating_belief_of_monopolist(
  P->(Q=B/B0),
  at(Node:T),
  observing(Enter),
  reason(prob(B,for(T)),prob(BN,if_not))
 ):-
   strategy_of_entrant(T,Enter,S),
   knowledge(Node->monopolist is T),
   collect_probs_of_consistent_states(Enter,_,B0),
   prior_belief_of_monopolist(T,P),
   bayes_rule(B0,P,S,B,Q),
   BN is B0 - B.


bayes_rule(B0,P,S,B,Q):-
   B0 > 0,
   B is P * S,
   Q is B / B0.

bayes_rule(0,_,_,0.5,0.5). % posterior of measure-0 event.

collect_probs_of_consistent_states(Enter,BL,B0):-
   findall(B1,
     (
      strategy_of_entrant(T1,Enter,P1),
      prior_belief_of_monopolist(T1,S1),
      B1 is P1 * S1
     ),
   BL),
   sum(BL,B0).


/*
?- updating_belief_of_monopolist(Update,Where,Data,Why).

Update = 0.5->0=0/0.5
Where = at(upper_node:weak)
Data = observing(enter)
Why = reason(prob(0, for(weak)), prob(0.5, if_not)) ;

Update = 0.5->1=0.5/0.5
Where = at(lower_node:tough)
Data = observing(enter)
Why = reason(prob(0.5, for(tough)), prob(0, if_not)) ;

Update = 0.5->1=0.5/0.5
Where = at(upper_node:weak)
Data = observing(exit)
Why = reason(prob(0.5, for(weak)), prob(0, if_not)) ;

Update = 0.5->0=0/0.5
Where = at(lower_node:tough)
Data = observing(exit)
Why = reason(prob(0, for(tough)), prob(0.5, if_not)) ;

No
?- 
*/


%=====================================
% payoffs for pure strategy profile
%=====================================

payoff([_, _, _], nature, 0).

payoff([tough, exit, coop], entrant, 0).
payoff([tough, exit, deter], entrant, 0).
payoff([tough, enter, coop], entrant, 3).
payoff([tough, enter, deter], entrant, 1).
payoff([tough, exit, coop], monopolist, 5).
payoff([tough, exit, deter], monopolist, 5).
payoff([tough, enter, coop], monopolist, 0).
payoff([tough, enter, deter], monopolist, 1).
payoff([weak, exit, coop], entrant, 0).
payoff([weak, exit, deter], entrant, 0).
payoff([weak, enter, coop], entrant, 2).
payoff([weak, enter, deter], entrant, -2).
payoff([weak, exit, coop], monopolist, 5).
payoff([weak, exit, deter], monopolist, 5).
payoff([weak, enter, coop], monopolist, 3).
payoff([weak, enter, deter], monopolist, 1).



%================================
% rational choice for monopolist
%================================

expected_utility_of_monopolist(if(T,Enter),deter(Q),utility(U=Ueq)):-
   payoff([T, Enter, deter], monopolist, Ud),
   payoff([T, Enter, coop], monopolist, Uc),
   possible_strategy_of_monopolist(deter,Q),
   W1 is integer(Q * 100),
   W2 is integer((1-Q) * 100),
   % to avoide nemerical error.
   Ueq = (W1 * Ud + W2 * Uc) /100,
   U is Ueq. 

expected_utility_of_monopolist(if(Enter),belief(weak:P),deter(Q),utility(U=Ueq)):-
   updating_belief_of_monopolist(_->(P=_),at(_:weak),observing(Enter),_),
   expected_utility_of_monopolist(if(weak,Enter),deter(Q),utility(_=Uw/100)),
   expected_utility_of_monopolist(if(tough,Enter),deter(Q),utility(_=Ut/100)),
   K1 is P * 100,
   K2 is 100 - K1,
   Ueq = (K1 * Uw + K2 * Ut)/10000,
   U is Ueq. 

rational_choice_of_monopolist(if(Enter),belief(weak:P),deter(Q),utility(U)):-
   member(Enter,[exit, enter]),
   EU=expected_utility_of_monopolist(if(Enter),belief(weak:P),deter(Q),utility(U=_)),
   max(U,EU).

/*
% prior_belief_of_monopolist(weak,0.5).

?- rational_choice_of_monopolist(E,B,D,U).

E = if(exit)
B = belief(weak, 1)
D = deter(0)
U = utility(5) ;

E = if(exit)
B = belief(weak, 1)
D = deter(1)
U = utility(5) ;

E = if(enter)
B = belief(weak, 0)
D = deter(1)
U = utility(1) ;

No
?- 
*/


%================================
% rational choice for entrant
%================================

expected_utility_of_entrant((T,Enter),if(belief(weak:P),deter(Q)),utility(U=Ueq)):-
   rational_choice_of_monopolist(if(Enter),belief(weak:P),deter(Q),utility(_)),
   payoff([T, Enter, deter], entrant, Ud),
   payoff([T, Enter, coop], entrant, Uc),
   W1 is integer(Q * 100),   % to avoide nemerical error.
   W2 is integer((1-Q) * 100),
   Ueq = (W1 * Ud + W2 * Uc) /100,
   U is Ueq. 

expected_utility_of_entrant((T,enter(P)),assess(ASSESS),utility(U=Ueq)):-
   expected_utility_of_entrant((T,enter),if(Be,De),utility(_=Ue/100)),
   expected_utility_of_entrant((T,exit),if(Bx,Dx),utility(_=Ux/100)),
   ASSESS=[if(enter,Be,De),if(exit,Bx,Dx)],
   possible_strategy_of_entrant(T,enter,P),
   W1 is integer(P * 100),   % to avoide nemerical error.
   W2 is integer((1-P) * 100),
   Ueq = (W1 * Ue + W2 * Ux) /10000,
   U is Ueq. 

/*
% abolished:21 Jun 2004.
rational_choice_of_entrant((T,enter(P)),assess(ASSESS),utility(U=Ueq)):-
   possible_type_of_entrant(T),
   EU=expected_utility_of_entrant((T,enter(P)),assess(ASSESS),utility(U=Ueq)),
   max(U,EU).
*/

%modified:21 Jun 2004.
rational_choice_of_entrant((T,enter(P)),assess(ASSESS),utility(U=Ueq)):-
   possible_type_of_entrant(T),
   EU=expected_utility_of_entrant((T,enter(P)),assess(ASSESS),utility(U=Ueq)),
   setof((T,P,U=Ueq),EU,Bag),
   max(U,member((T,P,U=Ueq),Bag)).

/*
% pure strategies case:
% prior_belief_of_monopolist(weak,0.5).

?- rational_choice_of_entrant(A,B,C).

A = weak, enter(0)
B = assess([if(enter, belief(weak:0), deter(1)), if(exit, belief(weak:1), deter(0))])
C = utility(0= (0* (100* -2+0*2)+100* (0*0+100*0))/10000) ;

A = weak, enter(0)
B = assess([if(enter, belief(weak:0), deter(1)), if(exit, belief(weak:1), deter(1))])
C = utility(0= (0* (100* -2+0*2)+100* (100*0+0*0))/10000) ;

A = tough, enter(1)
B = assess([if(enter, belief(weak:0), deter(1)), if(exit, belief(weak:1), deter(0))])
C = utility(1= (100* (100*1+0*3)+0* (0*0+100*0))/10000) ;

A = tough, enter(1)
B = assess([if(enter, belief(weak:0), deter(1)), if(exit, belief(weak:1), deter(1))])
C = utility(1= (100* (100*1+0*3)+0* (100*0+0*0))/10000) ;

No
?- 
*/


%==========================
% consistency test
%==========================

consistent_if(P,P,yes):-!.
consistent_if(_,_,no).

:- dynamic consistency/4.

consistency_test(weak:P1,tough:P2):-
   strategy_of_entrant(T,enter,P0),
   rational_choice_of_entrant((T,enter(P)),assess(ASSESS),utility(_)),
   (
    member((C,P,X),[(if(exit,B,D),0,a),(if(enter,B,D),1,b)])
    ;
    (P >0, P <1, X=c)
   ),
   member(C,ASSESS),
   consistent_if(P,P0,Y),
   CON = consistency(Y,(weak:P1,tough:P2),(T,enter(hypo:P0,best:P)),C),
   (clause(CON,true)->true;assert(CON)),
   fail.

consistency_test(_,_).


%:- dynamic strategy_of_entrant/3.

consistency_test:-
   abolish(consistency/4),
   scan_strategies_of_entrant(weak:P1,tough:P2),
   update_strategies_of_entrant(weak:P1,tough:P2),
   consistency_test(weak:P1,tough:P2),
   fail.
consistency_test:-
   display_consistency_results(yes).

scan_strategies_of_entrant(weak:P1,tough:P2):-
   possible_strategy_of_entrant(weak,enter,P1),
   possible_strategy_of_entrant(tough,enter,P2).

update_strategies_of_entrant(weak:P1,tough:P2):-
   retractall(strategy_of_entrant(weak,enter,_)),
   retractall(strategy_of_entrant(tough,enter,_)),
   assert(strategy_of_entrant(weak,enter,P1)),
   assert(strategy_of_entrant(tough,enter,P2)),
   !.

display_strategies_of_entrant(weak:P1,tough:P2):-
   S1=strategy_of_entrant(weak,enter,P1),
   S2=strategy_of_entrant(tough,enter,P2),
   nl,write(S1),nl,write(S2).

display_consistency_results(all):-
   scan_strategies_of_entrant(weak:P1,tough:P2),
   display_strategies_of_entrant(weak:P1,tough:P2),
   consistency(Y,(weak:P1,tough:P2),(T,enter(hypo:P0,best:P)),C),
   nl,
   write((consistency(Y),(T,enter(hypo:P0,best:P)),C)),
   fail.

% modified: 21 Jun 2004.

display_consistency_results(yes):-
   scan_strategies_of_entrant(weak:P1,tough:P2),
  % \+ consistency(no,(weak:P1,tough:P2),(T,enter(hypo:P0,best:P)),C),
   findall(T,consistency(yes,(weak:P1,tough:P2),(T,_),_),Bag), sort(Bag,[_,_]),
   display_strategies_of_entrant(weak:P1,tough:P2),
   consistency(yes,(weak:P1,tough:P2),(T,enter(hypo:P0,best:P)),C),
   nl,
   write((consistency(yes),(T,enter(hypo:P0,best:P)),C)),
   fail.

display_consistency_results(_).

test_a:-
  member(X,[a,b,c]),
  test(X,Y),
  write(Y),
  fail.
test(a,1).
test(b,2).
test(c,3).

:- title(A),forall(member(B,A),(nl,write(B))).

/*
%--------------------------------
% case of pure strategies 
% prior_belief_of_monopolist(weak,0.5).
%--------------------------------

?- consistency_test.

strategy_of_entrant(weak, enter, 0)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(1))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0), deter(1))
strategy_of_entrant(weak, enter, 1)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:0.5), deter(0))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.5), deter(0))

Yes
?- display_consistency_results(all).

strategy_of_entrant(weak, enter, 0)
strategy_of_entrant(tough, enter, 0)
consistency(no), (weak, enter(hypo:0, best:1)), if(enter, belief(weak:0.5), deter(0))
consistency(no), (tough, enter(hypo:0, best:1)), if(enter, belief(weak:0.5), deter(0))
strategy_of_entrant(weak, enter, 0)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(1))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0), deter(1))
strategy_of_entrant(weak, enter, 1)
strategy_of_entrant(tough, enter, 0)
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:1), deter(0))
consistency(no), (tough, enter(hypo:0, best:1)), if(enter, belief(weak:1), deter(0))
strategy_of_entrant(weak, enter, 1)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:0.5), deter(0))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.5), deter(0))

Yes
?-  

%----------------------------------------------------------------
% case of 0.1xn probabilities, and prior of weak 0.75.
%----------------------------------------------------------------

?- prior_belief_of_monopolist(A,B).

A = weak
B = 0.75 ;

A = tough
B = 0.25 ;

No
?- consistency_test.

strategy_of_entrant(weak, enter, 0)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.1))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.2))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.3))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.4))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.5))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.6))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.7))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.8))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.9))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(1))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0), deter(1))
strategy_of_entrant(weak, enter, 1)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:0.75), deter(0))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.75), deter(0))

Yes
?- 

%----------------------------------------------------------------
% case where 0.1xn probabilities and prior of weak 1/3.
%----------------------------------------------------------------

?- prior_belief_of_monopolist(A,B).

A = weak
B = 1/3 ;

A = tough
B = 0.666667 ;

No
?- consistency_test.

strategy_of_entrant(weak, enter, 0)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.1))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.2))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.3))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.4))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.5))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.6))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.7))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.8))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.9))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(1))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0), deter(1))
strategy_of_entrant(weak, enter, 1)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.2))
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.3))
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.4))
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.5))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.2))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.3))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.4))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.5))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.6))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.7))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.8))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.9))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(1))

Yes

% comparison with the output of previous program. 

?- consistency_test.

strategy_of_entrant(weak, enter, 0)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.1))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.2))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.3))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.4))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.5))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.6))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.7))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.8))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(0.9))
consistency(yes), (weak, enter(hypo:0, best:0)), if(exit, belief(weak:1), deter(1))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0), deter(1))
strategy_of_entrant(weak, enter, 1)
strategy_of_entrant(tough, enter, 1)
consistency(yes), (weak, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.2))
consistency(yes), (tough, enter(hypo:1, best:1)), if(enter, belief(weak:0.333333), deter(0.2))

Yes
?- 
*/



%==============
% utilities
%==============

% sum
% -----------------------------------------------------------  %
sum([],0).
sum([X|Members],Sum):-
   sum(Members,Sum1),
   Sum is Sum1 + X.



% maximal solution for given goal clause : a naive solver 
%---------------------------------------------------------

max(X,Goal):-
  % X: the objective variable,
  % Goal: the objective function and constraints,
  setof((X,Goal),Goal,Z),
  member((X,Goal),Z),
  \+ (
    member((Y,_),Z),
    Y > X
  ).


% probability 
% -----------------------------------------------------------  %
probability(W,P):-
   N1 is integer(1/W) + 1,
   length(L,N1),nth1(K,L,_), K1 is K - 1, P is K1/(N1 - 1).


/*
% allocation
% -----------------------------------------------------------  %
allocation(N,A,[X|Y]):-
    allocation(N,A,A,[X|Y]).
allocation(0,_,0,[]).
allocation(N,A,B,[X|Y]):-
    integer(A),
    length([X|Y],N),
    allocation(_N1,A,B1,Y),
    K is A - B1 + 1,
    length(L,K),
    nth0(X,L,X),
    B is B1 + X.
%
% probability (percentile) by using allocation
% -----------------------------------------------------------  %
probabilities(0,[]).
probabilities(N,[X|Y]):-
    integer(N),
    length([X|Y],N),
    allocation(N,100,[X|Y]).

*/

return to front page.