neurosynchro.impl
: the neural-network implementation¶
The main neural network code.
This module contains PhysicalApproximator
, the class that uses
prebuild keras
neural networks to rapidly approximate radiative
transfer coefficients.
-
class
neurosynchro.impl.
PhysicalApproximator
(nn_dir)[source]¶ This class approximates the eight nontrivial RT coefficients using a physically-based parameterization.
See Tutorial, AKA, How to Use It for detailed documentation of how to prepare and train the neural networks used by this class.
Constructor argument
- nn_dir
- The path to a directory containing trained neural network data. This
directory should contain the configuration file
nn_config.toml
and serialized neural network weights in files with names likerho_Q_sign.h5
.
-
compute_all_nontrivial
(nu, B, n_e, theta, **kwargs)[source]¶ Compute the nontrivial radiative transfer coefficients.
Arguments
- nu
- The observing frequency, in Hz. This and all parameters may be scalars or arrays; they are broadcast to a common shape before performing the computations.
- B
- The local magnetic field strength, in G.
- n_e
- The local density of synchrotron-emitting particles, in cm^-3.
- theta
- The angle between the line of sight and the local magnetic field, in radians.
**kwargs
- Other arguments to the synchrotron model; these can vary depending on which particle distribution was used.
Return values
A tuple of
(coeffs, oos)
:- coeffs
- The radiative transfer coefficients in the Stokes basis where the
Stokes U axis is aligned with the magnetic field. This is an array
of shape
S + (8,)
where S is the shape of the broadcasted input parameters. Along the inner axis of the array, the coefficients are:(j_I, alpha_I, j_Q, alpha_Q, j_V, alpha_V, rho_Q, rho_V)
. - oos
- An array of integers reporting where the calculations encountered
out-of-sample values, that is, inputs or outputs beyond the range in
which the neural networks were trained. The shape of this array is
the same as that of the broadcased input parameters, or a scalar if
the inputs were all scalars. For each set of input parameters, the
least significant bit is set to 1 if the first input parameter was
out-of-sample, where “first” is defined by the order in which these
parameters are listed in the
nn_config.toml
file. The next more significant bit is set if the second input parameter was out of sample, and so on. After all of the input parameters, there are 9 flag bits indicating whether any of the output results were out-of-sample, relative to the range of normalized values encountered in the training set. The order in which these parameters are processed isj_I
,alpha_I
,rho_Q
,rho_V
,j_frac_pol
,alpha_frac_pol
,j_V_share
,alpha_V_share
,rho_Q_sign
. Therefore if the synchrotron model takes 4 input parameters and therho_Q_sign
output is the only one to have been out-of-sample, the resultingoos
value will be0x1000
.