This package contains a few helper functions to model speakers and hearers in the RSA framework.
Defines a representation of an agent (a speaker or hearer).
params
is an associative array with the following keys:
credence
: a Distribution or a dictionary of states and their probabilitiesoptions
(optional): a list of possible acts/utterancesutility
(optional): a function that takes an act and a state and returns a numberalpha
(optional): if set, controls the agent’s softmax rationality; if unset, the agent maximizes expected utilitykinematics
(optional): a function that specifies how the agent updates its credence in response to an inputinferParams
(optional): optional update parameters: ‘inferMethod’, ‘new_p’
see choice
and learn
.
Examples:
var speaker = Agent({
credence: { 'rain': 0.2, 'sun': 0.8 },
` options: ['A', 'B', 'C'],
utility: function(act, state) { return act == 'A' ? (state == 'rain' ? 1 : 0) : 0; }
});
viz(choice(speaker));
var hearer = Agent({
credence: { 'rain': 0.2, 'sun': 0.8 },
kinematics: function(utterance) {
return function(state) {
return state == utterance;
};
}
});
viz(learn(hearer, 'rain'));
Returns the uniquely best option for an agent if there is one, else false
.
This function computes a softmax distribution over the agent’s options and
checks if the best option is at least threshold
more likely than the second
best.
Returns all elements of states
for which the output of question
is equal to
state
.
Computes a distribution over the agent’s options based on their credences and utilities.
If the agent is an expected utility mazimizer, the distribution is a uniform distribution over all options that maximize EU.
Converts a dictionary into a Categorical distribution.
dict
is an associative array {key1: prob1, key2: prob2, …}.
The returned distribution is a Categorical distribution over the keys in dict.
Defines an algebra of states by combining the dimensions of its arguments.
Examples:
var weight = [{ weight: 1 }, { weight: 2 }, { weight: 3 }];
var colour = [{ colour: 'red' }, { colour: 'green' }, { colour: 'blue' }];
// Think of these as discrete random variables.
var states = Cross(weight, colour);
// [ { weight: 1, colour: 'red' }, { weight: 1, colour: 'green' }, ... ]
var states = Cross({ weight: [1,2,3], colour: ['red','green','blue'] });
// [ { weight: 1, colour: 'red' }, { weight: 1, colour: 'green' }, ... ]
var states = Cross('sunny', 'cold');
// [ { 'sunny': false, 'cold': false }, { 'sunny': false, 'cold': true }, ... ]
Applies the function to the argument and returns the result.
Converts a list into a flat Categorical distribution over its elements.
Returns the joint distribution of several distributions, treated as independent.
Example:
var d1 = Credence({ 'rain': 0.2, 'sun': 0.8 });
var d2 = Credence({ 'cold': 0.3, 'warm': 0.7 });
var d = join({ 'weather': d1, 'temperature': d2 });
Returns the keys of a dictionary as a list.
Updates an agent’s credence by some input in accordance with their kinematics function. Returns the posterior distribution.
Returns the number of words in a string.
Partitions an array into an array of arrays based on the return value of a function.
Returns the probability of an event under a distribution. The event can be either a state, an array of states, a function state → bool, or a value of a multidimensional state, e.g. { ‘a’: 7 }.
Prints the agent’s doxastic response to each element in the given list.
Prints the choice dispositions for a family of agents.
Prints the best option for a family of agents.
Prints the agent’s decision matrix.
Conditionalizes a distribution on an event.
The event can be either a state, an array of states, a function state → bool, or
a value of a multidimensional state, e.g. { ‘a’: 7 }.
The optional params
argument can specify:
new_p
: the new probability of the event, trigger an update by Jeffrey conditioning,inferMethod
: the method passed to the WebPPL ‘infer’ function; defaults to ‘enumerate’.