# Coordinated Intelligence¶

Implements Coordinated PGT Intelligence for SemiNFG objects

Created on Tue Mar 12 17:38:37 2013

pynfg.pgtsolutions.intelligence.coordinated.coordinated_MC(G, S, noise, X, M, innoise=1, delta=1, integrand=None, mix=False, satisfice=None)[source]

Run Importance Sampling on strategies for PGT Intelligence Calculations

For examples, see below or PyNFG/bin/stackelberg.py for SemiNFG or PyNFG/bin/hideandseek.py for iterSemiNFG

Parameters: G (SemiNFG or iterSemiNFG) – the game to be evaluated S (int) – number of policy profiles to sample noise (float) – the degree of independence of the proposal distribution on the current value. 1 is independent, 0 returns no perturbation. X (int) – number of samples of each policy profile M (int) – number of random alt policies to compare innoise (float) – the perturbation noise for the loop within iq_calc to draw alt CPTs to compare utilities to current CPT. delta (float) – the discount factor (ignored if SemiNFG) integrand (func) – a user-supplied function of G that is evaluated for each s in S mix (bool) – False if restricting sampling to pure strategies. True if mixed strategies are included in sampling. Default is False. satisfice (SemiNFG or iterSemiNFG) – game G such that the CPTs of G together with innoise determine the intelligence satisficing distribution. intel - a sample-keyed dictionary of player-keyed iq dictionaries funcout - a sample-keyed dictionary of the output of the user-supplied integrand. weight - a sample-keyed dictionay of player-keyed importance weight dictionaries.

Note

This is the coordinated-approach because intelligence is assigned to a player instead of being assigned to a DecisionNode

Example:

def welfare(G):
#calculate the welfare of a single sample of the SemiNFG G
G.sample()
w = G.utility('1')+G.utility('2') #'1' & '2' are player names in G
return w

import copy
GG = copy.deepcopy(G) #G is a SemiNFG
S = 50 #number of MC samples
X = 10 #number of samples of utility of G in calculating iq
M = 20 #number of alternative strategies sampled in calculating iq
noise = .2 #noise in the perturbations of G for MC sampling

from pynfg.pgtsolutions.intelligence.coordinated import coordinated_MC

intelMC, funcoutMC, weightMC = coordinated_MC(GG, S, noise, X, M,
innoise=.2,
delta=1,
integrand=welfare,
mix=False,
satisfice=GG)

pynfg.pgtsolutions.intelligence.coordinated.coordinated_MH(G, S, density, noise, X, M, innoise=1, delta=1, integrand=None, mix=False, satisfice=None)[source]

Run Metropolis-Hastings on strategies for PGT Intelligence Calculations

For examples, see below or PyNFG/bin/stackelberg.py for SemiNFG or PyNFG/bin/hideandseek.py for iterSemiNFG

Parameters: G (SemiNFG or iterSemiNFG) – the game to be evaluated S (int) – number of MH iterations density (func) – the function that assigns weights to iq noise (float) – the degree of independence of the proposal distribution on the current value. 1 is independent, 0 returns no perturbation. X (int) – number of samples of each policy profile M (int) – number of random alt policies to compare innoise (float) – the perturbation noise for the loop within iq_calc to draw alt CPTs to compare utilities to current CPT. delta (float) – the discount factor (ignored if SemiNFG) integrand (func) – a user-supplied function of G that is evaluated for each s in S mix (bool) – if true, proposal distribution is over mixed CPTs. Default is False. satisfice (SemiNFG or iterSemiNFG) – game G such that the CPTs of G together with innoise determine the intelligence satisficing distribution. intel - a sample-keyed dictionary of player-keyed iq dictionaries funcout - a sample-keyed dictionary of the output of the user-supplied integrand. dens - a list of the density values, one for each MH draw.

Note

This is the coordinated-approach because intelligence is assigned to a player instead of being assigned to a DecisionNode

Example:

def density(iqdict):
#calculate the PGT density for a given iqdict
x = iqdict.values()
y = np.power(x,2)
z = np.product(y)
return z

def welfare(G):
#calculate the welfare of a single sample of the SemiNFG G
G.sample()
w = G.utility('1')+G.utility('2') #'1' & '2' are player names in G
return w

import copy
GG = copy.deepcopy(G) #G is a SemiNFG
S = 50 #number of MH samples
X = 10 #number of samples of utility of G in calculating iq
M = 20 #number of alternative strategies sampled in calculating iq
noise = .2 #noise in the perturbations of G for MH sampling

from pynfg.pgtsolutions.intelligence.coordinated import coordinated_MH

intelMH, funcoutMH, densMH = coordinated_MH(GG, S, density, noise, X, M,
innoise=.2,
delta=1,
integrand=welfare,
mix=False,
satisfice=GG)

pynfg.pgtsolutions.intelligence.coordinated.coordinated_calciq(p, G, X, M, mix, delta, innoise, satisfice=None)[source]

Estimate IQ of player’s strategy

Parameters: p (str) – the name of the player whose intelligence is being evaluated. G (SemiNFG or iterSemiNFG) – the iterated semi-NFG to be evaluated X (int) – number of samples of each policy profile M (int) – number of random alt policies with which to compare mix (bool) – if true, proposal distribution is over mixed CPTs. Default is False. delta (float) – the discount factor (ignored if SemiNFG) innoise (float) – the perturbation noise for the inner loop to draw alt CPTs satisfice (SemiNFG or iterSemiNFG) – game G such that the CPTs of G together with innoise determine the intelligence satisficing distribution. an estimate of the fraction of alternative strategies that yield lower expected utility than the current policy.

PGT Solutions

#### Next topic

Uncoordinated Intelligence