diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2014-09-18 17:09:58 +0200 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2014-09-18 17:09:58 +0200 |
commit | b20d416c4765b2280526c633ca62f43677b1d26a (patch) | |
tree | d7e4e719edf41b4adee94bf3811ea573d7235b21 /pyspike/function.py | |
parent | eb076dcd9d76ed3b848c78fb067c1ad6a1d6da23 (diff) |
add spike-distance, PWL function (probably buggy)
Diffstat (limited to 'pyspike/function.py')
-rw-r--r-- | pyspike/function.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/pyspike/function.py b/pyspike/function.py index c1de9cb..adf4dbb 100644 --- a/pyspike/function.py +++ b/pyspike/function.py @@ -44,8 +44,6 @@ class PieceWiseConstFunc: Returns: - the average a. """ - print(self.x) - print(self.y) return np.sum((self.x[1:]-self.x[:-1]) * self.y) / \ (self.x[-1]-self.x[0]) @@ -58,3 +56,34 @@ class PieceWiseConstFunc: """ return np.sum((self.x[1:]-self.x[:-1]) * np.abs(self.y)) / \ (self.x[-1]-self.x[0]) + + +class PieceWiseLinFunc: + """ A class representing a piece-wise linear function. """ + + def __init__(self, x, y1, y2): + """ Constructs the piece-wise linear function. + Params: + - x: array of length N+1 defining the edges of the intervals of the pwc + function. + - y1: array of length N defining the function values at the left of the + intervals. + - y2: array of length N defining the function values at the right of the + intervals. + """ + self.x = x + self.y1 = y1 + self.y2 = y2 + + def get_plottable_data(self): + """ Returns two arrays containing x- and y-coordinates for immeditate + plotting of the piece-wise function. + """ + x_plot = np.empty(2*len(self.x)-2) + x_plot[0] = self.x[0] + x_plot[1::2] = self.x[1:] + x_plot[2::2] = self.x[1:-1] + y_plot = np.empty_like(x_plot) + y_plot[0::2] = self.y1 + y_plot[1::2] = self.y2 + return x_plot, y_plot |