Skip to content

Commit

Permalink
(fix) comment for docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
statefb committed Jul 9, 2019
1 parent 256b6cf commit 9e14cbc
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 27 deletions.
2 changes: 2 additions & 0 deletions docs/modules/step_pattern.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. module:: dtwalign.step_pattern

=============
Step patterns
=============
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Then run :func:`~dtwalign.dtw` method which returns :class:`~dtwalign.result.Dtw
DTW distance
------------

DTW distance can be refered via ``DtwResult`` object.
DTW distance can be refered via :class:`~dtwalign.result.DtwResult` object.

.. code-block:: python
Expand All @@ -55,7 +55,7 @@ DTW distance can be refered via ``DtwResult`` object.
Alignment path
--------------

``DtwResult`` object offers a method which visualize alignment path with cumsum cost matrix.
:class:`~dtwalign.result.DtwResult` object offers a method which visualize alignment path with cumsum cost matrix.

.. code-block:: python
Expand Down Expand Up @@ -103,7 +103,7 @@ Advanced Usage
Global constraint
-----------------

``dtw`` method can take ``window_type`` parameter to constrain
:func:`~dtwalign.dtw` method can take ``window_type`` parameter to constrain
the warping path globally which is also known as 'windowing'.

.. code-block:: python
Expand Down Expand Up @@ -168,7 +168,7 @@ Following step patterns are supported:
Partial alignment
-----------------

``dtw`` method also be able to perform partial matching algorithm
:func:`~dtwalign.dtw` method also be able to perform partial matching algorithm
by setting ``open_begin`` and ``open_end``.
Before see example code, let's make toy data via following:

Expand Down
28 changes: 15 additions & 13 deletions dtwalign/dtw.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ def dtw(x, y, dist="euclidean", window_type="none", window_size=None,
y : 1D or 2D array (sample * feature)
Reference time series.
dist : string or function
Define how to calclulate pair-wise distance between x and y.
string - metric argument of scipy.spatial.distance
function - user function that defines metric between two samples.
ex) euclidean distance: user_func = lambda x,y : np.sqrt((x-y)**2)
dist : string or callable
Define how to calclulate pair-wise distance between x and y.
* string: metric argument of ``scipy.spatial.distance``
* callable: user function that defines metric between two samples.
ex) lambda x, y : np.sqrt((x - y)**2)
window_type : string
Window type to use.
"sakoechiba" - Sakoechiba window
"itakura" - Itakura window
Window type to use.
* "sakoechiba": Sakoechiba window
* "itakura": Itakura window
window_size : int
Window size to use for Sakoechiba window.
Expand All @@ -63,15 +63,15 @@ def dtw(x, y, dist="euclidean", window_type="none", window_size=None,
Step pattern to use.
dist_only : bool
Whether or not to obtain warping path. If true,
Whether or not to obtain warping path. If true,
only alignment distance will be calculated.
open_begin : bool
Whether or not perform open-ended alignment at the starting point of
Whether or not perform open-ended alignment at the starting point of
query time series. If true, partial alignment will be performed.
open_end : bool
Whether or not perform open-ended alignment at the end point of
Whether or not perform open-ended alignment at the end point of
query time series. If true, partial alignment will be performed.
Returns
Expand Down Expand Up @@ -109,7 +109,8 @@ def dtw_from_distance_matrix(X, window_type="none", window_size=None,
X : 2D array
Pre-computed pair-wise distance matrix.
others : see `dtw` function.
others :
see :func:`~dtwalign.dtw` function.
Returns
-------
Expand Down Expand Up @@ -138,7 +139,8 @@ def dtw_low(X, window, pattern, dist_only=False,
pattern : dtwalign.step_pattern.BasePattern object
step pattern object.
others : see `dtw` function.
others :
see :func:`~dtwalign.dtw` function.
Returns
-------
Expand Down
19 changes: 16 additions & 3 deletions dtwalign/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@
from scipy.interpolate import interp1d

class DtwResult():
"""Result of DTW."""
"""Result of DTW.
Attributes
----------
path : 2d array
Alignment path.
* First column: query path array
* Second column: reference path array
distance : float
Alignment distance.
normalized_distance : float
Normalized alignment distance.
"""
def __init__(self, cumsum_matrix, path, window, pattern):
self.cumsum_matrix = cumsum_matrix

Expand All @@ -23,7 +36,7 @@ def get_warping_path(self, target="query"):
Parameters
----------
target : "query" or "reference"
target : string, "query" or "reference"
Specify the target to be warped.
Returns
Expand Down Expand Up @@ -74,7 +87,7 @@ def plot_path(self, with_="cum"):
Parameters
----------
with_ : "win", "cum" or None
with_ : string, "win" or "cum" or None
If given, following will be plotted with alignment path:
* "win" : window matrix
* "cum" : cumsum matrix
Expand Down
8 changes: 5 additions & 3 deletions dtwalign/step_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,9 @@ def __init__(self, pattern_info, normalize_guide):
Parameters
----------
pattern_info : list
list contains pattern information.
ex) the case of symmetric2 pattern:
list contains pattern information.
ex) the case of symmetric2 pattern:
```
pattern_info = [
dict(
indices=[(-1,0),(0,0)],
Expand All @@ -798,9 +799,10 @@ def __init__(self, pattern_info, normalize_guide):
weights=[1]
)
]
```
normalize_guide : string ('N','M','N+M','none')
guide to compute normalized distance.
Guide to compute normalized distance.
"""
# validation
Expand Down
33 changes: 29 additions & 4 deletions dtwalign/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def __init__(self):
pass

def plot(self):
"""Show window.
"""
_, ax = plt.subplots(1)
sns.heatmap(self.matrix.T, vmin=0, vmax=1,
xticklabels=self.matrix.shape[0]//10,
Expand All @@ -28,6 +30,13 @@ def plot(self):
class NoWindow(BaseWindow):
label = "no window"
def __init__(self, len_x, len_y):
"""No window class which will be used for no constraint.
len_x : int
Length of query.
len_y : int
Length of reference.
"""
self._gen_window(len_x, len_y)

def _gen_window(self, len_x, len_y):
Expand All @@ -38,6 +47,15 @@ def _gen_window(self, len_x, len_y):
class SakoechibaWindow(BaseWindow):
label = "sakoechiba window"
def __init__(self, len_x, len_y, size):
"""Sakoechiba window.
len_x : int
Length of query.
len_y : int
Length of reference.
size : int
Size of window width.
"""
self._gen_window(len_x, len_y, size)

def _gen_window(self, len_x, len_y, size):
Expand All @@ -50,6 +68,13 @@ def _gen_window(self, len_x, len_y, size):
class ItakuraWindow(BaseWindow):
label = "itakura window"
def __init__(self, len_x, len_y):
"""Itakura window.
len_x : int
Length of query.
len_y : int
Length of reference.
"""
self._gen_window(len_x, len_y)

def _gen_window(self, len_x, len_y):
Expand Down Expand Up @@ -77,13 +102,13 @@ def __init__(self, len_x, len_y, win_func, *args, **kwargs):
Parameters
----------
len_x : int
length of query.
Length of query.
len_y : int
length of reference.
Length of reference.
win_func : callable
any function which returns bool.
Any function which returns bool.
*args, **kwargs :
arguments for win_func
Arguments for win_func
"""
self._gen_window(len_x, len_y, win_func, *args, **kwargs)
Expand Down

0 comments on commit 9e14cbc

Please sign in to comment.