Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats managers #63

Merged
merged 53 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2164781
Last commit before I completely overhaul OEE.h
emilydolson Apr 6, 2016
eba2749
Merge branch 'master' of github.com:devosoft/Empirical
emilydolson Apr 8, 2016
d70eea3
Merge branch 'master' of github.com:devosoft/Empirical
emilydolson Apr 19, 2016
4e615bc
Adding update signal
emilydolson Apr 22, 2016
24aa95f
Merge branch 'master' of github.com:devosoft/Empirical
emilydolson Apr 22, 2016
0ebbf5c
Complexity and Ecology work
emilydolson May 11, 2016
b787d67
Fixed merge conflict
emilydolson May 11, 2016
2c7be2f
Merge branch 'master' of github.com:devosoft/Empirical
emilydolson May 11, 2016
6ae3880
All metrics work
emilydolson May 11, 2016
2abc7e5
All metrics work
emilydolson May 12, 2016
fdd1819
All metrics work, skeletonization streamlined
emilydolson May 13, 2016
570aab4
Separate generations deduction works now
emilydolson May 13, 2016
e718cf2
Merge branch 'master' of github.com:devosoft/Empirical
emilydolson May 13, 2016
24e903a
Cleaned up OEE.h, added comments
emilydolson May 13, 2016
de8731e
Added example for OEE tracker
emilydolson May 14, 2016
7481633
Fixed bug in change deque length, added fitness tracking
emilydolson May 14, 2016
bcb6fa9
Merge branch 'master' of github.com:devosoft/Empirical
emilydolson May 14, 2016
86fe09b
Added print statement to verify settings
emilydolson May 14, 2016
88b491e
Added template specializations to appease std::vector
emilydolson May 15, 2016
8aac649
Made template specialization of ShannonDiversity to take a World
emilydolson May 18, 2016
1c525dc
Worlds are iterable
emilydolson May 18, 2016
7c51aeb
Fixing merge conflict
emilydolson May 18, 2016
779a6f4
Use world iterator in stats
emilydolson May 19, 2016
89150a8
Merge branch 'master' of github.com:devosoft/Empirical into nullorgs
emilydolson May 19, 2016
e6629c8
Fixed tournament selection to only choose from valid orgs
emilydolson May 19, 2016
229d7d9
NK_OEE now uses const landscapes
emilydolson May 19, 2016
39d792d
Lineage tracker does everything automatically with signals
emilydolson May 19, 2016
b119b08
Made ids actually propagate correctly
emilydolson May 19, 2016
295fd66
Elite selection is null org safe
emilydolson May 19, 2016
7795f83
GetValidOrgIndices actually works now
emilydolson May 19, 2016
0303f20
Merge in Jake and Stevens addition to Stats.h
emilydolson May 20, 2016
c41f784
Merge in null org handling
emilydolson May 20, 2016
a740eb6
Base stats manager functionality works
emilydolson May 20, 2016
f331839
StatsManagers handle output locations
emilydolson May 22, 2016
b718da7
Worlditerator uses pointers
emilydolson May 22, 2016
a848858
Added error message for invalid file
emilydolson May 22, 2016
b68dba6
Created default stats manager, made header
emilydolson May 23, 2016
14a5af0
Merge branch 'master' of github.com:devosoft/Empirical
emilydolson May 23, 2016
261a9f3
Added comments, cleaned up types
emilydolson May 23, 2016
49744de
OEE stats manager uses base output
emilydolson May 23, 2016
09fdf57
Stats managers have config files
emilydolson May 23, 2016
34198f6
Fixed possible null dereference in tournament fitness calculation
emilydolson May 23, 2016
db2c17d
Guard against null dereference in MutatePop
emilydolson May 23, 2016
39ae05f
StatsManagers can be passed as template arguments
emilydolson May 27, 2016
eb645f2
LineageTracker and OEEStats now follow general StatsManager format
emilydolson May 29, 2016
2149343
LineageTracker and OEEStats now follow general StatsManager format
emilydolson May 29, 2016
4fd1544
Merge branch 'master' of github.com:emilydolson/Empirical
emilydolson May 29, 2016
0a6b803
Lineage tracker automatically hooks up to OEE stats
emilydolson May 29, 2016
97f0ffb
Automatic lineage tracker construction works
emilydolson May 29, 2016
adadaac
Made stats generic and moved them to tools
emilydolson May 29, 2016
a92e954
Merge branch 'master' of github.com:devosoft/Empirical
emilydolson May 30, 2016
a80244f
Fixed g++ compilation bug
emilydolson May 31, 2016
a6897a1
Stats Manager headers + assorted cleanup
emilydolson Jun 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
StatsManagers can be passed as template arguments
  • Loading branch information
emilydolson committed May 27, 2016
commit 39ae05f283170213470130f1db0e161d8ac4e70d
82 changes: 82 additions & 0 deletions evo/PopulationIterator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef EMP_EVO_POP_ITER_H
#define EMP_EVO_POP_ITER_H

//#include "World.h"
#include "PopulationManager.h"

