Error C2440: 'initializing' : cannot convert from 'const std::_Vector_iterator' to 'Gene *'

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I get this error when I try to compile one of my files. Problem is, the file is huge, and its not showing any errors inline. When I double-click on the error warning after a compile attempt it takes me VC/include/xmemory. This obviously has something to
do with a memory intialisation, but how am I supposed to know where it is? It makes no reference to any code Ive written.. Here is the complete error:

<pre class="prettyprint 1>c:Program Files (x86)Microsoft Visual Studio 10.0VCincludexmemory(208): error C2440: initializing : cannot convert from const std::_Vector_iterator<_Myvec> to Gene *
1> with
1> [
1> _Myvec=std::_Vector_val<Gene *,std::allocator<Gene *>>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:Program Files (x86)Microsoft Visual Studio 10.0VCincludexmemory(280) : see reference to function template instantiation void std::allocator<_Ty>::construct<const std::_Vector_iterator<_Myvec>&>(Gene **,_Other) being compiled
1> with
1> [
1> _Ty=Gene *,
1> _Myvec=std::_Vector_val<Gene *,std::allocator<Gene *>>,
1> _Other=const std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>> &
1> ]
1> c:Program Files (x86)Microsoft Visual Studio 10.0VCincludememory(376) : see reference to function template instantiation void std::_Cons_val<_Alloc,Gene*,const std::_Vector_iterator<_Myvec>&>(_Alloc &,_Ty1 *,_Ty2) being compiled
1> with
1> [
1> _Alloc=std::allocator<Gene *>,
1> _Myvec=std::_Vector_val<Gene *,std::allocator<Gene *>>,
1> _Ty1=Gene *,
1> _Ty2=const std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>> &
1> ]
1> c:Program Files (x86)Microsoft Visual Studio 10.0VCincludememory(414) : see reference to function template instantiation _FwdIt std::_Uninit_copy<_InIt,_FwdIt,_Alloc>(_InIt,_InIt,_FwdIt,_Alloc &,std::_Nonscalar_ptr_iterator_tag) being compiled
1> with
1> [
1> _FwdIt=Gene **,
1> _InIt=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>>,
1> _Alloc=std::allocator<Gene *>
1> ]
1> c:Program Files (x86)Microsoft Visual Studio 10.0VCincludevector(1318) : see reference to function template instantiation _FwdIt std::_Uninitialized_copy<_Iter,Gene**,std::allocator<_Ty>>(_InIt,_InIt,_FwdIt,_Alloc &) being compiled
1> with
1> [
1> _FwdIt=Gene **,
1> _Iter=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>>,
1> _Ty=Gene *,
1> _InIt=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>>,
1> _Alloc=std::allocator<Gene *>
1> ]
1> c:Program Files (x86)Microsoft Visual Studio 10.0VCincludevector(1131) : see reference to function template instantiation Gene **std::vector<_Ty>::_Ucopy<_Iter>(_Iter,_Iter,Gene **) being compiled
1> with
1> [
1> _Ty=Gene *,
1> _Iter=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>>
1> ]
1> c:Program Files (x86)Microsoft Visual Studio 10.0VCincludevector(1065) : see reference to function template instantiation void std::vector<_Ty>::_Insert<_Iter>(std::_Vector_const_iterator<_Myvec>,_Iter,_Iter,std::forward_iterator_tag) being compiled
1> with
1> [
1> _Ty=Gene *,
1> _Iter=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>>,
1> _Myvec=std::_Vector_val<Gene *,std::allocator<Gene *>>
1> ]
1> c:Program Files (x86)Microsoft Visual Studio 10.0VCincludevector(1042) : see reference to function template instantiation void std::vector<_Ty>::insert<_Iter>(std::_Vector_const_iterator<_Myvec>,_Iter,_Iter) being compiled
1> with
1> [
1> _Ty=Gene *,
1> _Iter=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>>,
1> _Myvec=std::_Vector_val<Gene *,std::allocator<Gene *>>
1> ]
1> c:Program Files (x86)Microsoft Visual Studio 10.0VCincludevector(1029) : see reference to function template instantiation void std::vector<_Ty>::_Assign<_Iter>(_Iter,_Iter,std::input_iterator_tag) being compiled
1> with
1> [
1> _Ty=Gene *,
1> _Iter=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>>
1> ]
1> ..........Google DrivecodeNuEDENstructuresstruct_species.cpp(336) : see reference to function template instantiation void std::vector<_Ty>::assign<std::_Tree_const_iterator<_Mytree>>(_Iter,_Iter) being compiled
1> with
1> [
1> _Ty=Gene *,
1> _Mytree=std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>,
1> _Iter=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>,std::less<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,std::allocator<std::_Vector_iterator<std::_Vector_val<Gene *,std::allocator<Gene *>>>>,false>>>
1> ][/code]
And here is the file where the error occurs:
<pre class="prettyprint #include "struct_species.h"

using namespace std;

// create a new, undefined, empty species
Species::Species(World* p_world) {

this->p_world = p_world;

// set up random number distributions
gaussian_engine.seed(rand());

number_of_synapses = 0;
current_generation = 0;

birth_epoch = p_world->current_epoch;
}

Species::~Species() {
// delete genes
for (auto it_genes = genes_vec.begin(), lim_it_genes = genes_vec.end(); it_genes != lim_it_genes; it_genes++)
delete *it_genes;
}

// make this species an exact copy of the source, leaving p_world intact
Species& Species::operator= (const Species& source) {

if (&source == this)
return *this; // if they are they same species

// loop through genes of the smallest of the two species
auto it_genes = genes_vec.begin();
auto lim_it_genes = genes_vec.end();
auto it_genesSource = source.genes_vec.begin();
auto lim_it_genesSource = source.genes_vec.end();
for (; it_genes != lim_it_genes, it_genesSource != lim_it_genesSource; it_genes++, it_genesSource++)
**it_genes = **it_genesSource; // make the genes identical

if (genes_vec.size() > source.genes_vec.size()) {
// the current species is larger than the source
for (; it_genes != lim_it_genes; it_genes++)
delete *it_genes; // delete every excess gene
genes_vec.resize(source.genes_vec.size()); // resize the vector to the new size
} else if (genes_vec.size() < source.genes_vec.size()) {
// the current species is smaller than the source
genes_vec.reserve(source.genes_vec.size());
for (; it_genesSource != lim_it_genesSource; it_genesSource++) {
Gene* pNewGene = new Gene(this);
*pNewGene = **it_genesSource;
genes_vec.push_back(pNewGene);
}
}

RealignSynapses(genes_vec,source.genes_vec); // align synapse connections from the source to the host genes
RepairNeighbourMarkers(genes_vec); // repair the prev/next pointers
UpdateActiveGenes(); // this is probably going to be invalidated later anyway, but for consistency we should return a functional species

// set the number of active synapses
number_of_active_synapses = source.number_of_active_synapses;

// champion, and currentness:
champion = source.champion;
is_current = source.is_current;

return *this;
}

// mutates the species
void Species::operator~ () {
// random mutation rate to decide strength of this series of mutations
double global_mutation_rate = RandN();

bool identical_structure = true; // tracks whether or not the host species is identical in structure to source

// --------------------------------------------------------------------------------------------------------------------
// Node generation:

// first identify the node generation candidate
vector<Gene*>::iterator iNodeCandidate = genes_vec.begin() + p_world->input_genes + rand() % (genes_vec.size() - p_world->input_genes);

Node* p_node = NULL; // this is where the node will be created

// loop through every synapse of every input gene, and consider inserting this node
size_t j = p_world->input_genes;
for (vector<Gene*>::iterator it_genes = genes_vec.begin() + p_world->input_genes, lim_it_genes = genes_vec.end(); it_genes != lim_it_genes; it_genes++, j++) {
if (InstantVariance(genes_vec.size(),RandN(),global_mutation_rate) * RandN() > kNodeInsertionTrigger) {
// if the node insertion trigger is met...

identical_structure = false;
vector<Synapse*>::iterator it_synapses = (*it_genes)->synapses_vec.begin() + rand() % (*it_genes)->synapses_vec.size(); // random synapse along which the node will be inserted

if (!p_node)
p_node = new Node(iNodeCandidate); // the node doesnt exist yet, so we have to build it now

number_of_synapses += p_node->Insert(genes_vec,it_genes,it_synapses);

// as of this point the it_genes iterators are potentially invalid
it_genes = genes_vec.begin() + j - 1; // return to the gene at the node insertion
lim_it_genes = genes_vec.end(); // reset the limit
}
}

if (p_node)
delete p_node; // delete the node if it was created

// End of node generation
// --------------------------------------------------------------------------------------------------------------------

// Standard gene and synapse mutation:
// --------------------------------------------------------------------------------------------------------------------

// loop through every non-input gene of the species
j = p_world->input_genes;
for (vector<Gene*>::iterator it_genes = genes_vec.begin() + p_world->input_genes, lim_it_genes = genes_vec.end(); it_genes != lim_it_genes; it_genes++, j++) {

// consider synapse generation
if (InstantVariance(genes_vec.size(),RandN(),global_mutation_rate) * RandN() > kSynapseGenerationTrigger) {
identical_structure = false;
(*it_genes)->synapses_vec.push_back(new Synapse(GetRandomGene(j))); // generate a synapse
number_of_synapses++; // account for the synapse just created
}

// consider activation function mutation
if (InstantVariance(genes_vec.size(),RandN(),global_mutation_rate) * RandN() > kActivationFunctionMutationTrigger) {
identical_structure = false;
(*it_genes)->activation_function = ACTIVATION_FUNCTION_POINTERS[rand() % kNumberOfActivationFunctions];
}

// consider gene cloning / deletion
double gene_mutation_strength = InstantVariance(genes_vec.size(),RandN(),global_mutation_rate) * RandN();
if (gene_mutation_strength > kGeneCloningTrigger) {
// gene cloning will occur
identical_structure = false;
it_genes = GeneInsert(new Gene(*it_genes),it_genes,(*it_genes)->synapses_vec.begin() + rand() % (*it_genes)->synapses_vec.size()); // insert a copy of the current gene along a random synapse
}
else if (gene_mutation_strength < -kGeneDeletionTrigger) {
// gene deletion will occur
identical_structure = false;
it_genes = GeneRemove(it_genes);
}

// loop through every synapse
for (auto it_synapses = (*it_genes)->synapses_vec.begin(), lim_it_synapses = (*it_genes)->synapses_vec.end(); it_synapses != lim_it_synapses; it_synapses++) {

// consider synapse source mutation
double synapse_source_mutation_strength = InstantVariance(number_of_synapses,RandN(),global_mutation_rate) * RandN();
if (abs(synapse_source_mutation_strength) > kSynapseSourceMinorMutationTrigger) {
// the mutation strength is at least strong enough to cause a minor mutation
identical_structure = false;
if (abs(synapse_source_mutation_strength) > kSynapseSourceMajorMutationTrigger) {
// the mutation strength is strong enough for a major mutation of the synapse source
(*it_synapses)->synapse_source = GetRandomGene(j);
} else if (synapse_source_mutation_strength > kSynapseSourceMinorMutationTrigger) {
// the mutation strength will cause a minor positive mutation of the synapse source
if ((*it_synapses)->synapse_source->next != *it_genes)
// mutating in the positive direction will not cause the synapse to point to itself
(*it_synapses)->synapse_source = (*it_synapses)->synapse_source->next;
} else {// if (synapse_source_mutation_strength < -kSynapseSourceMinorMutationTrigger)
// the mutation strength will cause a minor negative mutation of the synapse source
if ((*it_synapses)->synapse_source->prev)
// mutating in the negative direction will not cause the synapse out of bounds
(*it_synapses)->synapse_source = (*it_synapses)->synapse_source->prev;
}
}
}
}
// --------------------------------------------------------------------------------------------------------------------

// Housekeeping following structural changes
// --------------------------------------------------------------------------------------------------------------------
if (!identical_structure) {
UpdateActiveGenes();

// finally count the number of active synapses
number_of_active_synapses = 0;
for (auto it_active_genes_vec = active_genes_vec.begin(), lim_it_active_genes_vec = active_genes_vec.end(); it_active_genes_vec != lim_it_active_genes_vec; it_active_genes_vec++)
number_of_active_synapses += (*it_active_genes_vec)->synapses_vec.size();

is_current = false; // if structure has changed, set is_current to false in any cause
ResetVariances(); // reset variances
} else {
// if kOptimiseIdenticalChildren is true, set is_current to false even if identical_structure is true
if (kOptimiseIdenticalChildren) {
is_current = false;

// also consider reseting variances
if (kResetVarianceOfIdenticalChildren)
ResetVariances(); // reset variances
}
}

// DEBUGGING
if (number_of_synapses != CountNumberOfSynapses(genes_vec.begin(),genes_vec.end()));
throw;
}

// insert a gene pointer at the iterator position and make necessary adjustments to pointer information
vector<Gene*>::iterator Species::GeneInsert(Gene* p_gene, vector<Gene*>::iterator it) {

Gene* p_prev_gene;
Gene* p_next_gene;

// check if gene is being inserted at the end of the vector
if (it == genes_vec.end()) {
// it is the end of the vector
if (genes_vec.size() == 0) {
// it is the only gene of the vector
p_prev_gene = false;
p_next_gene = false;
} else {
// it is the last gene, but there is one before it
p_prev_gene = *(it-1);
p_prev_gene->next = p_gene; // change next pointer of prev gene
p_next_gene = false;
}
} else if (it == genes_vec.begin()) {
// it is the first gene of the vector, but there is one after it
p_prev_gene = false;
p_next_gene = *it;
p_next_gene->prev = p_gene; // change prev pointer of next gene
} else {
// it is neither the first nor the last gene in the vector
p_prev_gene = *(it-1);
p_next_gene = *it;
p_prev_gene->next = p_gene; // change next pointer of prev gene
p_next_gene->prev = p_gene; // change prev pointer of next gene
}

// modify the inserted genes prev/next pointers
p_gene->next = p_next_gene;
p_gene->prev = p_prev_gene;

number_of_synapses += p_gene->synapses_vec.size();

// finally insert the gene into the p_genes vector and return the new iterator
return genes_vec.insert(it,p_gene);
}

// insert a gene into the specified synapse of a specified gene
vector<Gene*>::iterator Species::GeneInsert(Gene* p_gene_new,vector<Gene*>::iterator it_gene,vector<Synapse*>::iterator iSynapse) {

Gene* p_synapse_source_old = (*iSynapse)->synapse_source; // gene source for the synapse

// point the synapse to the new gene
(*iSynapse)->synapse_source = p_gene_new;

// add a synapse to the gene pointing to the old synapse source
p_gene_new->synapses_vec.push_back(new Synapse(p_synapse_source_old));

number_of_synapses++; // account for the synapse that was just created

// insert the new gene and return the new pointer
return GeneInsert(p_gene_new,it_gene);
}

// add a gene pointer to the end of p_genes and make necessary adjustments to pointer information
void Species::GenePushBack(Gene* p_gene) {

Gene* p_prev_gene;

if (genes_vec.size() == 0) {
// there is no previous gene
p_prev_gene = false;
} else {
// there is a previous gene
p_prev_gene = genes_vec.back();
p_prev_gene->next = p_gene; // adjust next pointer of prev gene
}

// adjust pointer information of new gene
p_gene->next = false;
p_gene->prev = p_prev_gene;

// account for the new synapses
number_of_synapses += p_gene->synapses_vec.size();

// finally insert the gene
genes_vec.push_back(p_gene);
}

// picks a random gene before the input pointer
Gene* Species::GetRandomGene(size_t j) {
if (kPseudoRandomSynapseSelection) { // if we have chosen pseudo-random synapse selection
// check if the value before j represents an input gene
if (j > p_world->input_genes) { // any gene before j will be an input
return genes_vec[rand() % j]; // just pick a random gene
} else { // there are genes before j that are hidden genes
// flip a coin to decide whether to select from input our output genes
if (rand() % 2) {
// arbitrarily choose this outcome to represent input genes
return genes_vec[rand() % p_world->input_genes]; // return a random input gene
} else {
// this outcome arbitrarily represents hidden genes
return genes_vec[p_world->input_genes + rand() % (j - p_world->input_genes)]; // return a random hidden gene
}
}
} else { // if we have chosen truly random synapse selection
return genes_vec[rand() % j]; // pick a random gene
}
}
// make a member a mutated version of another
void Species::MutateMember(size_t source,size_t target) {
double global_mutation_rate = RandN(); // random mutation rate for this mutation instance
// iterate through every input gene
for (vector<Gene*>::iterator it_genes_vec = genes_vec.begin() + p_world->input_genes, lim_it_genes_vec = genes_vec.end(); it_genes_vec != lim_it_genes_vec; it_genes_vec++) {
// mutate the bias weights of the gene
(*it_genes_vec)->bias_weight_var_phenotypes[target] = (*it_genes_vec)->bias_weight_var_phenotypes[source]*DeltaVariance(genes_vec.size(),RandN(),global_mutation_rate);
(*it_genes_vec)->bias_weight_phenotypes[target] = (*it_genes_vec)->bias_weight_phenotypes[source] + (*it_genes_vec)->bias_weight_var_phenotypes[target] * RandN();

// now iterate through every synapse of the gene
for (auto it_synapses_vec = (*it_genes_vec)->synapses_vec.begin(), lim_it_synapses_vec = (*it_genes_vec)->synapses_vec.begin(); it_synapses_vec != lim_it_synapses_vec; it_synapses_vec++) {
// mutate the synapse weights of the synapse
(*it_synapses_vec)->synapse_weight_var_phenotypes[target] = (*it_synapses_vec)->synapse_weight_var_phenotypes[source]*DeltaVariance(number_of_synapses,RandN(),global_mutation_rate);
(*it_synapses_vec)->synapse_weight_phenotypes[target] = (*it_synapses_vec)->synapse_weight_phenotypes[source] + (*it_synapses_vec)->synapse_weight_var_phenotypes[target] * RandN();
}
}
member_is_current[target] = false; // this process invalidates the error values of the member
}

// produce a random number from a gaussian distribution
inline double Species::RandN() {
return gaussian_distribution(gaussian_engine);
}

// update the active_genes_vec
void Species::UpdateActiveGenes() {
// create a gene pointer set to populate with active genes
set<vector<Gene*>::iterator> p_active_genes_set; // create the empty set

// call the neuron path recursor function for every output gene
for (auto it_output_genes = output_genes_vec.begin(), lim_it_output_genes = output_genes_vec.end(); it_output_genes != lim_it_output_genes; it_output_genes++)
// find the iterator to the output gene in the genes_vec vector, then recourse to find all connected genes and append them to the active_genes set
NeuronPathRecursor(find(genes_vec.begin() + p_world->input_genes, genes_vec.end(), *it_output_genes),p_active_genes_set);

// we now have the p_active_genes_set set, which contains iterators to all active genes. Convert it to a vector:
active_genes_vec.assign(p_active_genes_set.begin(),p_active_genes_set.end());
}

// rank the members of this species
void Species::UpdateMemberRankings() {

vector<double> member_error_ordered = member_error; // create a copy vector that will be manipulated alongside member_order

vector<double>::iterator it_member_error_ordered = member_error_ordered.begin();
vector<size_t>::iterator it_member_order = member_order.begin();

for (size_t k = 0; k != number_of_members; it_member_error_ordered++, it_member_order++, k++) {

(*it_member_order) = k; // list of indices arranged by their points (for now just linear order)

// iterating k_dest from the current position in member_order (k) to the front, stopping at the first index for which the error of the index in front is smaller than for k
size_t k_dest = k;
while (k_dest != 0 && *it_member_error_ordered > it_member_error_ordered[k_dest - 1])
k_dest--;

if (k != k_dest) {
// shift it around
VecShift<double>(member_error_ordered, k, k_dest);
VecShift<size_t>(member_order, k, k_dest);
}
}

champion = member_order[0]; // define the champion
}

// reset the variances of all phenotype in the species
void Species::ResetVariances() {
// iterate through every hidden gene
for (vector<Gene*>::iterator it_genes = genes_vec.begin() + p_world->input_genes, lim_it_genes = genes_vec.end(); it_genes != lim_it_genes; it_genes++)
(*it_genes)->ResetVariances();
}

// set the number of phenotypes in the species
void Species::SetNumberOfMembers(size_t new_number_of_members) {
if (number_of_members != new_number_of_members) { // we need to change the number of members
// iterate through every non-input gene (ie. every gene that can have synapses)
for (vector<Gene*>::iterator it_genes = genes_vec.begin() + p_world->input_genes, lim_it_genes = genes_vec.end(); it_genes != lim_it_genes; it_genes++)
(*it_genes)->SetNumberOfPhenotypes(new_number_of_members);
// adjust the number of phenotypes counter
number_of_members = new_number_of_members;

// adjust the member vectors
member_error.resize(new_number_of_members);
member_is_current.resize(new_number_of_members,false); // flag all new members as is_current = false
member_order.resize(new_number_of_members);
}
}


// remove a gene from the p_genes vector
vector<Gene*>::iterator Species::GeneRemove(vector<Gene*>::iterator it) {

// make sure were not deleting input or output genes
if ((*it)->type != 0)
return it;

// kill any synapses that point to this gene
for (vector<Gene*>::iterator it_genes = it + 1, lim_it_genes = genes_vec.end(); it_genes != lim_it_genes; it_genes++)
for (auto it_synapses = (*it_genes)->synapses_vec.begin(), lim_it_synapses = (*it_genes)->synapses_vec.end(); it_synapses != lim_it_synapses; it_synapses++)
if ((*it_synapses)->synapse_source == *it) {
delete *it_synapses;
number_of_synapses--;
}

// p_gene cant be the first gene of the species because its not an input, and it cant be the last because its not an output,
// so it must have neighbours:

(*it)->prev->next = (*it)->next; // next of it becomes next of the prev gene
(*it)->next->prev = (*it)->prev; // prev of it becomes prev of the next gene

// account for the synapses that this gene contained
number_of_synapses -= (*it)->synapses_vec.size();

// kill the gene itself
delete *it;

return genes_vec.erase(it); // now remove it from the p_genes vector
}

// update convergence values for this species
void Species::UpdateConvergenceInfo() {

// find the mean of the member_error vector
double member_error_sum = 0;
for (auto it_member_error = member_error.begin(), lim_it_member_error = member_error.end(); it_member_error != lim_it_member_error; it_member_error++)
member_error_sum += *it_member_error;
double member_error_mean = member_error_sum/static_cast<double>(member_error.size());

// find the standard deviation (sigma) of the member_error values
double square_of_deviation_sum = 0;
for (auto it_member_error = member_error.begin(), lim_it_member_error = member_error.end(); it_member_error != lim_it_member_error; it_member_error++)
square_of_deviation_sum += pow(*it_member_error - member_error_mean,2);
double member_error_sigma = sqrt(square_of_deviation_sum);

/* the convergenece of the species is defined as the standard deviation
* of the error values across the species, as a fraction of the mean of
* that error value
*/
double convergence = member_error_sigma / member_error_mean;

// push back the current convergence into convergence_vec until we reach the full size, then insert at an incremented position
if (convergence_vec.size() != kResidualHistoryLength)
convergence_vec.push_back(convergence);
else
convergence_vec[convergence_vec_pos++ % kResidualHistoryLength] = convergence;

// find the mean of every value in convergence_vec:
double convergence_sum = 0;
for (auto it_convergence_vec = convergence_vec.begin(), lim_it_convergence_vec = convergence_vec.end(); it_convergence_vec != lim_it_convergence_vec; it_convergence_vec++)
convergence_sum += *it_convergence_vec;
this->mean_convergence = convergence_sum / static_cast<double>(convergence_vec.size());
}[/code]
<br/>
Short of scouring through every line of code, is there some easy way to find out what the problem is?

View the full article
 
Back
Top