|
Last change
on this file was
1,
checked in by David Owen <david.owen@…>, 16 years ago
|
|
Public release
|
|
File size:
683 bytes
|
| Line | |
|---|
| 1 | # Copyright 2010 David Owen <dsowen@fugue88.ws> |
|---|
| 2 | # Licensed under the Academic Free License version 3.0 |
|---|
| 3 | |
|---|
| 4 | import math |
|---|
| 5 | |
|---|
| 6 | class Emar(object): |
|---|
| 7 | |
|---|
| 8 | def __init__(self, period): |
|---|
| 9 | self.last = None |
|---|
| 10 | self.count = 0.0 |
|---|
| 11 | self.period = float(period) |
|---|
| 12 | |
|---|
| 13 | def _advance_to_time(self, t): |
|---|
| 14 | if self.last is not None: |
|---|
| 15 | r = (self.last - t) / self.period |
|---|
| 16 | self.count *= math.exp(r) |
|---|
| 17 | self.last = t |
|---|
| 18 | |
|---|
| 19 | def read_at_time(self, t): |
|---|
| 20 | self._advance_to_time(t) |
|---|
| 21 | return self.count / self.period |
|---|
| 22 | |
|---|
| 23 | def observed_at_time(self, t): |
|---|
| 24 | self._advance_to_time(t) |
|---|
| 25 | self.count = self.count + 1 |
|---|
| 26 | return self.count / self.period |
|---|
Note: See
TracBrowser
for help on using the repository browser.