utils
#
Common utility functions.
Functions:
-
pinv
–Invert a matrix using SVD.
-
compute_rmsd
–Compute the RMSD and maximum displacement between two sets of coordinates.
-
brent
–Find the root of a function using Brent's method.
pinv
#
Invert a matrix using SVD.
Parameters:
-
matrix
(Tensor
) –The matrix to invert.
-
threshold
(float
, default:1e-06
) –Eigenvalues below this value will be ignored.
Returns:
-
Tensor
–The inverted matrix.
Source code in tico/utils.py
compute_rmsd
#
Compute the RMSD and maximum displacement between two sets of coordinates.
Parameters:
-
x
(Tensor
) –The first set of coordinates.
-
y
(Tensor
) –The second set of coordinates.
Returns:
-
tuple[Tensor, Tensor]
–The RMSD and maximum displacement.
Source code in tico/utils.py
brent
#
brent(
fn: Callable[[float, Any], tuple[float, bool]],
a: float,
b: float,
rel: float,
cvg: float = 0.1,
args: tuple[Any, ...] | None = None,
) -> tuple[float, list[tuple[float, float, bool]], bool]
Find the root of a function using Brent's method.
The algorithm is considered converged when abs(fs / rel) <= cvg
.
Notes
Based on https://en.wikipedia.org/wiki/Brent (31/01/24).
Parameters:
-
fn
(Callable[[float, Any], tuple[float, bool]]
) –The function to evaluate.
-
a
(float
) –The minimum value of the starting bracket.
-
b
(float
) –The maximum value of the starting bracket.
-
rel
(float
) –The denominator used to calculate the fractional error.
-
cvg
(float
, default:0.1
) –The convergence threshold for the relative error.
-
args
(tuple[Any, ...] | None
, default:None
) –Additional arguments to pass to the function.
Returns:
-
tuple[float, list[tuple[float, float, bool]], bool]
–The found root, the attempted trials, and whether the algorithm converged.
Source code in tico/utils.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|