namespace emp{
namespace evo{

template <typename POP_MANAGER>
class PopulationIterator{
private:
using ORG = typename POP_MANAGER::value_type;
POP_MANAGER * pop;
int curr = 0;
int size;

public:
//typedef iterator;
//typedef ptrdiff_t difference_type;
//typedef size_t size_type;
//typedef T value_type;
//typedef T * pointer;
//typedef T & reference;

PopulationIterator(POP_MANAGER * w, int ind = 0){
pop = w;
curr = ind;
size = pop->size();
while ((curr < size) && (((*pop)[curr]) == nullptr)){
++curr;
}
}

PopulationIterator(PopulationIterator * w){
pop = w->pop;
curr = w->curr;
size = w->size;
while (curr < size && (((*pop)[curr]) == nullptr)) {
++curr;
}
}

PopulationIterator<POP_MANAGER> & operator++() {
++curr;
while (curr < size && (((*pop)[curr]) == nullptr)) {
++curr;
}
return *this;
}

PopulationIterator<POP_MANAGER> & operator--() {
--curr;
while (curr < size && (((*pop)[curr]) == nullptr)) {
--curr;
}
return *this;
}

bool operator==(const PopulationIterator<POP_MANAGER>& rhs){
return curr == rhs.curr;
}

bool operator!=(const PopulationIterator<POP_MANAGER>& rhs){
return curr != rhs.curr;
}

ORG & operator*() {return (*pop)[curr];}

PopulationIterator<POP_MANAGER> begin() {
return PopulationIterator<ORG>(pop, 0);
}

PopulationIterator<POP_MANAGER> end() {
return PopulationIterator<POP_MANAGER>(pop, size);
}


};
}
}
#endif
9 changes: 9 additions & 0 deletions evo/PopulationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#define EMP_EVO_POPULATION_MANAGER_H

#include "../tools/random_utils.h"
#include "PopulationIterator.h"

namespace emp {
namespace evo {

template <typename POP_MANAGER> class PopulationIterator;

template <typename ORG=int>
class PopulationManager_Base {
protected:
Expand All @@ -32,9 +35,15 @@ namespace evo {
// Allow this and derived classes to be identified as a population manager.
static constexpr bool emp_is_population_manager = true;
static constexpr bool emp_has_separate_generations = false;
using value_type = ORG*;

friend class PopulationIterator<PopulationManager_Base<ORG> >;
using iterator = PopulationIterator<PopulationManager_Base<ORG> >;

ptr_t & operator[](int i) { return pop[i]; }
const ptr_t operator[](int i) const { return pop[i]; }
iterator begin(){return iterator(this, 0);}
iterator end(){return iterator(this, pop.size());}

uint32_t size() const { return pop.size(); }
void resize(int new_size) { pop.resize(new_size); }
Expand Down
51 changes: 34 additions & 17 deletions evo/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
namespace emp{
namespace evo{



//Calculates Shannon Entropy of the members of the container passed
template <typename C, class = typename C::value_type >
double ShannonDiversity(C elements) {
template <typename C>
typename std::enable_if<!std::is_pointer<typename C::value_type>::value, double>::type
ShannonDiversity(C & elements) {

//Count number of each value present
std::map<typename C::value_type, int> counts;
Expand All @@ -42,23 +45,24 @@ namespace evo{
}

return -1 * result;
}
}

//Calculates Shannon Entropy of the members of a world
template <typename ORG, typename... MANAGERS>
double ShannonDiversity(emp::evo::World<ORG, MANAGERS...> & elements) {
template <typename C>
typename std::enable_if<std::is_pointer<typename C::value_type>::value, double>::type
ShannonDiversity(C & elements) {

using pointed_at = typename std::remove_pointer<typename C::value_type>::type;
//Count number of each value present
std::map<ORG, int> counts;
std::map<pointed_at, int> counts;
for (auto element : elements) {
if (counts.find(element) != counts.end()) {
counts[element]++;
if (counts.find(*element) != counts.end()) {
counts[*element]++;
} else {
counts[element] = 1;
counts[*element] = 1;
}

}

//Shannon entropy calculation
double result = 0;
for (auto element : counts) {
Expand All @@ -67,7 +71,7 @@ namespace evo{
}

return -1 * result;
}
}

//Calculates number of unique elements in the container passed
template <typename C>
Expand All @@ -78,19 +82,19 @@ namespace evo{
return unique_elements.size();
}

template <typename ORG, typename C, class = typename C::value_type >
double MaxFitness(std::function<double(ORG * org)> fit_fun, C orgs){
double fittest = fit_fun(&orgs[0]);
template <typename C, class = typename C::value_type >
double MaxFitness(std::function<double(typename C::value_type org)> fit_fun, C orgs){
double fittest = fit_fun(orgs[0]);
for (auto org : orgs){
double fitness = fit_fun(&org);
double fitness = fit_fun(org);
if (fitness > fittest){
fittest = fitness;
}
}
return fittest;
}

template <typename ORG, typename... MANAGERS>
/* template <typename ORG, typename... MANAGERS>
double MaxFitness(std::function<double(ORG * org)> fit_fun, World<ORG, MANAGERS...> & orgs){
double fittest = fit_fun(&(*(orgs.begin())));
for (auto org : orgs){
Expand All @@ -101,7 +105,20 @@ namespace evo{
}
return fittest;
}
*/

template <typename C, class = typename C::value_type>
double AverageFitness(std::function<double(typename C::value_type org)> fit_fun, C & orgs){
double cumulative_fitness = 0;
double num_orgs = 0;
for (auto org : orgs){
++num_orgs;
cumulative_fitness += fit_fun(org);
}
return (cumulative_fitness / num_orgs);
}

/*
template <typename ORG, typename... MANAGERS>
double AverageFitness(std::function<double(ORG * org)> fit_fun, World<ORG, MANAGERS...> & orgs){
double cumulative_fitness = 0;
Expand All @@ -112,7 +129,7 @@ template <typename ORG, typename... MANAGERS>
}
return (cumulative_fitness / num_orgs);
}

*/
}
}

Expand Down
Loading