Utils Reference
This page contains the API reference for utility functions in neojax.
neojax.utils
Functions
count_array_params(arr, dims=None)
Returns the number of parameters (elements) in a single array, optionally, along certain dimensions only
Parameters
array : Array dims : int list or None, default is None if not None, the dimensions to consider when counting the number of parameters (elements)
Notes
One complex number is counted as two parameters (we count real and imaginary parts)'
Source code in neojax/utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
count_model_params(model)
Returns the total number of parameters of an equinox model
Notes
One complex number is counted as two parameters (we count real and imaginary parts)'
Source code in neojax/utils.py
19 20 21 22 23 24 25 26 27 28 | |
spectrum_2d(signal, n_observations, normalize=True)
This function computes the spectrum of a 2D signal using the Fast Fourier Transform (FFT).
Parameters
signal : an array of shape (T * n_observations * n_observations) A 2D discretized signal represented as a 1D array with shape (T * n_observations * n_observations), where T is the number of time steps and n_observations is the spatial size of the signal.
T can be any number of channels that we reshape into and
n_observations * n_observations is the spatial resolution.
n_observations: an integer
Number of discretized points. Basically the resolution of the signal.
normalize: bool
whether to apply normalization to the output of the 2D FFT.
If True, normalizes the outputs by 1/n_observations
(actually 1/sqrt(n_observations * n_observations)).
Returns
spectrum: a array A 1D array of shape (s,) representing the computed spectrum. The spectrum is computed using a square approximation to radial binning, meaning that the wavenumber 'bin' into which a particular coefficient is the coefficient's location along the diagonal, indexed from the top-left corner of the 2d FFT output.
Source code in neojax/utils.py
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 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
validate_scaling_factor(scaling_factor, n_dim, n_layers=None)
Parameters
scaling_factor : None OR float OR list[float] Or list[list[float]]
n_dim : int
n_layers : int or None; defaults to None
If None, return a single list (rather than a list of lists)
with factor repeated dim times.
Source code in neojax/utils.py
160 161 162 163 164 165 166 167 168 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 205 206 | |