|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--utilities.Individual
A class that implements individuals for agent based modeling. This is compatible with any form of game and either reinforcement or bayesian learning. Very little processing is done in this class. Only some basic sanity checks for assignments. In addition, I have removed functionality for keeping track of history of play beyond one round. For learning rules which require longer memory of actions, one should implement another class. (Keeping track of past play was very taxing on resources, and so was removed.)
Constructor Summary | |
Individual()
Returns and individual object. |
|
Individual(int i)
Returns and individual object like the simple constructor, but also sets an id. |
|
Individual(int i,
int s,
MersenneTwister r,
Individual[] nw,
ConnectionRule c,
LearningRule l)
Returns and individual object, but with more initialized. |
Method Summary | |
void |
addAlpha(double a,
int d)
Adds a value to the alpha function, used in updating |
void |
addBeta(double a,
int d)
Adds a value to the alpha function, used in updating |
void |
addConnected(Individual i)
Adds a neighbor to an individuals current neighbors. |
void |
addPayoff(int p)
Adds a value to the current payoff |
void |
addStratWeight(int p,
double w)
Adds a specified weight to a particular strategy. |
void |
addStratWeight(int d,
int p,
double w)
Adds a specified weight to a particular strategy. |
int |
chooseStrat()
Uses the learning rule to choose a strategy |
void |
clearConnected()
Clears the list of neighbors. |
void |
clearDomainWeights(int d)
A function that will clear the weights in only one domain, but leave the others intact |
void |
clearStratWeights()
A function to reset all strategy weights to 1.0. |
void |
clearStratWeights(int n)
A function to reset all strategy weights to 1.0. |
void |
clearStratWeights(int n,
int d)
A function to reset all stategy weights to 1.0. |
void |
formConnections()
Uses the connection rule to update the neighborhood. |
double[] |
getAlpha()
Gets the alpha value |
double |
getAlpha(int d)
Gets the alpha value for a particular domain |
double |
getBelief(int b)
Returns an agent's beliefs about a particular state in a model where the agent is only learning about one thing. |
double |
getBelief(int d,
int b)
Returns an agent's belief about a particular state in a model where there are many things about which the agent may be learning. |
double[][] |
getBeliefs()
Returns an agent's beliefs. |
double[] |
getBeta()
Gets the beta value |
double |
getBeta(int d)
Gets the beta value for a particular domain |
java.util.HashSet |
getConnected()
Returns the individuals neighbors |
ConnectionRule |
getConnectionRule()
Returns the connection rule |
double |
getConstraint()
Returns the constraints on generating new beliefs in a one domain model |
double |
getConstraint(int d)
Returns the constraints on generating new beliefs for a particular domain. |
double |
getDiscount()
Returns the discount factor |
double[] |
getDomainWeights(int d)
Returns the full set of weights for a particular domain |
Game |
getGame()
Returns the game |
int |
getId()
Returns an the individuals id number |
int |
getLastPayoff()
Returns the payoff from the last round |
int |
getLastStrat()
This returns the strategy used on the last round |
LearningRule |
getLearningRule()
Returns the learning rule |
int |
getMaxalpha()
Returns the value of maxalpha used to contrain the reseting of alpha. |
int |
getMaxbeta()
Returns the value of maxbeta. |
int |
getMaxWeight()
Gets the maxWeight |
double |
getMutation()
Calls the mutationRules get function. |
MutationRule |
getMutationRule()
|
Individual[] |
getNetwork()
Returns the network (all other individuals in the model). |
int |
getPayoff()
Returns the payoff from the last round |
MersenneTwister |
getRandom()
Returns the random number generator |
int |
getStrat()
Returns the current strategy, if its not set chooses one. |
double[] |
getWeights()
Returns the current weights. |
double |
getWeights(int p)
Returns the weights for a current strategy |
double |
getWeights(int d,
int p)
Returns the weights for a current strategy |
void |
initAB(int d)
Initializes the alpha's without setting them. |
void |
initDomains(int d)
Initializes the beliefs for a multi-domain model. |
void |
initStart(int s)
The initializes the individual for single domain models by giving them random beliefs and randomizing the weights The random beliefs are constrained by the zeroconstraint. |
void |
initStart(int d,
int s)
The initializes the individual for multi domain models by giving them random beliefs and randomizes the the wieghts The random beliefs are constrained by the zeroconstraint. |
void |
mutate()
Calls the mutationRules mutate function. |
void |
playGame()
Plays the game with each neighbor. |
void |
randBeliefs(int states)
Randomizes an agents beliefs, this requires that the random be set. |
void |
randBeliefs(int states,
boolean constrained)
Randomizes an agents beliefs, this requires that the random be set. |
void |
randBeliefs(int states,
int d)
Randomizes an agents beliefs, this requires that the random be set. |
void |
randBeliefs(int states,
int d,
boolean constrained)
Randomizes an agents beliefs, this requires that the random be set. |
void |
randomAB()
Randomizes alpha and beta. |
void |
randomAB(int d)
Randomizes alpha and beta. |
void |
randomAB(int a,
int b,
int d)
Randomizes alpha and beta. |
void |
randStratWeights(int n)
Randomizes the weights using the set maximum. |
void |
randStratWeightsD(int n,
int d)
Randomizes the weights using the set maximum. |
void |
reset()
Resets for a new generation. |
void |
setAlpha(double[] a)
Sets alpha at a specific value |
void |
setAlpha(double a,
int d)
Sets alpha at a specific value |
void |
setBeliefs(double[] b)
A function to set the Bayesian beliefs for one domain. |
void |
setBeliefs(double[][] b)
A function to set the Bayesian beliefs for multi-domain situations. |
void |
setBeliefs(double[] b,
int d)
A function to set the Bayesian beliefs for one domain in mutli-domain learning situations. |
void |
setBeta(double[] b)
Sets beta at a specific value |
void |
setBeta(double b,
int d)
Sets beta at a specific value |
void |
setConnected(java.util.HashSet c)
Sets the neighbors to a particular HashSet of individuals |
void |
setConnectionRule(ConnectionRule c)
Sets the connection rule, which determines how the individual updates its neighborhood |
void |
setConstraint(double c)
Sets a constraint that initializations can be constrained by. |
void |
setConstraint(double[] c)
Sets a constraint that initializations can be constrained by. |
void |
setConstraint(int d,
double c)
Sets a constraint that initializations can be constrained by. |
void |
setDiscount(double d)
Sets a discount value |
void |
setGame(Game g)
Sets the game |
void |
setId(int i)
Sets the id number. |
void |
setLastPayoff()
Sets the last round payoff equal to the current payoff |
void |
setLastStrat()
This updates the strategy for the next round by setting the last round strat equal to the current strat. |
void |
setLearningRule(LearningRule l)
Sets the learning rule for updating strategies |
void |
setMaxalpha(int maxalpha)
Sets the value of maxalpha. |
void |
setMaxbeta(int maxbeta)
Sets the value of maxbeta. |
void |
setMaxWeight(int m)
Sets the maxWeight |
void |
setMutation(double m)
Calls the mutationRule set function. |
void |
setMutationRule(MutationRule m)
|
void |
setNetwork(Individual[] nw)
Sets the network (all other individuals in the model). |
void |
setPayoff(int p)
Sets the payoff from the last generation |
void |
setRandom(MersenneTwister r)
Sets the random number generator |
void |
setStrat(int s)
Sets the current strategy of a user |
void |
setStratWeights(double[] s)
Sets the strategy weights to a specific value. |
void |
setStratWeights(double[][] s)
Sets the strategy weights to a specific value. |
void |
setStratWeights(int p,
double s)
Sets the strategy weight for a particular strategy to a specific value. |
void |
setStratWeights(int d,
int p,
double s)
Sets the strategy weight for a particular strategy to a specific value. |
void |
uniformBeliefs(int states)
Generates uniform beliefs over a number of states. |
void |
uniformBeliefs(int states,
int d)
Generates uniform beliefs over a number of states. |
void |
update()
Updates after play is complete. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Individual()
public Individual(int i)
i
- The idpublic Individual(int i, int s, MersenneTwister r, Individual[] nw, ConnectionRule c, LearningRule l)
i
- The ids
- The number of strategiesr
- The random number generatornw
- The networkc
- The connection rulel
- The learning ruleMethod Detail |
public void setId(int i)
i
- the id numberpublic int getId()
public void setBeliefs(double[] b) throws ModelError
b
- A 1-D double array containing beliefs.
ModelError
- if there is something wrong with the beliefspublic void setBeliefs(double[][] b) throws ModelError
b
- A 2-D double array containing beliefs.
ModelError
- if there is something wrong with the beliefspublic void setBeliefs(double[] b, int d) throws ModelError
b
- A 2-D double array containing beliefs.d
- The domain to set
ModelError
- if there is something wrong with the beliefspublic double[][] getBeliefs()
public double getBelief(int b)
b
- the state we're interested in
public double getBelief(int d, int b)
d
- the domain that the agent is learning aboutb
- the thing about which where interested
public void setConstraint(double c) throws ModelError
c
- A double representing the constraint
ModelError
- if the constraint is outside of [0,1]public void setConstraint(double[] c) throws ModelError
c
- A double array representing the constraints
ModelError
- if the constraint is outside of [0,1]public void setConstraint(int d, double c) throws ModelError
d
- the domain in which the constraint appliesc
- A double representing the constraint
ModelError
- if the constraint is outside of [0,1]public double getConstraint()
public double getConstraint(int d)
d
- the domain for the constraint
public void initDomains(int d)
d
- the number of domains in the modelpublic void randBeliefs(int states, boolean constrained)
states
- the number of states over which to generate beliefsconstrained
- a boolean to decide if we'll pay attention to the constraintpublic void randBeliefs(int states, int d, boolean constrained)
states
- the number of states over which to generate beliefsd
- which domain should be randomly assignedconstrained
- a boolean to decide if we'll pay attention to the constraintpublic void randBeliefs(int states)
states
- the number of states over which to generate beliefspublic void randBeliefs(int states, int d)
states
- the number of states over which to generate beliefsd
- the domain in which the beliefs should be generatedpublic void uniformBeliefs(int states)
states
- the number of statespublic void uniformBeliefs(int states, int d)
states
- the number of statesd
- the domain in which to create uniform beliefspublic void setMaxWeight(int m)
m
- The max weightpublic int getMaxWeight()
public void clearStratWeights()
public void clearDomainWeights(int d)
d
- The domain to clearpublic void clearStratWeights(int n)
n
- the number of states which require weightspublic void clearStratWeights(int n, int d)
n
- the number of strategies that require weightsd
- the number of domainspublic void randStratWeights(int n)
n
- The number of strategiespublic void randStratWeightsD(int n, int d)
n
- The number of strategiespublic void setStratWeights(double[] s) throws ModelError
s
- the weights
ModelError
- if any weight is negativepublic void setStratWeights(double[][] s) throws ModelError
s
- the weights
ModelError
- if any weight is negativepublic void setStratWeights(int p, double s) throws ModelError
p
- the strategy whose weight we will changes
- the new weight
ModelError
- if the weight is less than 0public void setStratWeights(int d, int p, double s) throws ModelError
d
- the domainp
- the strategy whose weight we will changes
- the new weight
ModelError
- if the weight is less than 0public void addStratWeight(int p, double w) throws ModelError
p
- the strategy to updatew
- the amount to add
ModelError
- if the number to add is negativepublic void addStratWeight(int d, int p, double w) throws ModelError
d
- the domainp
- the strategy to updatew
- the amount to add
ModelError
- if the number to add is negativepublic double[] getWeights()
public double getWeights(int p)
p
- the strategy for which we want weights
public double getWeights(int d, int p)
d
- the domain weights.p
- the strategy for which we want weights
public double[] getDomainWeights(int d)
d
- the domainpublic void setDiscount(double d) throws ModelError
d
- the discount factor
ModelError
- if the discount factor is outside [0,1]public double getDiscount()
public int getMaxalpha()
public void setMaxalpha(int maxalpha)
maxalpha
- The value to assign maxalpha.public int getMaxbeta()
public void setMaxbeta(int maxbeta)
maxbeta
- The value to assign maxbeta.public double[] getAlpha()
public double[] getBeta()
public double getAlpha(int d)
d
- the domain
public double getBeta(int d)
d
- the domain
public void addAlpha(double a, int d)
a
- amount to add to alphad
- the domain to which to addpublic void addBeta(double a, int d)
a
- amount to add to alphad
- the domain to which to addpublic void setAlpha(double a, int d)
a
- the value to set alphad
- the domainpublic void setBeta(double b, int d)
b
- the value to set betad
- the domainpublic void setAlpha(double[] a)
a
- the value to set alphapublic void setBeta(double[] b)
b
- the value to set betapublic void randomAB(int a, int b, int d)
a
- Upper bound for alphab
- Upper bound for betad
- The number of domainspublic void randomAB(int d)
d
- The number of domainspublic void randomAB()
public void initAB(int d)
d
- the number of domainspublic void setMutationRule(MutationRule m)
public MutationRule getMutationRule()
public void setMutation(double m) throws ModelError
m
- the mutation rate
ModelError
- if the mutation rate is outside of [0,1]public double getMutation()
public void mutate() throws ModelError
ModelError
public void setNetwork(Individual[] nw)
nw
- an array of Individuals that constitutes the networkpublic Individual[] getNetwork()
public void clearConnected()
public void setConnected(java.util.HashSet c)
c
- The new neighborspublic void addConnected(Individual i)
i
- The individual to add to the list of neighborspublic java.util.HashSet getConnected()
public void setRandom(MersenneTwister r)
r
- The MersenneTwister random number generatorpublic MersenneTwister getRandom()
public void setConnectionRule(ConnectionRule c)
c
- The connection rulepublic void formConnections()
public ConnectionRule getConnectionRule()
public void setLearningRule(LearningRule l)
l
- The learning rule to setpublic LearningRule getLearningRule()
public void setStrat(int s) throws ModelError
s
- The strategy
ModelError
- if the strategy is negative or bigger than the possible number of
stratspublic int chooseStrat() throws ModelError
ModelError
- if there is a problem selecting the strategypublic int getStrat() throws ModelError
ModelError
- if there is a problem choosing the strategy.public int getLastStrat()
public void setLastStrat()
public int getPayoff()
public void setPayoff(int p)
p
- the payoffpublic void addPayoff(int p)
p
- The amount to addpublic int getLastPayoff()
public void setLastPayoff()
public void setGame(Game g)
g
- The gamepublic Game getGame()
public void reset() throws ModelError
ModelError
- If there is some problempublic void playGame() throws ModelError
ModelError
- If there are any problemspublic void update() throws ModelError
ModelError
- From processpayoffpublic void initStart(int s) throws ModelError
s
- The number of strategies
ModelError
- If there are any problemspublic void initStart(int d, int s) throws ModelError
s
- The number of strategies
ModelError
- If there are any problems
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |