From: Dariusz Murakowski Date: Wed, 17 Jun 2015 17:48:16 +0000 (-0400) Subject: Numerical stability modification to sigmoid function (for survival probability). X-Git-Url: http://src.murakowski.org/?a=commitdiff_plain;h=c6cabecdfcaa58e1f9c270c84e1442bccc58f8f1;p=VirEvoDyn.git Numerical stability modification to sigmoid function (for survival probability). --- diff --git a/virus.cpp b/virus.cpp index c5124a9..c242999 100644 --- a/virus.cpp +++ b/virus.cpp @@ -66,22 +66,26 @@ void Virus::mutate(const Hamiltonian &H, gsl_rng* r) { } -// Computes the odds of survival. +// Computes the odds of survival as a sigmoid function. double Virus::survival() const { - double z = exp(-energy); - return z/(1+z); + //double z = exp(-energy); + //return z/(1+z); + return (energy<0.0) ? 1.0/(1.0+exp(energy)) : exp(-energy)/(1.0+exp(-energy)); } -// Computes the odds of survival. +// Computes the odds of survival as a sigmoid function, +// relative to average energy. double Virus::survival(double Eavg) const { - double z = exp(Eavg-energy); - return z/(1+z); + //double z = exp(Eavg-energy); + //return z/(1+z); + double dE = Eavg - energy; + return (dE>0.0) ? 1.0/(1.0+exp(-dE)) : exp(dE)/(1.0+exp(dE)); }