[Avida-SVN] r3008 - in branches/hjg-dev/source: actions cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Mon Dec 8 07:56:29 PST 2008
Author: hjg
Date: 2008-12-08 10:56:29 -0500 (Mon, 08 Dec 2008)
New Revision: 3008
Modified:
branches/hjg-dev/source/actions/PrintActions.cc
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/main/cOrganism.cc
branches/hjg-dev/source/main/cOrganism.h
branches/hjg-dev/source/main/cStats.cc
branches/hjg-dev/source/main/cStats.h
branches/hjg-dev/source/main/cTaskLib.cc
Log:
Added stats tracking and made reputation an average of donation quality.
Modified: branches/hjg-dev/source/actions/PrintActions.cc
===================================================================
--- branches/hjg-dev/source/actions/PrintActions.cc 2008-12-06 21:35:20 UTC (rev 3007)
+++ branches/hjg-dev/source/actions/PrintActions.cc 2008-12-08 15:56:29 UTC (rev 3008)
@@ -115,6 +115,7 @@
// reputation
STATS_OUT_FILE(PrintReputationData, reputation.dat);
STATS_OUT_FILE(PrintDirectReciprocityData, reciprocity.dat);
+STATS_OUT_FILE(PrintStringMatchData, stringmatch.dat);
@@ -2752,6 +2753,7 @@
// Reputation
action_lib->Register<cActionPrintReputationData>("PrintReputationData");
action_lib->Register<cActionPrintDirectReciprocityData>("PrintDirectReciprocityData");
+ action_lib->Register<cActionPrintStringMatchData>("PrintStringMatchData");
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-12-06 21:35:20 UTC (rev 3007)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-12-08 15:56:29 UTC (rev 3008)
@@ -7369,7 +7369,7 @@
// tag the organism & update the reputation
organism->SetTag(best);
- organism->SetReputation(max);
+ organism->SetAverageReputation(max);
// Donate the string
neighbor->ReceiveString(org_str, organism->GetID());
Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc 2008-12-06 21:35:20 UTC (rev 3007)
+++ branches/hjg-dev/source/main/cOrganism.cc 2008-12-08 15:56:29 UTC (rev 3008)
@@ -840,7 +840,14 @@
return;
}
+/* An organism's reputation is based on a running average*/
+void cOrganism::SetAverageReputation(int rep){
+ int current_total = GetReputation() * m_opinion->opinion_list.size();
+ int new_rep = (current_total + rep)/(m_opinion->opinion_list.size()+1);
+ SetReputation(new_rep);
+}
+
/* Check if an organism has previously donated to this organism */
bool cOrganism::IsDonor(int neighbor_id)
{
Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h 2008-12-06 21:35:20 UTC (rev 3007)
+++ branches/hjg-dev/source/main/cOrganism.h 2008-12-08 15:56:29 UTC (rev 3008)
@@ -462,6 +462,8 @@
int GetReputation();
// set the organism's reputation
void SetReputation(int rep);
+ // update the reputation to be an average on the basis of this new info
+ void SetAverageReputation(int rep);
// increment reputation
void IncReputation() { SetReputation(GetReputation() + 1); }
// get number of donors
Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc 2008-12-06 21:35:20 UTC (rev 3007)
+++ branches/hjg-dev/source/main/cStats.cc 2008-12-08 15:56:29 UTC (rev 3008)
@@ -1774,6 +1774,27 @@
}
+/* Print information about the string matching... */
+void cStats::PrintStringMatchData(const cString& filename){
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.WriteComment("Avida organism string donation information");
+ df.WriteTimeStamp();
+ df.Write(m_update, "Update [update]");
+
+ // Interate through map of information.
+
+ // df.Write(m_donate_to_donor, "Number of donate to donor [donatedonor]");
+ // df.Write(m_donate_to_facing, "Number of donate to facing [donatefacing]");
+
+ map<cString,cDoubleSum>::iterator iter;
+ for(iter = m_string_bits_matched.begin(); iter != m_string_bits_matched.end(); iter++ ) {
+// cout << "word: " << iter->first << ", count: " << iter->second << endl;
+ df.Write(iter->second.Average(), iter->first);
+ }
+
+ df.Endl();
+}
+
/* Print information about the reputation... */
void cStats::PrintReputationData(const cString& filename){
cDataFile& df = m_world->GetDataFile(filename);
Modified: branches/hjg-dev/source/main/cStats.h
===================================================================
--- branches/hjg-dev/source/main/cStats.h 2008-12-06 21:35:20 UTC (rev 3007)
+++ branches/hjg-dev/source/main/cStats.h 2008-12-08 15:56:29 UTC (rev 3008)
@@ -31,6 +31,7 @@
#include <iostream>
#include <vector>
#include <map>
+#include <string>
#ifndef defs_h
#include "defs.h"
@@ -790,9 +791,13 @@
void PrintDirectReciprocityData(const cString& filename);
void IncDonateToDonor() { m_donate_to_donor++; }
void IncDonateToFacing() { m_donate_to_facing++; }
+ void PrintStringMatchData(const cString& filename);
+ void AddStringBitsMatchedValue(cString name, int value) { m_string_bits_matched[name].Add(value); }
protected:
int m_donate_to_donor;
int m_donate_to_facing;
+ std::map <cString, cDoubleSum> m_string_bits_matched;
+
// -------- Deme replication support --------
Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc 2008-12-06 21:35:20 UTC (rev 3007)
+++ branches/hjg-dev/source/main/cTaskLib.cc 2008-12-08 15:56:29 UTC (rev 3008)
@@ -42,6 +42,7 @@
#include <cmath>
#include <climits>
#include <iomanip>
+#include <string>
// Various workarounds for Visual Studio shortcomings
#if AVIDA_PLATFORM(WINDOWS)
@@ -1951,9 +1952,12 @@
int num_matched = 0;
int test_output;
int max_num_matched = 0;
- int max_org_id;
+// int max_org_id;
int num_real=0;
+ int my_string;
+ int donated_string;
std::pair < int, int > best_string;
+ cString name;
if (!binary)
{
@@ -1980,7 +1984,8 @@
num_matched++;
}
max_num_matched = num_matched;
- max_org_id = ctx.GetOrganism()->GetID();
+// max_org_id = ctx.GetOrganism()->GetID();
+ my_string = num_matched;
}
@@ -2001,15 +2006,42 @@
*/
best_string = ctx.GetOrganism()->MatchString(string_to_match);
num_matched = best_string.first;
+ donated_string = num_matched;
if (num_matched > max_num_matched) {
max_num_matched = num_matched;
- max_org_id = best_string.second;
+// max_org_id = best_string.second;
used_received = true;
+
+ // update stats
+ name = "[useddonated";
+ name += string_to_match;
+ name += "]";
+ m_world->GetStats().AddStringBitsMatchedValue(name, max_num_matched);
+
+ } else {
+ // update stats
+ name = "[usedmy";
+ name += string_to_match;
+ name += "]";
+ m_world->GetStats().AddStringBitsMatchedValue(name, max_num_matched);
}
-// }
-// }
-
+
+ // Update stats
+ name = "[popavmine";
+ name += string_to_match;
+ name += "]";
+ m_world->GetStats().AddStringBitsMatchedValue(name, my_string);
+ name = "[popavdonated";
+ name += string_to_match;
+ name += "]";
+ m_world->GetStats().AddStringBitsMatchedValue(name, donated_string);
+ name = "[score";
+ name += string_to_match;
+ name += "]";
+ m_world->GetStats().AddStringBitsMatchedValue(name, max_num_matched);
+
+
// Update the reputation of the organism whose string we used!
// Check if it the organisms string:
/* cOrganism * neighbor = ctx.GetOrganism()->GetNeighbor();
More information about the Avida-cvs
mailing list