https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Moose::LibtorchArtificialNeuralNet Class Reference

Simple feed-forward neural net with optional affine input and output scaling. More...

#include <LibtorchArtificialNeuralNet.h>

Inheritance diagram for Moose::LibtorchArtificialNeuralNet:
[legend]

Public Member Functions

 LibtorchArtificialNeuralNet (const std::string name, const unsigned int num_inputs, const unsigned int num_outputs, const std::vector< unsigned int > &num_neurons_per_layer, const std::vector< std::string > &activation_function={"relu"}, const torch::DeviceType device_type=torch::kCPU, const torch::ScalarType scalar_type=torch::kDouble, const bool build_on_construct=true, const std::vector< Real > &input_shift_factors={}, const std::vector< Real > &input_scaling_factors={}, const std::vector< Real > &output_scaling_factors={})
 Build a plain feed-forward neural network.
 
 LibtorchArtificialNeuralNet (const Moose::LibtorchArtificialNeuralNet &nn, const bool build_on_construct=true)
 Copy-construct a feed-forward neural network.
 
virtual void addLayer (const std::string &layer_name, const std::unordered_map< std::string, unsigned int > &parameters)
 Add one linear layer to the network.
 
virtual torch::Tensor forward (const torch::Tensor &x) override
 Run a forward pass through the network.
 
const std::string & name () const
 Return the name of the neural network.
 
unsigned int numInputs () const
 Return the number of neurons on the input layer.
 
unsigned int numOutputs () const
 Return the number of neurons on the output layer.
 
unsigned int numHiddenLayers () const
 Return the number of hidden layers.
 
const std::vector< unsigned int > & numNeuronsPerLayer () const
 Return the hidden layer architecture.
 
const MultiMooseEnum & activationFunctions () const
 Return the multi enum containing the activation functions.
 
torch::DeviceType deviceType () const
 Return the device used by this neural network.
 
torch::ScalarType dataType () const
 Return the data type used by this neural network.
 
const std::vector< Real > & inputShiftFactors () const
 Return the affine input shift factors used before evaluation.
 
const std::vector< Real > & inputScalingFactors () const
 Return the affine input scaling factors used before evaluation.
 
const std::vector< Real > & outputScalingFactors () const
 Return the output scaling factors applied after evaluation.
 
virtual void constructNeuralNetwork ()
 Construct the neural network.
 
void synchronizeAffineFactorsFromBuffers ()
 Update cached affine metadata vectors from the registered libtorch buffers.
 
Real determineGain (const std::string &activation)
 Map an activation name to the orthogonal-initialization gain we want to use.
 
virtual void initializeNeuralNetwork (c10::optional< at::Generator > generator=c10::nullopt)
 Initialize the trainable weights and biases.
 
void store (nlohmann::json &json) const
 Store the network architecture in a JSON object for debugging or visualization.
 

Protected Member Functions

void initializeAffineBuffers ()
 Initialize the registered affine metadata buffers used by serialization.
 
virtual torch::Tensor preprocessInput (const torch::Tensor &x) const
 Apply affine preprocessing to the raw input tensor.
 
virtual torch::Tensor scaleOutput (const torch::Tensor &y) const
 Apply the configured output scaling to a network output tensor.
 

Static Protected Member Functions

static std::vector< Real > setAffineFactors (const std::vector< Real > &factors, unsigned int expected_size, Real default_value, const std::string &factor_name)
 Set affine metadata by either accepting the user values or filling defaults.
 

Protected Attributes

const std::string _name
 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)
 
const unsigned int _num_inputs
 Number of neurons on the input layer.
 
const unsigned int _num_outputs
 Number of neurons on the output layer.
 
const std::vector< unsigned int > _num_neurons_per_layer
 Hidden layer architecture.
 
MultiMooseEnum _activation_function
 Activation functions (either one for all hidden layers or one for every layer separately)
 
const torch::DeviceType _device_type
 The device type used for this neural network.
 
const torch::ScalarType _data_type
 The data type used in this neural network.
 
std::vector< Real > _input_shift_factors
 Affine preprocessing applied to the flattened input.
 
std::vector< Real > _input_scaling_factors
 Multiplicative affine preprocessing applied after shifting the input.
 
