Procházet zdrojové kódy

Added bidirectional feature

valapil před 2 roky
rodič
revize
186a9a9449
1 změnil soubory, kde provedl 10 přidání a 6 odebrání
  1. 10 6
      glamina.py

+ 10 - 6
glamina.py

@@ -200,12 +200,12 @@ def LongestSet(IntList):
     return Result
 
 
-def glamina(X: np.ndarray, Y: np.ndarray, threshold: float, l_min: list[int], l_max: int, col_x: list[int] | None =None, col_y: list[int] | None =None, shifts: list[int] | None =None, distancemeasure: str ='pearson'):
+def glamina(X: np.ndarray, Y: np.ndarray, threshold: float, l_min: list[int], l_max: int, col_x: list[int] | None =None, col_y: list[int] | None =None, shifts: list[int] | None =None, distancemeasure: str ='pearson', bidirectional: bool = False):
     """
     Finds the relevant intervals among multiple time series based on correlation between them.
 
-    :param X: whole data of subject 1 with columns holding each time series
-    :param Y: whole data of subject 2 with columns holding each time series
+    :param X: whole data of subject 1 with columns holding each time series. By default, initial time series
+    :param Y: whole data of subject 2 with columns holding each time series. By default, following (reaction) time series
     :param threshold: threshold value starting from which the correlation is significant
     :param l_min: list of minimum length of continuous relevant intervals to be considered
     :param l_max: maximum length of continuous relevant intervals
@@ -213,6 +213,7 @@ def glamina(X: np.ndarray, Y: np.ndarray, threshold: float, l_min: list[int], l_
     :param col_y: list of selected columns in subject 2 with respect to col_x. By default, takes in all columns.
     :param shifts: list of values with which X is shifted back and forth in time.
     :param distancemeasure: correlation metric. By default, Pearson's correlation
+    :param bidirectional: True if the influence of both subjects on each other are relevant. By default, influence of subject 1 on 2 is only considered
 
     :return: List of lists containing selected relevant intervals as [starting time, duration].
     """
@@ -236,9 +237,12 @@ def glamina(X: np.ndarray, Y: np.ndarray, threshold: float, l_min: list[int], l_
 
     # loop for each minimum interval length
     for m in l_min:
-        d1 = [[X[s:, :], Y[:-s, :]] if s != 0 else [X, Y] for s in shifts]
-        d2 = [[X[:-s, :], Y[s:, :]] for s in shifts if s != 0]
-        d = d1 + d2
+        if bidirectional:
+            d1 = [[X[s:, :], Y[:-s, :]] if s != 0 else [X, Y] for s in shifts]
+            d2 = [[X[:-s, :], Y[s:, :]] for s in shifts if s != 0]
+            d = d1 + d2
+        elif not bidirectional:
+            d = [[X[:-s, :], Y[s:, :]] for s in shifts if s != 0]
         for X, Y in d:
             indexlength = min(X.shape[0], Y.shape[0])
             IntMat = np.zeros([indexlength, l_max - m + 1], dtype=np.float64)