Getting a variable to shift on a scale.

Tips and questions about scripting your Verbot®.

Moderator: Staff

Getting a variable to shift on a scale.

Postby HoboHarty » Fri Feb 17, 2012 1:28 pm

I am having problems with my current University project, I am currently researching affective computing with agents. I chose verbots as it offers the most flexibility, and it is cheap to host on-line once I have it running.

My Idea: I am trying to make the agent affective through detecting peoples expressive emotions. Such as "I am getting angry" would make the bot aware that the mood is sliding down the way. I had this idea that I could make a Var that adapts to these expressions, so the previous example of "angry" would -2 to the var, and then the bot would check where the mood is, and comment on their mood. It would work both ways, so if they express happiness it would go up the scale, and the agent will act on this.

My issue is that I do not know C# very well, at all, I was wondering what approach other people would take for this idea? I am not expecting the answer as much as a general pointer in the right direction right now.

Thanks in advance.
Sorry if someone has already posted a similar idea like this before.

HoboHarty.
HoboHarty
ShyBot
ShyBot
 
Posts: 7
Joined: Thu Feb 16, 2012 12:36 pm
Location: Dundee, UK

Re: Getting a variable to shift on a scale.

Postby HoboHarty » Fri Feb 17, 2012 2:45 pm

I have got the bot capable of adding +1 to a var, but I cannot figure out how to make the new value carry into the function again when needed, as it resets it to 10. And when I tried to make it carry through, I always got that it cannot compile as "moodSet" is not defined.

Code: Select all
double moodSet = 10;
double moodChange = 1;
bool bGood = true;

try{moodChange = Double.Parse(mChange.Trim());} catch{bGood = false;}

if(bGood)
{
moodSet = moodSet + moodChange;
return moodSet.ToString();
}
else
return moodSet + " + " +mChange;


I adapted the function from this thread: http://www.verbots.com/forums/viewtopic.php?t=2696 by leseur sylvain.
HoboHarty
ShyBot
ShyBot
 
Posts: 7
Joined: Thu Feb 16, 2012 12:36 pm
Location: Dundee, UK

Re: Getting a variable to shift on a scale.

Postby HoboHarty » Fri Feb 17, 2012 6:16 pm

Managed to answer my own question :oops:
HoboHarty
ShyBot
ShyBot
 
Posts: 7
Joined: Thu Feb 16, 2012 12:36 pm
Location: Dundee, UK

Re: Getting a variable to shift on a scale.

Postby MikeA » Fri Feb 17, 2012 7:11 pm

Something I noticed, rather than double, you'd want int. Just a bit cleaner, as presumably your not dealing in fractions.
MikeA
MightyBot
MightyBot
 
Posts: 318
Joined: Sun Mar 22, 2009 1:35 pm

Re: Getting a variable to shift on a scale.

Postby JonC » Fri Feb 17, 2012 9:28 pm

Also,
it wouldn't be a bad idea to search this forum (if you've not done so yet).
there have been previous posts on creating/manipulating a Verbot's mood, e.g.:
http://www.verbots.com/forums/viewtopic.php?f=7&t=2976&p=11983
http://www.verbots.com/forums/viewtopic.php?f=7&t=3001&p=12219
(There are others too.)
----
I use a bit of vcm code to do this:

Function name: Mood
Parameters: string state, int effect, int limit, int threshold
Code:
// returns a "mood" variable depending on starting state "state", the direction (+/-) and value of the 'mood' change "effect", upper limit "limit" (lower assumed zero) and the probability of change determined by "threshold" in milliseconds (lower means more probable).

int x = 0;
x = int.Parse(state);
int t1 = 1;
DateTime time = DateTime.Now;
t1= time.Millisecond;
if(t1>threshold)
{x += effect; if(x> limit) x = limit; if (x<0) x = 0;}
return x.ToString();

---
What this does is allows you to increment or decrement the "mood" value (or any other!) held in a vars-variable i.e. [mood] by the amount specified in "effect" and allows a random effect by as to whether or not the mood is changed by "threshold".
This means that the bot may or may no be cheered up/angered/etc. by what you say depending on the value of threshold. (If you are certain that you want to change the mood, set this to 0.)
Clearly, although (with the exception of [mood] itself) all parameters are passed as integers, any of these can be derived as the result of prior events.
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Re: Getting a variable to shift on a scale.

Postby Mapestone » Mon Feb 20, 2012 12:04 pm

HoboHarty wrote:...I am currently researching affective computing with agents. ...
Great research topic Hobo. Is this project for a thesis? My favorite site on this subject is wefeelfine.org
Welcome to the Verbot Community.
Mapestone
PowerBot
PowerBot
 
