diff --git a/docs/pyerrors/correlators.html b/docs/pyerrors/correlators.html index a3f979d6..1158f611 100644 --- a/docs/pyerrors/correlators.html +++ b/docs/pyerrors/correlators.html @@ -185,15 +185,9 @@ -
  • - sort_vectors -
  • permutation
  • -
  • - GEVP_solver -
  • @@ -316,15 +310,15 @@ for j in range(self.N): item[i, j].gamma_method(**kwargs) - # We need to project the Correlator with a Vector to get a single value at each timeslice. - # The method can use one or two vectors. - # If two are specified it returns v1@G@v2 (the order might be very important.) - # By default it will return the lowest source, which usually means unsmeared-unsmeared (0,0), but it does not have to def projected(self, vector_l=None, vector_r=None, normalize=False): + """We need to project the Correlator with a Vector to get a single value at each timeslice. + + The method can use one or two vectors. + If two are specified it returns v1@G@v2 (the order might be very important.) + By default it will return the lowest source, which usually means unsmeared-unsmeared (0,0), but it does not have to + """ if self.N == 1: raise Exception("Trying to project a Corr, that already has N=1.") - # This Exception is in no way necessary. One could just return self - # But there is no scenario, where a user would want that to happen and the error message might be more informative. self.gamma_method() @@ -370,8 +364,6 @@ newcontent = [None if(item is None) else item[i, j] for item in self.content] return Corr(newcontent) - # Obs and Matplotlib do not play nicely - # We often want to retrieve x,y,y_err as lists to pass them to something like pyplot.errorbar def plottable(self): """Outputs the correlator in a plotable format. @@ -386,9 +378,6 @@ return x_list, y_list, y_err_list - # symmetric returns a Corr, that has been symmetrized. - # A symmetry checker is still to be implemented - # The method will not delete any redundant timeslices (Bad for memory, Great for convenience) def symmetric(self): """ Symmetrize the correlator around x0=0.""" if self.T % 2 != 0: @@ -425,8 +414,8 @@ raise Exception("Corr could not be symmetrized: No redundant values") return Corr(newcontent, prange=self.prange) - # This method will symmetrice the matrices and therefore make them positive definit. def smearing_symmetric(self): + """Symmetrizes the matrices and therefore make them positive definite.""" if self.N > 1: transposed = [None if (G is None) else G.T for G in self.content] return 0.5 * (Corr(transposed) + self) @@ -446,7 +435,7 @@ G0[i, j] = self.content[t0][i, j].value Gt[i, j] = self.content[ts][i, j].value - sp_vecs = GEVP_solver(Gt, G0) + sp_vecs = _GEVP_solver(Gt, G0) sp_vec = sp_vecs[state] return sp_vec if return_list: @@ -459,16 +448,16 @@ G0[i, j] = self.content[t0][i, j].value Gt[i, j] = self.content[t][i, j].value - sp_vecs = GEVP_solver(Gt, G0) + sp_vecs = _GEVP_solver(Gt, G0) if sorting == "Eigenvalue": sp_vec = sp_vecs[state] all_vecs.append(sp_vec) else: all_vecs.append(sp_vecs) - except "Failure to solve for one timeslice": # This could contain a check for real eigenvectors + except Exception: all_vecs.append(None) if sorting == "Eigenvector": - all_vecs = sort_vectors(all_vecs, ts) + all_vecs = _sort_vectors(all_vecs, ts) all_vecs = [a[state] for a in all_vecs] return all_vecs @@ -493,11 +482,20 @@ return Corr(newcontent) def Hankel(self, N, periodic=False): - # Constructs an NxN Hankel matrix - # C(t) c(t+1) ... c(t+n-1) - # C(t+1) c(t+2) ... c(t+n) - # ................. - # C(t+(n-1)) c(t+n) ... c(t+2(n-1)) + """Constructs an NxN Hankel matrix + + C(t) c(t+1) ... c(t+n-1) + C(t+1) c(t+2) ... c(t+n) + ................. + C(t+(n-1)) c(t+n) ... c(t+2(n-1)) + + Parameters: + ----------- + N : int + Dimension of the Hankel matrix + periodic : bool, optional + determines whether the matrix is extended periodically + """ if self.N != 1: raise Exception("Multi-operator Prony not implemented!") @@ -734,11 +732,6 @@ if self.N != 1: raise Exception("Correlator must be projected before fitting") - # The default behavior is: - # 1 use explicit fitrange - # if none is provided, use the range of the corr - # if this is also not set, use the whole length of the corr (This could come with a warning!) - if fitrange is None: if self.prange: fitrange = self.prange @@ -1138,7 +1131,8 @@ return self._apply_func_to_corr(return_imag) -def sort_vectors(vec_set, ts): # Helper function used to find a set of Eigenvectors consistent over all timeslices +def _sort_vectors(vec_set, ts): + """Helper function used to find a set of Eigenvectors consistent over all timeslices""" reference_sorting = np.array(vec_set[ts]) N = reference_sorting.shape[0] sorted_vec_set = [] @@ -1157,7 +1151,6 @@ if current_score > best_score: best_score = current_score best_perm = perm - # print("best perm", best_perm) sorted_vec_set.append([vec_set[t][k] for k in best_perm]) else: sorted_vec_set.append(vec_set[t]) @@ -1178,7 +1171,7 @@ return ll -def GEVP_solver(Gt, G0): # Just so normalization an sorting does not need to be repeated. Here we could later put in some checks +def _GEVP_solver(Gt, G0): # Just so normalization an sorting does not need to be repeated. Here we could later put in some checks sp_val, sp_vecs = scipy.linalg.eig(Gt, G0) sp_vecs = [sp_vecs[:, np.argsort(sp_val)[-i]] for i in range(1, sp_vecs.shape[0] + 1)] sp_vecs = [v / np.sqrt((v.T @ G0 @ v)) for v in sp_vecs] @@ -1290,15 +1283,15 @@ for j in range(self.N): item[i, j].gamma_method(**kwargs) - # We need to project the Correlator with a Vector to get a single value at each timeslice. - # The method can use one or two vectors. - # If two are specified it returns v1@G@v2 (the order might be very important.) - # By default it will return the lowest source, which usually means unsmeared-unsmeared (0,0), but it does not have to def projected(self, vector_l=None, vector_r=None, normalize=False): + """We need to project the Correlator with a Vector to get a single value at each timeslice. + + The method can use one or two vectors. + If two are specified it returns v1@G@v2 (the order might be very important.) + By default it will return the lowest source, which usually means unsmeared-unsmeared (0,0), but it does not have to + """ if self.N == 1: raise Exception("Trying to project a Corr, that already has N=1.") - # This Exception is in no way necessary. One could just return self - # But there is no scenario, where a user would want that to happen and the error message might be more informative. self.gamma_method() @@ -1344,8 +1337,6 @@ newcontent = [None if(item is None) else item[i, j] for item in self.content] return Corr(newcontent) - # Obs and Matplotlib do not play nicely - # We often want to retrieve x,y,y_err as lists to pass them to something like pyplot.errorbar def plottable(self): """Outputs the correlator in a plotable format. @@ -1360,9 +1351,6 @@ return x_list, y_list, y_err_list - # symmetric returns a Corr, that has been symmetrized. - # A symmetry checker is still to be implemented - # The method will not delete any redundant timeslices (Bad for memory, Great for convenience) def symmetric(self): """ Symmetrize the correlator around x0=0.""" if self.T % 2 != 0: @@ -1399,8 +1387,8 @@ raise Exception("Corr could not be symmetrized: No redundant values") return Corr(newcontent, prange=self.prange) - # This method will symmetrice the matrices and therefore make them positive definit. def smearing_symmetric(self): + """Symmetrizes the matrices and therefore make them positive definite.""" if self.N > 1: transposed = [None if (G is None) else G.T for G in self.content] return 0.5 * (Corr(transposed) + self) @@ -1420,7 +1408,7 @@ G0[i, j] = self.content[t0][i, j].value Gt[i, j] = self.content[ts][i, j].value - sp_vecs = GEVP_solver(Gt, G0) + sp_vecs = _GEVP_solver(Gt, G0) sp_vec = sp_vecs[state] return sp_vec if return_list: @@ -1433,16 +1421,16 @@ G0[i, j] = self.content[t0][i, j].value Gt[i, j] = self.content[t][i, j].value - sp_vecs = GEVP_solver(Gt, G0) + sp_vecs = _GEVP_solver(Gt, G0) if sorting == "Eigenvalue": sp_vec = sp_vecs[state] all_vecs.append(sp_vec) else: all_vecs.append(sp_vecs) - except "Failure to solve for one timeslice": # This could contain a check for real eigenvectors + except Exception: all_vecs.append(None) if sorting == "Eigenvector": - all_vecs = sort_vectors(all_vecs, ts) + all_vecs = _sort_vectors(all_vecs, ts) all_vecs = [a[state] for a in all_vecs] return all_vecs @@ -1467,11 +1455,20 @@ return Corr(newcontent) def Hankel(self, N, periodic=False): - # Constructs an NxN Hankel matrix - # C(t) c(t+1) ... c(t+n-1) - # C(t+1) c(t+2) ... c(t+n) - # ................. - # C(t+(n-1)) c(t+n) ... c(t+2(n-1)) + """Constructs an NxN Hankel matrix + + C(t) c(t+1) ... c(t+n-1) + C(t+1) c(t+2) ... c(t+n) + ................. + C(t+(n-1)) c(t+n) ... c(t+2(n-1)) + + Parameters: + ----------- + N : int + Dimension of the Hankel matrix + periodic : bool, optional + determines whether the matrix is extended periodically + """ if self.N != 1: raise Exception("Multi-operator Prony not implemented!") @@ -1708,11 +1705,6 @@ if self.N != 1: raise Exception("Correlator must be projected before fitting") - # The default behavior is: - # 1 use explicit fitrange - # if none is provided, use the range of the corr - # if this is also not set, use the whole length of the corr (This could come with a warning!) - if fitrange is None: if self.prange: fitrange = self.prange @@ -2254,10 +2246,14 @@ region indentified for this correlator.
    View Source
        def projected(self, vector_l=None, vector_r=None, normalize=False):
    +        """We need to project the Correlator with a Vector to get a single value at each timeslice.
    +
    +        The method can use one or two vectors.
    +        If two are specified it returns v1@G@v2 (the order might be very important.)
    +        By default it will return the lowest source, which usually means unsmeared-unsmeared (0,0), but it does not have to
    +        """
             if self.N == 1:
                 raise Exception("Trying to project a Corr, that already has N=1.")
    -            # This Exception is in no way necessary. One could just return self
    -            # But there is no scenario, where a user would want that to happen and the error message might be more informative.
     
             self.gamma_method()
     
    @@ -2296,7 +2292,13 @@ region indentified for this correlator.
     
             
    - +

    We need to project the Correlator with a Vector to get a single value at each timeslice.

    + +

    The method can use one or two vectors. +If two are specified it returns v1@G@v2 (the order might be very important.) +By default it will return the lowest source, which usually means unsmeared-unsmeared (0,0), but it does not have to

    +
    +
    @@ -2458,6 +2460,7 @@ timeslice and the error on each timeslice.

    View Source
        def smearing_symmetric(self):
    +        """Symmetrizes the matrices and therefore make them positive definite."""
             if self.N > 1:
                 transposed = [None if (G is None) else G.T for G in self.content]
                 return 0.5 * (Corr(transposed) + self)
    @@ -2467,7 +2470,9 @@ timeslice and the error on each timeslice.

    - +

    Symmetrizes the matrices and therefore make them positive definite.

    +
    +
    @@ -2490,7 +2495,7 @@ timeslice and the error on each timeslice.

    G0[i, j] = self.content[t0][i, j].value Gt[i, j] = self.content[ts][i, j].value - sp_vecs = GEVP_solver(Gt, G0) + sp_vecs = _GEVP_solver(Gt, G0) sp_vec = sp_vecs[state] return sp_vec if return_list: @@ -2503,16 +2508,16 @@ timeslice and the error on each timeslice.

    G0[i, j] = self.content[t0][i, j].value Gt[i, j] = self.content[t][i, j].value - sp_vecs = GEVP_solver(Gt, G0) + sp_vecs = _GEVP_solver(Gt, G0) if sorting == "Eigenvalue": sp_vec = sp_vecs[state] all_vecs.append(sp_vec) else: all_vecs.append(sp_vecs) - except "Failure to solve for one timeslice": # This could contain a check for real eigenvectors + except Exception: all_vecs.append(None) if sorting == "Eigenvector": - all_vecs = sort_vectors(all_vecs, ts) + all_vecs = _sort_vectors(all_vecs, ts) all_vecs = [a[state] for a in all_vecs] return all_vecs @@ -2569,11 +2574,20 @@ timeslice and the error on each timeslice.

    View Source
        def Hankel(self, N, periodic=False):
    -        # Constructs an NxN Hankel matrix
    -        # C(t) c(t+1) ... c(t+n-1)
    -        # C(t+1) c(t+2) ... c(t+n)
    -        # .................
    -        # C(t+(n-1)) c(t+n) ... c(t+2(n-1))
    +        """Constructs an NxN Hankel matrix
    +
    +        C(t) c(t+1) ... c(t+n-1)
    +        C(t+1) c(t+2) ... c(t+n)
    +        .................
    +        C(t+(n-1)) c(t+n) ... c(t+2(n-1))
    +
    +        Parameters:
    +        -----------
    +        N : int
    +            Dimension of the Hankel matrix
    +        periodic : bool, optional
    +            determines whether the matrix is extended periodically
    +        """
     
             if self.N != 1:
                 raise Exception("Multi-operator Prony not implemented!")
    @@ -2603,7 +2617,21 @@ timeslice and the error on each timeslice.

    - +

    Constructs an NxN Hankel matrix

    + +

    C(t) c(t+1) ... c(t+n-1) +C(t+1) c(t+2) ... c(t+n) +................. +C(t+(n-1)) c(t+n) ... c(t+2(n-1))

    + +

    Parameters:

    + +

    N : int + Dimension of the Hankel matrix +periodic : bool, optional + determines whether the matrix is extended periodically

    +
    +
    @@ -3027,11 +3055,6 @@ guess for the root finder, only relevant for the root variant if self.N != 1: raise Exception("Correlator must be projected before fitting") - # The default behavior is: - # 1 use explicit fitrange - # if none is provided, use the range of the corr - # if this is also not set, use the whole length of the corr (This could come with a warning!) - if fitrange is None: if self.prange: fitrange = self.prange @@ -3653,48 +3676,6 @@ specifies a custom path for the file (default '.')
    - -
    -
    #   - - - def - sort_vectors(vec_set, ts): -
    - -
    - View Source -
    def sort_vectors(vec_set, ts):  # Helper function used to find a set of Eigenvectors consistent over all timeslices
    -    reference_sorting = np.array(vec_set[ts])
    -    N = reference_sorting.shape[0]
    -    sorted_vec_set = []
    -    for t in range(len(vec_set)):
    -        if vec_set[t] is None:
    -            sorted_vec_set.append(None)
    -        elif not t == ts:
    -            perms = permutation([i for i in range(N)])
    -            best_score = 0
    -            for perm in perms:
    -                current_score = 1
    -                for k in range(N):
    -                    new_sorting = reference_sorting.copy()
    -                    new_sorting[perm[k], :] = vec_set[t][k]
    -                    current_score *= abs(np.linalg.det(new_sorting))
    -                if current_score > best_score:
    -                    best_score = current_score
    -                    best_perm = perm
    -            # print("best perm", best_perm)
    -            sorted_vec_set.append([vec_set[t][k] for k in best_perm])
    -        else:
    -            sorted_vec_set.append(vec_set[t])
    -
    -    return sorted_vec_set
    -
    - -
    - - -
    #   @@ -3723,28 +3704,6 @@ specifies a custom path for the file (default '.') -
    -
    -
    #   - - - def - GEVP_solver(Gt, G0): -
    - -
    - View Source -
    def GEVP_solver(Gt, G0):  # Just so normalization an sorting does not need to be repeated. Here we could later put in some checks
    -    sp_val, sp_vecs = scipy.linalg.eig(Gt, G0)
    -    sp_vecs = [sp_vecs[:, np.argsort(sp_val)[-i]] for i in range(1, sp_vecs.shape[0] + 1)]
    -    sp_vecs = [v / np.sqrt((v.T @ G0 @ v)) for v in sp_vecs]
    -    return sp_vecs
    -
    - -
    - - -