I'm training some neural networks using NEAT C++, and would like to use the cross-entropy error function: $$E = -t\ln(y) -(1-t)\ln(1-y)$$ to train a network for a two-class classification problem.

NEAT C++ is a C++ library that allows one to use a special kind of neuro evolution (namely that of augmenting topologies) to train the networks. Yet to be able to use it, one needs to define a fitness function (and not an error function, such as the one above).


How can I construct a fitness function from the cross-entropy error function?

Everything below this line is wrong I guess because $E\in [0,\infty]$, and thus it's impossible to define a maximum. How should I do it then?

I was thinking about this: calculate the maximum error $E_{\text{max}}$ somehow and define the fitness, given a certain network output $y$, as: $$f(y)=E_{\text{max}} - E(y)$$ This way the fitness will be $0$ when $E(y)=E_{\text{max}}$ and it should reach a maximum if $E(y)=0$.

Is this the right method? If so how do I calculate the maximum error $E_{\text{max}}$?

note: NEAT does not allow the use of negative fitness functions, so using $f(y)=-E(y)$ would not work. Also I would like to refrain from using arbitrary stuff such as $f(y)=10000000 - E(y)$.

  • $\begingroup$ if you take exponential of -E, isn't it the likelihood, thus always positive with the same rank ordering? $\endgroup$
    – Memming
    Commented Apr 11, 2012 at 15:09
  • $\begingroup$ @Memming: how stupid of me not to think about that... $\endgroup$
    – romeovs
    Commented Apr 11, 2012 at 15:15
  • $\begingroup$ @Memming This would lead to $E=y^t(1-y)^{1-t}$. But then wouldn't that be the same as using the absolute distance as error $E = t-y$ and defining the fitness as I did above: $f(y) = E_{\text{max}} - E(y)$. Because $t$ can only be $0$ or $1$, one of $y^{1-t}$ and $y^t$ will equal $1$, and for the other one the exponent is $1$, leaving $f=y$ or $f=(1-y)$ depending on the value of $t$. $\endgroup$
    – romeovs
    Commented Apr 11, 2012 at 15:24

2 Answers 2


First of all: NEAT is an algorithm that is usually used for reinforcement learning. I guess it won't work very well in your case. You should rather find a good network architecture by cross-validation and train your network with stochastic gradient descent, conjugate gradient, ...

Since it is just a fitness function it usually does not matter if it has an upper bound. You almost certainly will not find a perfect solution in every classification problem. So you should think about another stop criterion than "find the maximal fitness".

However, you could take -E. Its upper bound is 0.

  • $\begingroup$ $-E$ wont't work because, for some reason, NEAT doesn't play well with negative fitness. Also, this is for a school project so wheter NEAT is the best choice doesn't matter very much. What would you recommend for stopping criterium? $\endgroup$
    – romeovs
    Commented Apr 17, 2012 at 19:58
  • $\begingroup$ @alfa NEAT is genetic algorithm for evolving neural networks, see the wiki page, although it wouldn't surprise me if there was a similarly named RL algorithm which is causing the confusion. $\endgroup$
    – alto
    Commented Jul 14, 2012 at 12:24
  • $\begingroup$ You can find some publications about NEAT at the NEAT user page (cs.ucf.edu/~kstanley/neat.html#papers). Its original purpose was reinforcement learning and I have never seen anything about NEAT and supervised learning. $\endgroup$
    – alfa
    Commented Jul 14, 2012 at 13:03
  • $\begingroup$ @alfa I see I was the one confused, sorry about that. So, I know next to nothing about GAs and I'm having trouble picturing how a optimization technique which doesn't explicitly work with the form of the function being optimized can be "for" reinforcement learning. Mind explaining? $\endgroup$
    – alto
    Commented Jul 14, 2012 at 15:15
  • $\begingroup$ I did not really understand this question. Can you rephrase it? $\endgroup$
    – alfa
    Commented Jul 14, 2012 at 18:17

You'll also see the function you've described referred to as the log loss in the machine learning literature. It is a loss function, you do not want to maximize it, you want to minimize it.

If you have a minimization problem, you can simply negate it to obtain a maximization problem.

Since you need non-negative values just add the minimum value of your negated objective. You can find this minimum because your data is finite, i.e. the worst you can do is get everything wrong.

edit: An alternative, still assuming your problem is binary prediction, would be to simply maximize $$\sum\mathbf{1}\{y = t\},$$ since you generally don't need a differentiable function for genetic algorithms anyway.

  • 1
    $\begingroup$ Speaking from experience, it helps if fitness functions are smooth. Just minimizing the empirical risk will probably fail. $\endgroup$
    – bayerj
    Commented Sep 12, 2012 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.