Posts: 116
Joined: Tue Apr 06, 2010 1:34 am

Re: Getting a variable to shift on a scale.

Postby HoboHarty » Tue Feb 21, 2012 12:43 pm

Thanks for all the help people, I ended up using code i found from another thread, took a while to find it though. I have now made it so the Bot gets most of its judgement from the question of "how are you". And it basically follows a pattern of: [possession][strength][power], possession being how the user attaches the emotion to him/her. strength being how much emphasis they put onto it. For example "I am VERY angry today". And then the actual mood itself.

This is my Honours Project for University in the UK. I am researching into customer support agents that helps the user, but tries to detect stress levels through their language alone, because not everyone has a webcam, microphone, or blood pressure tests in there house. Its turning out to be quite a challenge, at the moment I am trying to get the bot to constant look out for keywords in every message with a .contains() function. However, it is more than a little complex as a function call is required on every output, is there an easier way to keep a function constantly running, and looking for words?
HoboHarty
ShyBot
ShyBot
 
Posts: 7
Joined: Thu Feb 16, 2012 12:36 pm
Location: Dundee, UK

Re: Getting a variable to shift on a scale.

Postby JonC » Tue Feb 21, 2012 2:32 pm

Yes,
I think you need the global processing options for this:
http://www.verbots.com/forums/viewtopic.php?f=1&t=2763&p=1190
By modifying the OnAfterRuleFired, it could check for a range of "keywords" in every input.

You might also need to use hashtable vars to access all the vars you need to. For examples see:
http://www.verbots.com/forums/viewtopic.php?f=7&t=1490&p=7410
Hope this helps.
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Re: Getting a variable to shift on a scale.

Postby HoboHarty » Tue Feb 21, 2012 3:11 pm

Did you mean to link to the off topic thread about space? Couldn't see anything within it about the function. I have had a scout around, but right now that code looks beyond me, so it will need to go to the bottom of the list, for now what I will do is just analyse open answered questions where the users whole input is stored to a var, the model I am making is a pretend holiday customer services agent, so it might ask "I am sorry to hear that you had a problem with the hotels conditions, could you explain exactly what happened?" I will then hunt a series of arrays (I've already made this for that first question I mentioned) to see how the express their problems. If I get time before I have to evaluate my agent and do the write up, I will look into that function a bit more. Thanks for the links though :)
HoboHarty
ShyBot
ShyBot
 
Posts: 7
Joined: Thu Feb 16, 2012 12:36 pm
Location: Dundee, UK

Re: Getting a variable to shift on a scale.

Postby JonC » Wed Feb 22, 2012 7:38 am

Err, no I didn't.
Not sure what happened there! Try: http://www.verbots.com/forums/viewtopic.php?t=2763
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Re: Getting a variable to shift on a scale.

Postby Mapestone » Wed Feb 22, 2012 12:06 pm

HoboHarty wrote: is there an easier way to keep a function constantly running, and looking for words?
I don't understand. Why not use the Verbot engine's keyword matching ability? I'll collect the bits I have on this topic and upload it by the weekend. For starters, accepting the premise that there are but a few real emotions (Paul Eckman, "Emotions Revealed"), all others are grades and mixes of these (sad, angry, fear/surprise, joy). Keywords may be grouped into one or more synonym sets. Such as: Angry, synSet {angry, resent*, irritate*, enrage*, furious, annoy*, inflame*, provoke*, infuriate*, offend*, sullen*, indignant, irate, wrath*, cross, sulk*, bitter, frustrat*, grump*, boil*, fuming, fume, confuse*, awkward, bewilder*} ...
Accepting the additional premise that any strong emotion may contribute to stress, assign points to these words:
User: "At first I was angry, but then I realized that I tried to put the cap on upside down."
Angry + Realized = (100+5)/2 = stress level = 52% ... or something similar.
Mapestone
PowerBot
PowerBot
 
Posts: 116
Joined: Tue Apr 06, 2010 1:34 am

Re: Getting a variable to shift on a scale.

Postby JonC » Wed Feb 22, 2012 9:31 pm

Good thought Mapestone, but it may depend rather on the structure of H.Harty's Kb.
The potential problem I see with that method is that either lots of rules have the same "keyword" inputs (assuming that you are continually testing for emotion) which may:
a). make rule firing somewhat random, or,
b). need very carefully crafted inputs (along the synonym matching lines I think) and multiple conditional outputs to process this rule by rule.

