Numerical stability modification to sigmoid function (for survival probability).
authorDariusz Murakowski <murakdar@mit.edu>
Wed, 17 Jun 2015 17:48:16 +0000 (13:48 -0400)
committerDariusz Murakowski <murakdar@mit.edu>
Wed, 17 Jun 2015 17:48:16 +0000 (13:48 -0400)
virus.cpp

index c5124a9..c242999 100644 (file)
--- 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));
     
 }