Machine Learning helpers#
ML helpers: synthetic dataset generation and simple Keras models.
This module provides small utilities to generate simulated datasets and a
compact dense Keras model for parameter estimation. Note that some functions
rely on external variables/functions (L, STAR_SIGNALS,
kn_fields_jit, etc.). They are not executed during documentation builds.
- phise.modules.ml.parameter_grid(N, D, a, b)[source]#
Generate a regular grid [a, b]^D with N steps per axis.
- Parameters:
N – Resolution per axis (points per dimension).
D – Parameter space dimensionality.
a – Lower bound.
b – Upper bound.
- Returns:
np.ndarray of shape (N**D, D) listing all grid points.
- phise.modules.ml.parameter_basis(D, b=1)[source]#
Canonical basis augmented with the zero vector in R^D.
- Parameters:
D – Dimension.
b – Norm of each basis vector (default 1).
- Returns:
np.ndarray of shape (D+1, D).
- phise.modules.ml.parameter_basis_2p(D, b=1)[source]#
Two-point basis: {0, b·e_i, 2b·e_i} for i=1..D.
- Parameters:
D – Dimension.
b – Basis step.
- Returns:
np.ndarray of shape (2D+1, D).
- phise.modules.ml.get_dataset(size=1000, nb_shifters=14, nb_raw_outputs=7)[source]#
Build a structured synthetic dataset.
Note
Depends on external objects (e.g.
L,STAR_SIGNALS,kn_fields_jit).- Parameters:
size – Number of samples to generate.
nb_shifters – Dimension of the output layer (number of parameters to predict).
nb_raw_outputs – Number of raw outputs representing the intensity mapping.
- Returns:
np.ndarray of shape (size, vector_len).
- phise.modules.ml.get_random_dataset(
- size=1000,
- nb_shifters=14,
- nb_raw_outputs=7,
Build a random-point synthetic dataset.
- Parameters:
size – Number of samples to generate.
nb_shifters – Expected number of shifters outputs.
nb_raw_outputs – Number of raw outputs.
- Returns:
np.ndarray of shape (size, vector_len).
- phise.modules.ml.get_model(input_shape, nb_shifters=14)[source]#
Create a small dense Keras network for output parameters.
- Parameters:
input_shape – Input vector length.
nb_shifters – Expected number of outputs.
- Returns:
Compiled tf.keras.Model (Adam optimizer, MSE loss).
- phise.modules.ml.train_model(model, dataset, plot=True, nb_shifters=14)[source]#
Train the model and optionally plot the loss curves.
- Parameters:
model – Compiled Keras model.
dataset – Data with targets in the last 14 columns.
plot – If True, plots loss and val_loss (log scale).
nb_shifters – Expected number of outputs.
- Returns:
tf.keras.callbacks.History
- phise.modules.ml.test_model(model, dataset, nb_shifters=14, nb_raw_outputs=7)[source]#
Plot ground-truth targets vs predictions for a quick visual check.
- Parameters:
model – Trained Keras model.
dataset – Test data; uses 10 samples.
nb_shifters – Expected number of outputs.
nb_raw_outputs – expected number of raw outputs.
- Returns:
None