Thus my reasoning was that if the Verbot could be got to make this a "background task" by using VerbotStandard and OnAfterRuleFired, then:
a). you'd only need to write the emotion coding once and
b). It would operate automatically on the user's every response, thus allowing the 'bot to (easily) continuously "monitor" the user's emotions.
The downside is possibly that the 'bot's responses would slow (since it is now doing two things each time a rule fires), but that would be largely a function of processor power, so you probably wouldn't notice it on a modern machine (unlike mine! :oops: )
- - - - -
Of course, being me, I could just be doing it the hard way ... :roll:
- - - - -
That said, I do like your suggestion of using numeric values to represent the state of the user.
If we take what you say about emotions being mixes of sad, angry, fear/surprise, joy, then it occurs to me that we could express the emotional state with just two numbers:
Imagine a "compass" with Happy/Sad as North/South and Anger/fear as East/West.
One number (a "degree" number") would point to the emotion(s) in play (though not opposites) and a "radius" number would reflect intensity.
(Surprise, I'm assuming, is a "muted" fear response, thus represented by a short radius "pointing" at fear.)
I don't know if this is fine enough resolution for H.H., but it would be a simple starting point.
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Re: Getting a variable to shift on a scale.

Postby HoboHarty » Thu Feb 23, 2012 2:47 pm

The function OnAfterRuleFired will probably be my best bet for just now. As I understand how it works now that ive read up on it. I will need to look up Mapestone's method though, thanks for the link to the rules. Now i just need to look into how to make the function look at user inputs all the time in the background. As at the moment if I want to recalculate a mood, I have to call it at the end of each output, which is just asking for errors on later dates.
HoboHarty
ShyBot
ShyBot
 
Posts: 7
Joined: Thu Feb 16, 2012 12:36 pm
Location: Dundee, UK

Re: Getting a variable to shift on a scale.

Postby JonC » Fri Feb 24, 2012 3:41 pm

H.H.
I don't see why you need to call the code to re-calculate mood after each rule. You can do this as part of the OnAfterRuleFired function.
State s will contain the StringTable vars (not Hashtable as I previously said! :oops: ).
So, using VerbotStandard, append a line to _startup which <mem.set ...>s a vars-variable.
Re-save the kb (to another location preferably - to avoid changing the original version), then open the VerbotStandard vcm, and in OnAfterRuleFired, remove the /* and */ remming commands. Save and test (in case you've made a mistake!)the code.
Now if you run the VerbotStandard kb, you will see that State s contains your vars-variable (as part of s.Vars).
Therefore, once you learn how to "extract" your vars from state s, you can automatically update it and "put it back" into state s (by doing an extraction "in reverse").
See: http://www.verbots.com/forums/viewtopic.php?f=7&t=3008) for how to extract a vars-variable from state s.
and: http://www.verbots.com/forums/viewtopic.php?f=7&t=3065 for a necessary point.
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Re: Getting a variable to shift on a scale.

Postby Mapestone » Tue Feb 28, 2012 12:32 am

Hello HoboH,
I've uploaded my thoughts on this subject as mood_metrics.vkb in the Reference Section of the downloads.
By post processing recycled user input after a KnowledgeBase Rule Output it has little effect (hopefully none) on the outcome. My design philosophy: push the Engine to its' Limits. Code only when necessary.

mood_metrics bins user-defined lists of words into four mood categories: anger, fear, joy, and love.
Each word is assigned a relative score from 1 to 10.
For example: Anger Words(score): anger(10), grumpy(4), bewildered(1)

Using the external command file VerbotFileFeeder.cmd (another download) I scanned two poems.
mood_metrics produced the following statistics:
===============================================================
Elizabeth Barrett Browning: How do I love thee? Let me count the ways.
User Input Line Count: 15
Total Number of Words: 183
Anger Words: 0
Anger Total Score: 0
Anger Overall Average: 0
Fear Words: 0
Fear Total Score: 0
Fear Overall Average: 0
Joy Words: 0
Joy Total Score: 0
Joy Overall Average: 0
Love Words: 12
Love Total Score: 115
Love Overall Average: 0.628415300546448
Sadness Words: 0
Sadness Total Score: 0
Sadness Overall Average: 0
====================================
Emily Bronte: Death
User Input Line Count: 32
Total Number of Words: 326
Anger Words: 0
Anger Total Score: 0
Anger Overall Average: 0
Fear Words: 1
Fear Total Score: 10
Fear Overall Average: 0.030
Joy Words: 1
Joy Total Score: 10
Joy Overall Average: 0.030
Love Words: 1
Love Total Score: 10
Love Overall Average: 0.030
Sadness Words: 2
Sadness Total Score: 19
Sadness Overall Average: 0.058
====================================

This approach shows some promise, though there is plenty of room for improvement.
Mapestone
PowerBot
PowerBot
 
Posts: 116
Joined: Tue Apr 06, 2010 1:34 am

Next

Return to Scripting

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest