You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After training the network with a dataset of inputs X_train and associated outputs Y_train, I want to evaluate the neural network on a new input X_new for a subset of outputs, and plot the result.
To do this, I need to:
Normalize X_new in the same way as the original training data.
Restrict the evaluation of the neural network to a subset of outputs.
However, I am unable to locate the appropriate methods within the provided classes to accomplish this. Would it be possible to provide documentation or an example notebook demonstrating how to plot and extract output data from nnbma using the intended methods?
The text was updated successfully, but these errors were encountered:
Hello ! Thanks for your feedback. We will add an example notebook in the documentation as you suggested to illustrate how to use a trained network in practice.
In the meantime, here are some answers to address your difficulties:
To normalize your new input
Before training, you defined a normalization for your data. After training, it is essential that you use the exact same normalization. We implemented some data pre-processing (including normalization) in nnbma.operators, but you might prefer to resort to sklearn.preprocessing.StandardScaler. In this case, save your scaler object (for instance, in a pickle file) after training to be able to load it for future uses.
For instance, let's assume that your network net is a FullyConnected instance, and that it has two inputs and 10 outputs called "output 0" to "output 9". Say that after training, you
saved a StandardScaler object in a scaler.pickle file,
and saved your trained network in a folder path_to_network, using the class method save.
To use correctly your network, here are the 4 steps you should follow :
# step 1: load your scaler, already fitted before trainingimportpicklewithopen("scaler.pickle", "rb") asf:
scaler=pickle.load(f)
# step 2: load your trained network net=FullyConnected.load(path_to_network)
# step 3: define your new input and scale itX_new=np.array([[1., 2.]]) # creates one input of shape (1, 2)X_new_scaled=scaler.transform(X_new)
# step 4: evaluate your network on X_new_scaled pred_full=net(X_new_scaled) # evaluates `net` on all 10 outputs. pred_full has shape (1, 10).
To restrict the evaluation of the neural network to a subset of outputs:
We implemented a RestrictableLinear class (innnbma.layers.restrictable_layer.py). This class defines a linear transformation with outputs that have names. By default for the FullyConnected and DenselyConnected classes, the output layer is an instance of RestrictableLayer. Each of these two network classes has a restrict_to_output_subset() method that does exactly what you want.
For instance, continuing the example above with 10 outputs called "output 0" to "output 9".
net.restrict_to_output_subset(["output 1", "output 4", "output 7"]) # the network now only predicts these 3 outputspred_restricted=net(X_new_scaled) # pred_restricted has shape (1, 3)
I'm using
nnbma
to emulate an astrophysics code.After training the network with a dataset of inputs
X_train
and associated outputsY_train
, I want to evaluate the neural network on a new inputX_new
for a subset of outputs, and plot the result.To do this, I need to:
X_new
in the same way as the original training data.However, I am unable to locate the appropriate methods within the provided classes to accomplish this. Would it be possible to provide documentation or an example notebook demonstrating how to plot and extract output data from
nnbma
using the intended methods?The text was updated successfully, but these errors were encountered: