This is an archived abbreviated version of jennsand.com. Information here is only kept for historical purposes.
Masters thesis code: Evaluate
Go to thesis code page for an explanation of how this code fits into the overall theory, or go to the thesis overview page for information on the entire thesis. This code is written for the JACK programming language (which has a Java base) available through AOS.
This plan causes the agent to observe the current state of fulfillment of its soft goals based on the last interaction and update its somatic markers.
Evaluate.plan
package character.generic;
import character.domaindep.SMCharacter;
import character.generic.classes.PlanGoal;
import character.generic.classes.PosNegVal;
import character.generic.classes.StateID;
import java.io.*;
import java.util.Vector;
/**
This plan causes the agent to observe the current state of fulfillment of its soft goals
based on the last interaction and update its somatic markers.
*/
public plan Evaluate extends Plan {
#handles event EvaluateGoal eg;
#uses interface SMCharacter selfCharacter;
#uses data EmotionEvents emotionEvents;
#uses data Facts facts;
#uses data Opinions opinions;
#uses data SoftGoals softGoals;
#modifies data SomaticMarkers somaticMarkers;
#uses data Activities activities;
#reasoning method
body()
{
// Pull out the min & max values for this domain
PosNegVal minMaxSGs = softGoals.getMinMaxSGs();
PosNegVal minMaxReward = softGoals.getMinMaxReward();
// Grab the min max values for emotionEvents, so can update properly
PosNegVal minMaxEmotions = emotionEvents.getMinMax();
double averageEmotion = minMaxEmotions.getMidPoint();
// Find what value of beta will be used to update somatic markers and
// opinions.
double beta = ((SMAgent) getAgent()).BETA_PREF;
// Find total reward, based on soft goals.
// Soft goals are the things that the agent is trying to achieve.
// For each soft goal there is a domain dependent calculation
// method. This function causes the inidividual level of
// achievement of each active soft goal to be updated. This level
// of achievement values are summed together to obtain the total reward
// using a weighted sum equations. The weights are based on this agent's
// soft goal personality - the importance it places on each goal (since some
// soft goals may be more important than others, e.g. having money
// vs having friends).
double totalReward =
softGoals.getTotalReward( ((SMCharacter) getAgent()).numTicks,
((SMAgent) getAgent()).getMyName(),
oeug.activityID,
((SMAgent) getAgent()).eality.getThres(),
((SMAgent) getAgent()).eality.getUptake(),
((SMAgent) getAgent()).eality.getDecay(),
averageEmotion, ((SMAgent) getAgent()).refReward);
//Update somatic markers for plans that passed (during the last activity) using somatic markers
// Only do this if the agent is supposed to be adapting.
// This process uses the reinforcement comparision technique for
// reinforcement learning. This means the new somatic marker (preference)
// is calculated using:
// new_pref = old_pref + beta*(total_reward - reference_reward)
// For each plan that was successfully passed (executed) in the last
// activity, the somatic marker value is updated.
if ( ((SMAgent) getAgent()).adaptationOn ) {
String changed = somaticMarkers.updateAllSimplePrefs(
activities.getPlansPassed(oeug.activityID),
// Now include information needed
((SMAgent) getAgent()).isInit,
totalReward, minMaxReward, ((SMAgent) getAgent()).eality.getThres(),
((SMAgent) getAgent()).eality.getStamina(),
((SMAgent) getAgent()).refReward, beta);
}
// Update current value of emotion
double uptake = 0.0;
double decay = 0.0;
// Compare reward to reference reward (not minMaxReward)
if ( totalReward >= ((SMAgent) getAgent()).refReward ) {
// Have a positive event
uptake = (((SMAgent) getAgent()).eality.getUptake()).pos;
decay = (((SMAgent) getAgent()).eality.getDecay()).pos;
}
else { // Have a negative event
uptake = (((SMAgent) getAgent()).eality.getUptake()).neg;
decay = (((SMAgent) getAgent()).eality.getDecay()).neg;
}
// "Emotion" is a series of emotion events that decay over time
// So here we add a new emotion event to our list.
double valueAdded = emotionEvents.addNewEvent(
totalReward - ((SMAgent) getAgent()).refReward,
minMaxReward,
uptake,
((SMCharacter) getAgent()).numTicks,
decay,
averageEmotion, // Use average emotion not mood ((SMAgent) getAgent()).mood,
((SMAgent) getAgent()).eality.getThres());
// Since we have added a new emotion event, we need to work out
// the new value of overall emotion.
double newEmotionIntensity = emotionEvents.currIntensityVal();
// Now update our soft goal belief of how good emotion actually is
// (rather than the estimate we used before)
boolean updatedHappy = softGoals.updateBeHappyValues(
((SMCharacter) getAgent()).numTicks,
((SMAgent) getAgent()).getMyName(),
oeug.activityID,
((SMAgent) getAgent()).eality.getThres());
// Recalculate the new reference reward using
// new_reference_reward = old_ref_reward + alpha*(total_reward-old_ref_reward)
// Where alpha is a step-size parameter similar to beta.
double newRefReward = ((SMAgent) getAgent()).calculate_ref_reward(totalReward);
// Update number of evaluations performed
((SMAgent) getAgent()).numEvaluationsPerformed++;
}
}