From f1825b6ca420f63e17ca69e3c9412b80adcdbb1c Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 6 Dec 2018 23:25:46 -0500 Subject: all threshold comparisons now done in log, so as to prevent underflows at small beta --- lib/src/network.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/src') diff --git a/lib/src/network.cpp b/lib/src/network.cpp index bc7a0c6..9cb1007 100644 --- a/lib/src/network.cpp +++ b/lib/src/network.cpp @@ -89,10 +89,10 @@ void network::set_thresholds(double beta, std::mt19937& rng) { std::uniform_real_distribution d(0.0, 1.0); for (long double& threshold : thresholds) { - threshold = 0.0; + threshold = std::numeric_limits::lowest(); - while (threshold == 0.0) { - threshold = expl(logl(d(rng)) / (long double)beta); + while (threshold == std::numeric_limits::lowest()) { + threshold = logl(d(rng)) / (long double)beta; } } } @@ -202,11 +202,11 @@ void network::fracture(hooks& m, double cutoff) { } unsigned int max_pos = UINT_MAX; - long double max_val = 0; + long double max_val = std::numeric_limits::lowest(); for (unsigned int i = 0; i < G.edges.size(); i++) { if (!fuses[i] && fabs(ci.currents[i]) > cutoff) { - long double val = (long double)fabs(ci.currents[i]) / thresholds[i]; + long double val = logl(fabs(ci.currents[i])) - thresholds[i]; if (val > max_val) { max_val = val; max_pos = i; -- cgit v1.2.3-70-g09d2