10#ifdef MOOSE_LIBTORCH_ENABLED
14#include <torch/torch.h>
15#include <torch/script.h>
20#include "nlohmann/json.h"
37 const unsigned int num_inputs,
38 const unsigned int num_outputs,
39 const std::vector<unsigned int> & num_neurons_per_layer,
40 const std::vector<std::string> & activation_function = {
"relu"},
41 const torch::DeviceType device_type = torch::kCPU,
42 const torch::ScalarType scalar_type = torch::kDouble);
56 virtual void addLayer(
const std::string & layer_name,
57 const std::unordered_map<std::string, unsigned int> & parameters);
64 virtual torch::Tensor
forward(
const torch::Tensor & x)
override;
86 void store(nlohmann::json & json)
const;
115 std::ostream & stream,
116 std::shared_ptr<Moose::LibtorchArtificialNeuralNet> & nn,
121 std::istream & stream,
122 std::shared_ptr<Moose::LibtorchArtificialNeuralNet> & nn,
void dataStore< Moose::LibtorchArtificialNeuralNet >(std::ostream &stream, std::shared_ptr< Moose::LibtorchArtificialNeuralNet > &nn, void *context)
void dataLoad< Moose::LibtorchArtificialNeuralNet const >(std::istream &stream, Moose::LibtorchArtificialNeuralNet const *&nn, void *context)
void dataStore< Moose::LibtorchArtificialNeuralNet const >(std::ostream &stream, Moose::LibtorchArtificialNeuralNet const *&nn, void *context)
void dataLoad< Moose::LibtorchArtificialNeuralNet >(std::istream &stream, std::shared_ptr< Moose::LibtorchArtificialNeuralNet > &nn, void *context)
torch::ScalarType dataType() const
Return the data type which is used by this neural network.
const unsigned int _num_inputs
virtual torch::Tensor forward(const torch::Tensor &x) override
Overriding the forward substitution function for the neural network, unfortunately this cannot be con...
const torch::ScalarType _data_type
The data type used in this neural network.
void store(nlohmann::json &json) const
Store the network architecture in a json file (for debugging, visualization)
torch::DeviceType deviceType() const
Return the device which is used by this neural network.
MultiMooseEnum _activation_function
Activation functions (either one for all hidden layers or one for every layer separately)
const std::string & name() const
Return the name of the neural network.
std::vector< torch::nn::Linear > _weights
Submodules that hold linear operations and the corresponding weights and biases (y = W * x + b)
unsigned int numOutputs() const
Return the number of neurons on the output layer.
virtual void addLayer(const std::string &layer_name, const std::unordered_map< std::string, unsigned int > ¶meters)
Add layers to the neural network.
const unsigned int _num_outputs
Number of neurons on the output layer.
const std::vector< unsigned int > & numNeuronsPerLayer() const
Return the hidden layer architecture.
const std::string _name
Name of the neural network.
const torch::DeviceType _device_type
The device type used for this neural network.
unsigned int numHiddenLayers() const
Return the number of hidden layers.
unsigned int numInputs() const
Return the number of neurons on the input layer.
const std::vector< unsigned int > _num_neurons_per_layer
Hidden layer architecture.
const MultiMooseEnum & activationFunctions() const
Return the multi enum containing the activation functions.
void constructNeuralNetwork()
Construct the neural network.
This base class is meant to gather the functions and members common in every neural network based on ...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void to_json(nlohmann::json &json, const Moose::LibtorchArtificialNeuralNet *const &network)