temet.ML

Machine learning explorations.

temet.ML.common

  • Common ML/pytorch functionality.

train_model(dataloader, model, loss_fn, optimizer, batch_size, epoch_num, writer=None, verbose=True)

Train model for one epoch.

test_model(dataloader, model, loss_fn, current_sample, acc_tol=None, writer=None, verbose=True)

Test model and compute statistics.

temet.ML.explore

  • Misc ML exploration.

class mnist_network

Bases: Module

Simple NN to play with the MNIST Fashion dataset.

forward(x)

Forward pass.

mnist_tutorial()

Playing with the MNIST Fashion dataset.

temet.ML.smhm

  • Explorations: regression on stellar mass to halo mass (SMHM) relation.

class SMHMDataset(simname, redshift, secondary_params=None)

Bases: Dataset

A custom dataset for the stellar mass to halo mass (SMHM) relation.

Stores samples (M_star) and their corresponding labels (M_halo).

class mlp_network(hidden_size, num_inputs)

Bases: Module

Simple NN to play with the mstar->mhalo problem.

forward(x)

Forward pass.

train(hidden_size=8, verbose=True)

Train the SMHM MLP NN.

loss_vs_hidden_size()

Explore the effect of the hidden layer size on the loss.

plot_mstar_mhalo()

Plot the mstar->mhalo relation, ground truth vs trained model predictions.

plot_mhalo_error_distribution()

Plot a histogram of (ground truth - trained model prediction) i.e. error on mhalo.

plot_true_vs_predicted_mhalo(hidden_size=8)

Scatterplot of true vs predicted labels, versus the one-to-one (perfect) relation.

temet.ML.smhm_sbi

  • Explorations: stellar mass to halo mass (SMHM) relation, via sbi package.

train(method='SNPE')

Train a sbi (neural) estimator for the SMHM relation.

train_toy()

Testing.

temet.ML.spectra

  • Explorations: inference from mock spectra.

class MockSpectraDataset(simname, redshift, ion, instrument, model_type, EW_minmax=None, SNR=None, num_noisy_per_sample=1, coldens=False)

Bases: Dataset

A custom dataset for loading mock spectra and corresponding labels.

class mlp_network(hidden_size, num_inputs, num_hidden_layers=1)

Bases: Module

Simple MLP NN to explore the (normalized absorption spectra) -> (EW) mapping.

forward(x)

Forward pass.

class cnn_network(kernel_size, hidden_size, num_inputs, num_hidden_layers=1)

Bases: Module

Simple CNN to explore the (normalized absorption spectra) -> (EW) mapping.

forward(x)

Forward pass.

train(model_type='cnn', model_params=None, verbose=True)

Train the mockspec model.

Parameters:
  • model_type (str) – either ‘mlp’ or ‘cnn’.

  • model_params (dict) – pairs of name:value model parameters. for mlp: hidden_size, num_hidden_layers. for cnn: kernel_size, hidden_size, num_hidden_layers.

  • verbose (bool) – print out training progress.

plot_true_vs_predicted(model_type='cnn', params=None)

Scatterplot of true vs predicted labels, versus the one-to-one (perfect) relation.

run()

Driver.