std::vector< Real > _output_scaling_factors
 Multiplicative scaling applied after the network output is formed.
 
torch::Tensor _input_shift_tensor
 Registered libtorch buffer holding the affine input shifts.
 
torch::Tensor _input_scale_tensor
 Registered libtorch buffer holding the affine input scaling factors.
 
torch::Tensor _output_scale_tensor
 Registered libtorch buffer holding the output scaling factors.
 

Detailed Description

Simple feed-forward neural net with optional affine input and output scaling.

Definition at line 29 of file LibtorchArtificialNeuralNet.h.

Constructor & Destructor Documentation

◆ LibtorchArtificialNeuralNet() [1/2]

Moose::LibtorchArtificialNeuralNet::LibtorchArtificialNeuralNet ( const std::string  name,
const unsigned int  num_inputs,
const unsigned int  num_outputs,
const std::vector< unsigned int > &  num_neurons_per_layer,
const std::vector< std::string > &  activation_function = {"relu"},
const torch::DeviceType  device_type = torch::kCPU,
const torch::ScalarType  scalar_type = torch::kDouble,
const bool  build_on_construct = true,
const std::vector< Real > &  input_shift_factors = {},
const std::vector< Real > &  input_scaling_factors = {},
const std::vector< Real > &  output_scaling_factors = {} 
)

Build a plain feed-forward neural network.

Parameters
nameName of the neural network module.
num_inputsNumber of input neurons or parameters.
num_outputsNumber of output neurons.
num_neurons_per_layerHidden-layer widths.
activation_functionHidden-layer activation names.
device_typeTorch device used by the module.
scalar_typeTorch scalar type used by the module.
build_on_constructWhether to build the torch modules right away.
input_shift_factorsOptional affine input shifts.
input_scaling_factorsOptional affine input scales.
output_scaling_factorsOptional output scaling factors.

Definition at line 198 of file LibtorchArtificialNeuralNet.C.

