APOGEE Spectra with Convolutional Neural Net - ApogeeCNN

class astroNN.models.apogee_models.ApogeeCNN(lr=0.005)[source]

Class for Convolutional Neural Network for stellar spectra analysis

History:

2017-Dec-21 - Written - Henry Leung (University of Toronto)

digraph inheritance0f116a7e8d { bgcolor=transparent; dpi=144; rankdir=LR; size="8.0, 12.0"; "ABC" [URL="https://docs.python.org/3/library/abc.html#abc.ABC",dpi=144,fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Helper class that provides a standard way to create an ABC using"]; "ApogeeCNN" [URL="#astroNN.models.apogee_models.ApogeeCNN",dpi=144,fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Class for Convolutional Neural Network for stellar spectra analysis"]; "CNNBase" -> "ApogeeCNN" [arrowsize=0.5,style="setlinewidth(0.5)"]; "CNNBase" [URL="basic_usage.html#astroNN.models.base_cnn.CNNBase",dpi=144,fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Top-level class for a convolutional neural network"]; "NeuralNetMaster" -> "CNNBase" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ABC" -> "CNNBase" [arrowsize=0.5,style="setlinewidth(0.5)"]; "NeuralNetMaster" [URL="basic_usage.html#astroNN.models.base_master_nn.NeuralNetMaster",dpi=144,fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Top-level class for an astroNN neural network"]; "ABC" -> "NeuralNetMaster" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Although in theory you can feed any 1D data to astroNN neural networks. This tutorial will only focus on spectra analysis.

from astroNN.models import ApogeeCNN
from astroNN.datasets import H5Loader

# Load the train data from dataset first, x_train is spectra and y_train will be ASPCAP labels
loader = H5Loader('datasets.h5')
loader.load_err = False
x_train, y_train = loader.load()

# And then create an instance of Convolutional Neural Network class
cnn_net = ApogeeCNN()

# You don't have to specify the task because its 'regression' by default. But if you are doing classification. you can set task='classification'
cnn_net.task = 'regression'

# Set max_epochs to 10 for a quick result. You should train more epochs normally
cnn_net.max_epochs = 10
cnn_net.train(x_train, y_train)

Here is a list of parameter you can set but you can also not set them to use default

ApogeeCNN.batch_size = 64
ApogeeCNN.initializer = 'he_normal'
ApogeeCNN.activation = 'relu'
ApogeeCNN.num_filters = [2, 4]
ApogeeCNN.filter_len = 8
ApogeeCNN.pool_length = 4
ApogeeCNN.num_hidden = [196, 96]
ApogeeCNN.max_epochs = 250
ApogeeCNN.lr = 0.005
ApogeeCNN.reduce_lr_epsilon = 0.00005
ApogeeCNN.reduce_lr_min = 0.0000000001
ApogeeCNN.reduce_lr_patience = 10
ApogeeCNN.target = 'all'
ApogeeCNN.l2 = 1e-7
ApogeeCNN.input_norm_mode = 1
ApogeeCNN.labels_norm_mode = 2

Note

You can disable astroNN data normalization via ApogeeCNN.input_norm_mode=0 as well as ApogeeCNN.labels_norm_mode = 0 and do normalization yourself. But make sure you don’t normalize labels with MAGIC_NUMBER (missing labels).

After the training, you can use cnn_net in this case and call test method to test the neural network on test data. Or you can load the folder by

from astroNN.models import load_folder
cnn_net = load_folder('astroNN_0101_run001')

# Load the test data from dataset, x_test is spectra and y_test will be ASPCAP labels
loader2 = H5Loader('datasets.h5')
loader2.load_combined = False
x_test, y_test = loader2.load()

pred = cnn_net.test(x_test)  # pred contains denormalized result aka. ASPCAP labels prediction in this case

Since astroNN.models.ApogeeCNN does not have uncertainty analysis feature.

You can calculate jacobian which represents the output derivative to the input and see where those output is sensitive to in inputs.

# Calculate jacobian first
jacobian_array = cnn_net.jacobian(x_test, mean_output=True)

Note

You can access to Keras model method like model.predict via (in the above tutorial) cnn_net.keras_model (Example: cnn_net.keras_model.predict())

Example Plots using aspcap_residue_plot

../_images/logg_test1.png ../_images/teff_test.png

ASPCAP labels prediction using CNN vs The Cannon 2

Warning

Please refer to Bayesian Neural Network for the most updated result: https://astronn.readthedocs.io/en/latest/neuralnets/apogee_bcnn.html

https://image.ibb.co/fDY5JG/table1.png

Example Plots using jacobian

../_images/Cl_jacobian.png ../_images/Na_jacobian.png