Add fixes identified by test cases

pull/102/head
Matthew D. Scholefield 2019-11-01 01:16:21 -05:00
parent 4cec9b0767
commit a37958f3f2
4 changed files with 14 additions and 3 deletions

View File

@ -82,4 +82,6 @@ def asigmoid(x):
def pdf(x, mu, std):
"""Probability density function (normal distribution)"""
if std == 0:
return 0
return (1.0 / (std * sqrt(2 * pi))) * np.exp(-(x - mu) ** 2 / (2 * std ** 2))

View File

@ -62,6 +62,8 @@ class EngineScript(BaseScript):
stdout.buffer.flush()
except (EOFError, KeyboardInterrupt):
pass
finally:
sys.stdout = stdout
main = EngineScript.run_main

View File

@ -34,9 +34,12 @@ class ThresholdDecoder:
def decode(self, raw_output: float) -> float:
if raw_output == 1.0 or raw_output == 0.0:
return raw_output
ratio = (asigmoid(raw_output) - self.min_out) / self.out_range
ratio = min(max(ratio, 0.0), 1.0)
cp = self.cd[int(ratio * (len(self.cd) - 1) + 0.5)]
if self.out_range == 0:
cp = int(raw_output > self.min_out)
else:
ratio = (asigmoid(raw_output) - self.min_out) / self.out_range
ratio = min(max(ratio, 0.0), 1.0)
cp = self.cd[int(ratio * (len(self.cd) - 1) + 0.5)]
if cp < self.center:
return 0.5 * cp / self.center
else:

View File

@ -107,6 +107,10 @@ class ReadWriteStream(object):
self.buffer += s
self.write_event.set()
def flush(self):
"""Makes compatible with sys.stdout"""
pass
class TriggerDetector:
"""