210 : _name(name),
211 _num_inputs(num_inputs),
212 _num_outputs(num_outputs),
213 _num_neurons_per_layer(num_neurons_per_layer),
214 _activation_function(MultiMooseEnum("relu sigmoid elu gelu linear tanh", "relu")),
215 _device_type(device_type),
216 _data_type(data_type),
218 setAffineFactors(input_shift_factors, num_inputs, 0.0, "input_shift_factors")),
220 setAffineFactors(input_scaling_factors, num_inputs, 1.0, "input_scaling_factors")),
222 setAffineFactors(output_scaling_factors, num_outputs, 1.0, "output_scaling_factors"))
223{
224 _activation_function = activation_function;
226
227 // Check if the number of activation functions matches the number of hidden layers
228 if ((_activation_function.size() != 1) &&
230 mooseError("The number of activation functions should be either one or the same as the number "
231 "of hidden layers");
232
233 if (build_on_construct)
235}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const unsigned int _num_inputs
Number of neurons on the input layer.
const torch::ScalarType _data_type
The data type used in this neural network.
static std::vector< Real > setAffineFactors(const std::vector< Real > &factors, unsigned int expected_size, Real default_value, const std::string &factor_name)
Set affine metadata by either accepting the user values or filling defaults.
std::vector< Real > _input_shift_factors
Affine preprocessing applied to the flattened input.
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< Real > _input_scaling_factors
Multiplicative affine preprocessing applied after shifting the input.
void initializeAffineBuffers()
Initialize the registered affine metadata buffers used by serialization.
const unsigned int _num_outputs
Number of neurons on the output layer.
const std::string _name
Name of the neural network.
const torch::DeviceType _device_type
The device type used for this neural network.
const std::vector< unsigned int > _num_neurons_per_layer
Hidden layer architecture.
std::vector< Real > _output_scaling_factors
Multiplicative scaling applied after the network output is formed.
virtual void constructNeuralNetwork()
Construct the neural network.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
unsigned int size() const
Return the number of active items in the MultiMooseEnum.

◆ LibtorchArtificialNeuralNet() [2/2]

Moose::LibtorchArtificialNeuralNet::LibtorchArtificialNeuralNet ( const Moose::LibtorchArtificialNeuralNet &  nn,
const bool  build_on_construct = true 
)

Copy-construct a feed-forward neural network.

Parameters
nnNeural network to copy.
build_on_constructWhether to rebuild the module structure during the copy.

Definition at line 237 of file LibtorchArtificialNeuralNet.C.

239 : torch::nn::Module(),
240 _name(nn.name()),
246 _data_type(nn.dataType()),
250{
252
253 // We construct the NN architecture
254 if (build_on_construct)
255 {
257 // We fill it up with the current parameter values
258 const auto & from_params = nn.named_parameters();
259 auto to_params = this->named_parameters();
260 for (unsigned int param_i : make_range(from_params.size()))
261 to_params[param_i].value().data() = from_params[param_i].value().data().clone();
262
263 const auto & from_buffers = nn.named_buffers();
264 auto to_buffers = this->named_buffers();
265 for (unsigned int buffer_i : make_range(from_buffers.size()))
266 to_buffers[buffer_i].value().data() = from_buffers[buffer_i].value().data().clone();
267 }
268}
torch::ScalarType dataType() const
Return the data type used by this neural network.
const std::vector< Real > & outputScalingFactors() const
Return the output scaling factors applied after evaluation.
torch::DeviceType deviceType() const
Return the device used by this neural network.
const std::vector< Real > & inputShiftFactors() const
Return the affine input shift factors used before evaluation.
unsigned int numOutputs() const
Return the number of neurons on the output layer.
const std::vector< unsigned int > & numNeuronsPerLayer() const
Return the hidden layer architecture.
unsigned int numInputs() const
Return the number of neurons on the input layer.
const std::vector< Real > & inputScalingFactors() const
Return the affine input scaling factors used before evaluation.
const MultiMooseEnum & activationFunctions() const
Return the multi enum containing the activation functions.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
IntRange< T > make_range(T beg, T end)

Member Function Documentation

◆ activationFunctions()

const MultiMooseEnum & Moose::LibtorchArtificialNeuralNet::activationFunctions ( ) const
inline

Return the multi enum containing the activation functions.

Definition at line 103 of file LibtorchArtificialNeuralNet.h.

103{ return _activation_function; }

◆ addLayer()

void Moose::LibtorchArtificialNeuralNet::addLayer ( const std::string &  layer_name,
const std::unordered_map< std::string, unsigned int > &  parameters 
)
virtual

Add one linear layer to the network.

Parameters
layer_nameName of the layer to add.
parametersSmall parameter map that describes the layer shape.

Definition at line 412 of file LibtorchArtificialNeuralNet.C.

415{
416 auto it = parameters.find("inp_neurons");
417 if (it == parameters.end())
418 ::mooseError("Number of input neurons not found during the construction of "
419 "LibtorchArtificialNeuralNet!");
420 unsigned int inp_neurons = it->second;
421
422 it = parameters.find("out_neurons");
423 if (it == parameters.end())
424 ::mooseError("Number of output neurons not found during the construction of "
425 "LibtorchArtificialNeuralNet!");
426 unsigned int out_neurons = it->second;
427
428 _weights.push_back(register_module(layer_name, torch::nn::Linear(inp_neurons, out_neurons)));
429}
std::vector< torch::nn::Linear > _weights
Submodules that hold linear operations and the corresponding weights and biases (y = W * x + b)

Referenced by constructNeuralNetwork().

◆ constructNeuralNetwork()

void Moose::LibtorchArtificialNeuralNet::constructNeuralNetwork ( )
virtual

Construct the neural network.

Definition at line 346 of file LibtorchArtificialNeuralNet.C.

347{
348 // Adding hidden layers
349 unsigned int inp_neurons = _num_inputs;
350 for (unsigned int i = 0; i < numHiddenLayers(); ++i)
351 {
352 std::unordered_map<std::string, unsigned int> parameters = {
353 {"inp_neurons", inp_neurons}, {"out_neurons", _num_neurons_per_layer[i]}};
354 addLayer("hidden_layer_" + std::to_string(i + 1), parameters);
355
356 // Necessary to retain double precision (and error-free runs)
358 inp_neurons = _num_neurons_per_layer[i];
359 }
360 // Adding output layer
361 std::unordered_map<std::string, unsigned int> parameters = {{"inp_neurons", inp_neurons},
362 {"out_neurons", _num_outputs}};
363 addLayer("output_layer_", parameters);
364 _weights.back()->to(_device_type, _data_type);
365}
virtual void addLayer(const std::string &layer_name, const std::unordered_map< std::string, unsigned int > &parameters)
Add one linear layer to the network.
unsigned int numHiddenLayers() const
Return the number of hidden layers.

Referenced by LibtorchArtificialNeuralNet(), and LibtorchArtificialNeuralNet().

◆ dataType()

torch::ScalarType Moose::LibtorchArtificialNeuralNet::dataType ( ) const
inline

Return the data type used by this neural network.

Definition at line 111 of file LibtorchArtificialNeuralNet.h.

111{ return _data_type; }

◆ determineGain()

Real Moose::LibtorchArtificialNeuralNet::determineGain ( const std::string &  activation)

Map an activation name to the orthogonal-initialization gain we want to use.

Parameters
activationActivation name to look up.

Definition at line 271 of file LibtorchArtificialNeuralNet.C.

272{
273 if (activation == "relu")
274 return std::sqrt(2);
275 if (activation == "tanh")
276 return 5.0 / 3.0;
277
278 return 1.0;
279}

Referenced by initializeNeuralNetwork().

◆ deviceType()

torch::DeviceType Moose::LibtorchArtificialNeuralNet::deviceType ( ) const
inline

Return the device used by this neural network.

Definition at line 107 of file LibtorchArtificialNeuralNet.h.

107{ return _device_type; }

◆ forward()

torch::Tensor Moose::LibtorchArtificialNeuralNet::forward ( const torch::Tensor &  x)
overridevirtual

Run a forward pass through the network.

Parameters
xInput tensor for the evaluation.

Implements Moose::LibtorchNeuralNetBase.

Definition at line 386 of file LibtorchArtificialNeuralNet.C.

387{
388 torch::Tensor output = preprocessInput(x);
389
390 for (unsigned int i = 0; i < _weights.size() - 1; ++i)
391 {
392 std::string activation =
394 if (activation == "relu")
395 output = torch::relu(_weights[i]->forward(output));
396 else if (activation == "sigmoid")
397 output = torch::sigmoid(_weights[i]->forward(output));
398 else if (activation == "tanh")
399 output = torch::tanh(_weights[i]->forward(output));
400 else if (activation == "elu")
401 output = torch::elu(_weights[i]->forward(output));
402 else if (activation == "gelu")
403 output = torch::gelu(_weights[i]->forward(output));
404 else if (activation == "linear")
405 output = _weights[i]->forward(output);
406 }
407
408 return scaleOutput(_weights[_weights.size() - 1]->forward(output));
409}
virtual torch::Tensor forward(const torch::Tensor &x) override
Run a forward pass through the network.
virtual torch::Tensor preprocessInput(const torch::Tensor &x) const
Apply affine preprocessing to the raw input tensor.
virtual torch::Tensor scaleOutput(const torch::Tensor &y) const
Apply the configured output scaling to a network output tensor.

Referenced by forward().

◆ initializeAffineBuffers()

void Moose::LibtorchArtificialNeuralNet::initializeAffineBuffers ( )
protected

Initialize the registered affine metadata buffers used by serialization.

Definition at line 313 of file LibtorchArtificialNeuralNet.C.

314{
315 auto input_shift = _input_shift_factors;
317 _input_shift_tensor = register_buffer(
318 "input_shift", _input_shift_tensor.transpose(0, 1).to(_data_type).to(_device_type));
319
320 auto input_scale = _input_scaling_factors;
322 _input_scale_tensor = register_buffer(
323 "input_scale", _input_scale_tensor.transpose(0, 1).to(_data_type).to(_device_type));
324
325 auto output_scale = _output_scaling_factors;
327 _output_scale_tensor = register_buffer(
328 "output_scale", _output_scale_tensor.transpose(0, 1).to(_data_type).to(_device_type));
329}
torch::Tensor _input_shift_tensor
Registered libtorch buffer holding the affine input shifts.
torch::Tensor _input_scale_tensor
Registered libtorch buffer holding the affine input scaling factors.
torch::Tensor _output_scale_tensor
Registered libtorch buffer holding the output scaling factors.
void vectorToTensor(const std::vector< DataType > &vector, torch::Tensor &tensor, const bool detach=false)
Utility function that converts a standard vector to a torch::Tensor.

Referenced by LibtorchArtificialNeuralNet(), and LibtorchArtificialNeuralNet().

◆ initializeNeuralNetwork()

void Moose::LibtorchArtificialNeuralNet::initializeNeuralNetwork ( c10::optional< at::Generator >  generator = c10::nullopt)
virtual

Initialize the trainable weights and biases.

Parameters
generatorOptional torch random-number generator used for reproducible initialization.

Definition at line 282 of file LibtorchArtificialNeuralNet.C.

283{
284 for (const auto i : make_range(numHiddenLayers()))
285 {
286 const auto & activation =
288 const Real gain = determineGain(activation);
289 Moose::orthogonalInitializeTensor(_weights[i]->weight, gain, generator);
290 torch::nn::init::zeros_(_weights[i]->bias);
291 }
292
293 Moose::orthogonalInitializeTensor(_weights.back()->weight, 1.0, generator);
294 torch::nn::init::zeros_(_weights.back()->bias);
295}
Real determineGain(const std::string &activation)
Map an activation name to the orthogonal-initialization gain we want to use.
void orthogonalInitializeTensor(torch::Tensor &tensor, Real gain=1.0, c10::optional< at::Generator > generator=c10::nullopt)
Fill a tensor with a (semi) orthogonal matrix using the provided generator.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ inputScalingFactors()

const std::vector< Real > & Moose::LibtorchArtificialNeuralNet::inputScalingFactors ( ) const
inline

Return the affine input scaling factors used before evaluation.

Definition at line 119 of file LibtorchArtificialNeuralNet.h.

119{ return _input_scaling_factors; }

◆ inputShiftFactors()

const std::vector< Real > & Moose::LibtorchArtificialNeuralNet::inputShiftFactors ( ) const
inline

Return the affine input shift factors used before evaluation.

Definition at line 115 of file LibtorchArtificialNeuralNet.h.

115{ return _input_shift_factors; }

◆ name()

const std::string & Moose::LibtorchArtificialNeuralNet::name ( ) const
inline

Return the name of the neural network.

Definition at line 83 of file LibtorchArtificialNeuralNet.h.

83{ return _name; }

◆ numHiddenLayers()

unsigned int Moose::LibtorchArtificialNeuralNet::numHiddenLayers ( ) const
inline

Return the number of hidden layers.

Definition at line 95 of file LibtorchArtificialNeuralNet.h.

95{ return _num_neurons_per_layer.size(); }

Referenced by constructNeuralNetwork(), and initializeNeuralNetwork().

◆ numInputs()

unsigned int Moose::LibtorchArtificialNeuralNet::numInputs ( ) const
inline

Return the number of neurons on the input layer.

Definition at line 87 of file LibtorchArtificialNeuralNet.h.

87{ return _num_inputs; }

◆ numNeuronsPerLayer()

const std::vector< unsigned int > & Moose::LibtorchArtificialNeuralNet::numNeuronsPerLayer ( ) const
inline

Return the hidden layer architecture.

Definition at line 99 of file LibtorchArtificialNeuralNet.h.

99{ return _num_neurons_per_layer; }

◆ numOutputs()

unsigned int Moose::LibtorchArtificialNeuralNet::numOutputs ( ) const
inline

Return the number of neurons on the output layer.

Definition at line 91 of file LibtorchArtificialNeuralNet.h.

91{ return _num_outputs; }

◆ outputScalingFactors()

const std::vector< Real > & Moose::LibtorchArtificialNeuralNet::outputScalingFactors ( ) const
inline

Return the output scaling factors applied after evaluation.

Definition at line 123 of file LibtorchArtificialNeuralNet.h.

123{ return _output_scaling_factors; }

◆ preprocessInput()

torch::Tensor Moose::LibtorchArtificialNeuralNet::preprocessInput ( const torch::Tensor &  x) const
protectedvirtual

Apply affine preprocessing to the raw input tensor.

Parameters
xRaw input tensor.

Definition at line 368 of file LibtorchArtificialNeuralNet.C.

369{
370 torch::Tensor input(x);
371 if (_data_type != input.scalar_type())
372 input = input.to(_data_type);
373 if (_device_type != input.device().type())
374 input = input.to(_device_type);
375
376 return (input - _input_shift_tensor) * _input_scale_tensor;
377}

Referenced by forward().

◆ scaleOutput()

torch::Tensor Moose::LibtorchArtificialNeuralNet::scaleOutput ( const torch::Tensor &  y) const
protectedvirtual

Apply the configured output scaling to a network output tensor.

Parameters
yRaw network output tensor.

Definition at line 380 of file LibtorchArtificialNeuralNet.C.

381{
382 return y * _output_scale_tensor;
383}

Referenced by forward().

◆ setAffineFactors()

std::vector< Real > Moose::LibtorchArtificialNeuralNet::setAffineFactors ( const std::vector< Real > &  factors,
unsigned int  expected_size,
Real  default_value,
const std::string &  factor_name 
)
staticprotected

Set affine metadata by either accepting the user values or filling defaults.

Parameters
factorsUser-provided affine factors.
expected_sizeExpected number of entries.
default_valueDefault value used when the vector is empty.
factor_nameName used in error messages.

Definition at line 298 of file LibtorchArtificialNeuralNet.C.

302{
303 const auto resolved_factors =
304 factors.empty() ? std::vector<Real>(expected_size, default_value) : factors;
305
306 if (resolved_factors.size() != expected_size)
307 mooseError("The number of ", factor_name, " entries must match ", expected_size, ".");
308
309 return resolved_factors;
310}

◆ store()

void Moose::LibtorchArtificialNeuralNet::store ( nlohmann::json &  json) const

Store the network architecture in a JSON object for debugging or visualization.

Parameters
jsonJSON object that receives the network architecture.

Definition at line 432 of file LibtorchArtificialNeuralNet.C.

433{
434 const auto & named_params = this->named_parameters();
435 for (const auto & param_i : make_range(named_params.size()))
436 {
437 // We cast the parameters into a 1D vector
438 json[named_params[param_i].key()] = std::vector<Real>(
439 named_params[param_i].value().data_ptr<Real>(),
440 named_params[param_i].value().data_ptr<Real>() + named_params[param_i].value().numel());
441 }
442
443 json["input_shift_factors"] = _input_shift_factors;
444 json["input_scaling_factors"] = _input_scaling_factors;
445 json["output_scaling_factors"] = _output_scaling_factors;
446}

Referenced by Moose::to_json().

◆ synchronizeAffineFactorsFromBuffers()

void Moose::LibtorchArtificialNeuralNet::synchronizeAffineFactorsFromBuffers ( )

Update cached affine metadata vectors from the registered libtorch buffers.

Definition at line 332 of file LibtorchArtificialNeuralNet.C.

333{
334 auto input_shift = _input_shift_tensor.detach().reshape({-1}).to(torch::kCPU).to(torch::kDouble);
336
337 auto input_scale = _input_scale_tensor.detach().reshape({-1}).to(torch::kCPU).to(torch::kDouble);
339
340 auto output_scale =
341 _output_scale_tensor.detach().reshape({-1}).to(torch::kCPU).to(torch::kDouble);
343}
void tensorToVector(torch::Tensor &tensor, std::vector< DataType > &vector)
Utility function that converts a torch::Tensor to a standard vector.

Member Data Documentation

◆ _activation_function

MultiMooseEnum Moose::LibtorchArtificialNeuralNet::_activation_function
protected

Activation functions (either one for all hidden layers or one for every layer separately)

Definition at line 195 of file LibtorchArtificialNeuralNet.h.

Referenced by activationFunctions(), forward(), initializeNeuralNetwork(), and LibtorchArtificialNeuralNet().

◆ _data_type

const torch::ScalarType Moose::LibtorchArtificialNeuralNet::_data_type
protected

The data type used in this neural network.

Definition at line 199 of file LibtorchArtificialNeuralNet.h.

Referenced by constructNeuralNetwork(), dataType(), initializeAffineBuffers(), and preprocessInput().

◆ _device_type

const torch::DeviceType Moose::LibtorchArtificialNeuralNet::_device_type
protected

The device type used for this neural network.

Definition at line 197 of file LibtorchArtificialNeuralNet.h.

Referenced by constructNeuralNetwork(), deviceType(), initializeAffineBuffers(), and preprocessInput().

◆ _input_scale_tensor

torch::Tensor Moose::LibtorchArtificialNeuralNet::_input_scale_tensor
protected

Registered libtorch buffer holding the affine input scaling factors.

Definition at line 209 of file LibtorchArtificialNeuralNet.h.

Referenced by initializeAffineBuffers(), preprocessInput(), and synchronizeAffineFactorsFromBuffers().

◆ _input_scaling_factors

std::vector<Real> Moose::LibtorchArtificialNeuralNet::_input_scaling_factors
protected

Multiplicative affine preprocessing applied after shifting the input.

Definition at line 203 of file LibtorchArtificialNeuralNet.h.

Referenced by initializeAffineBuffers(), inputScalingFactors(), store(), and synchronizeAffineFactorsFromBuffers().

◆ _input_shift_factors

std::vector<Real> Moose::LibtorchArtificialNeuralNet::_input_shift_factors
protected

Affine preprocessing applied to the flattened input.

Definition at line 201 of file LibtorchArtificialNeuralNet.h.

Referenced by initializeAffineBuffers(), inputShiftFactors(), store(), and synchronizeAffineFactorsFromBuffers().

◆ _input_shift_tensor

torch::Tensor Moose::LibtorchArtificialNeuralNet::_input_shift_tensor
protected

Registered libtorch buffer holding the affine input shifts.

Definition at line 207 of file LibtorchArtificialNeuralNet.h.

Referenced by initializeAffineBuffers(), preprocessInput(), and synchronizeAffineFactorsFromBuffers().

◆ _name

const std::string Moose::LibtorchArtificialNeuralNet::_name
protected

Name of the neural network.

Definition at line 183 of file LibtorchArtificialNeuralNet.h.

Referenced by name().

◆ _num_inputs

const unsigned int Moose::LibtorchArtificialNeuralNet::_num_inputs
protected

Number of neurons on the input layer.

Definition at line 188 of file LibtorchArtificialNeuralNet.h.

Referenced by constructNeuralNetwork(), and numInputs().

◆ _num_neurons_per_layer

const std::vector<unsigned int> Moose::LibtorchArtificialNeuralNet::_num_neurons_per_layer
protected

Hidden layer architecture.

Definition at line 192 of file LibtorchArtificialNeuralNet.h.

Referenced by constructNeuralNetwork(), LibtorchArtificialNeuralNet(), numHiddenLayers(), and numNeuronsPerLayer().

◆ _num_outputs

const unsigned int Moose::LibtorchArtificialNeuralNet::_num_outputs
protected

Number of neurons on the output layer.

Definition at line 190 of file LibtorchArtificialNeuralNet.h.

Referenced by constructNeuralNetwork(), and numOutputs().

◆ _output_scale_tensor

torch::Tensor Moose::LibtorchArtificialNeuralNet::_output_scale_tensor
protected

Registered libtorch buffer holding the output scaling factors.

Definition at line 211 of file LibtorchArtificialNeuralNet.h.

Referenced by initializeAffineBuffers(), scaleOutput(), and synchronizeAffineFactorsFromBuffers().

◆ _output_scaling_factors

std::vector<Real> Moose::LibtorchArtificialNeuralNet::_output_scaling_factors
protected

Multiplicative scaling applied after the network output is formed.

Definition at line 205 of file LibtorchArtificialNeuralNet.h.

Referenced by initializeAffineBuffers(), outputScalingFactors(), store(), and synchronizeAffineFactorsFromBuffers().

◆ _weights

std::vector<torch::nn::Linear> Moose::LibtorchArtificialNeuralNet::_weights
protected

Submodules that hold linear operations and the corresponding weights and biases (y = W * x + b)

Definition at line 186 of file LibtorchArtificialNeuralNet.h.

Referenced by addLayer(), constructNeuralNetwork(), forward(), and initializeNeuralNetwork().


The documentation for this class was generated from the following files: