utils
Utils¶
This submodule provides utility functions that can be used to manipulate and test data, such as filtering and validation methods. The functions in this submodule can be used in conjunction with other parts of the software to perform a variety of tasks, making it an essential part of the package.
The submodule is structured into the following submodules:
- datasets: This submodule contains all methods related to create example datasets. This submodule needs to be imported explicitly!
- filtering: This submodule contains all methods related to dynamical smoothening.
- tests: This submodule holds functions to tests for given properties, e.g., if a matrix is ergodic, quadratic, etc.
find_first(search_val, array)
¶
Return first occurance of item in array.
Source code in src/msmhelper/utils/_utils.py
403 404 405 406 407 408 409 |
|
format_state_traj(trajs)
¶
Convert state trajectory to list of ndarrays.
Parameters:
-
trajs
(list or ndarray or list of ndarray
) –State trajectory/trajectories. The states should start from zero and need to be integers.
Returns:
-
trajs
(list of ndarray
) –Return list of ndarrays of integers.
Source code in src/msmhelper/utils/_utils.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
matrix_power(matrix, power)
¶
Calculate matrix power with np.linalg.matrix_power.
Numba wrapper for numpy.linalg.matrix_power. Only for float matrices.
Parameters:
-
matrix
(ndarray
) –2d matrix of type float.
-
power
((int, float)
) –Power of matrix.
Returns:
-
matpow
(ndarray
) –Matrix power.
Source code in src/msmhelper/utils/_utils.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
rename_by_index(trajs, return_permutation=False)
¶
Rename states sorted by their numerical values starting from 0.
Parameters:
-
trajs
(list or ndarray or list of ndarrays
) –State trajectory or list of state trajectories.
-
return_permutation
(bool
, default:False
) –Return additionaly the permutation to achieve performed renaming. Default is False.
Returns:
-
trajs
(ndarray
) –Renamed data.
-
permutation
(ndarray
) –Permutation going from old to new state nameing. So the
i
th state of the new naming corresponds to the old statepermutation[i-1]
.
Source code in src/msmhelper/utils/_utils.py
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 142 143 |
|
rename_by_population(trajs, return_permutation=False)
¶
Rename states sorted by their population starting from 1.
Parameters:
-
trajs
(list or ndarray or list of ndarrays
) –State trajectory or list of state trajectories.
-
return_permutation
(bool
, default:False
) –Return additionaly the permutation to achieve performed renaming. Default is False.
Returns:
-
trajs
(ndarray
) –Renamed data.
-
permutation
(ndarray
) –Permutation going from old to new state nameing. So the
i
th state of the new naming corresponds to the old statepermutation[i-1]
.
Source code in src/msmhelper/utils/_utils.py
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 |
|
runningmean(array, window)
¶
Compute centered running average with given window size.
This function returns the centered based running average of the given data. The output of this function is of the same length as the input, by assuming that the given data is zero before and after the given series. Hence, there are border affects which are not corrected.
Warning
If the given window is even (not symmetric) it will be shifted towards
the beginning of the current value. So for window=4
, it will consider
the current position \(i\), the two to the left \(i-2\) and \(i-1\) and
one to the right \(i+1\).
Function is taken from lapis: https://stackoverflow.com/questions/13728392/moving-average-or-running-mean
Parameters:
-
array
(ndarray
) –One dimensional numpy array.
-
window
(int
) –Integer which specifies window-width.
Returns:
-
array_rmean
(ndarray
) –Data which is time-averaged over the specified window.
Source code in src/msmhelper/utils/_utils.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
shift_data(array, val_old, val_new, dtype=np.int64)
¶
Shift integer array (data) from old to new values.
Warning
The values of val_old
, val_new
and data
needs to be integers.
The basic function is based on Ashwini_Chaudhary solution: https://stackoverflow.com/a/29408060
Parameters:
-
array
(StateTraj or ndarray or list or list of ndarrays
) –1D data or a list of data.
-
val_old
(ndarray or list
) –Values in data which should be replaced. All values needs to be within the range of
[data.min(), data.max()]
-
val_new
(ndarray or list
) –Values which will be used instead of old ones.
-
dtype
(data - type
, default:int64
) –The desired data-type. Needs to be of type unsigned integer.
Returns:
-
array
(ndarray
) –Shifted data in same shape as input.
Source code in src/msmhelper/utils/_utils.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
swapcols(array, indicesold, indicesnew)
¶
Interchange cols of an ndarray.
This method swaps the specified columns.
Parameters:
-
array
(ndarray
) –2D numpy array.
-
indicesold
(integer or ndarray
) –1D array of indices.
-
indicesnew
(integer or ndarray
) –1D array of new indices
Returns:
-
array_swapped
(ndarray
) –2D numpy array with swappend columns.
Source code in src/msmhelper/utils/_utils.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
unique(trajs, **kwargs)
¶
Apply numpy.unique to traj.
Parameters:
-
trajs
(list or ndarray or list of ndarrays
) –State trajectory or list of state trajectories.
-
**kwargs
–Arguments of numpy.unique
Returns:
-
unique
(ndarray
) –Array containing all states, see numpy for more details.
Source code in src/msmhelper/utils/_utils.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|