MiniDNN
MiniDNN::Network Class Reference

#include <Network.h>

Public Member Functions

 Network ()
 
 Network (RNG &rng)
 
 ~Network ()
 
void add_layer (Layer *layer)
 
void set_output (Output *output)
 
int num_layers () const
 
std::vector< const Layer * > get_layers () const
 
const Outputget_output () const
 
void set_callback (Callback &callback)
 
void set_default_callback ()
 
void init (const Scalar &mu=Scalar(0), const Scalar &sigma=Scalar(0.01), int seed=-1)
 
std::vector< std::vector< Scalar > > get_parameters () const
 
void set_parameters (const std::vector< std::vector< Scalar > > &param)
 
std::vector< std::vector< Scalar > > get_derivatives () const
 
template<typename TargetType >
void check_gradient (const Matrix &input, const TargetType &target, int npoints, int seed=-1)
 
template<typename DerivedX , typename DerivedY >
bool fit (Optimizer &opt, const Eigen::MatrixBase< DerivedX > &x, const Eigen::MatrixBase< DerivedY > &y, int batch_size, int epoch, int seed=-1)
 
Matrix predict (const Matrix &x)
 

Detailed Description

This class represents a neural network model that typically consists of a number of hidden layers and an output layer. It provides functions for network building, model fitting, and prediction, etc.

Definition at line 28 of file Network.h.

Constructor & Destructor Documentation

◆ Network() [1/2]

MiniDNN::Network::Network ( )
inline

Default constructor that creates an empty neural network

Definition at line 129 of file Network.h.

◆ Network() [2/2]

MiniDNN::Network::Network ( RNG rng)
inline

Constructor with a user-provided random number generator

Parameters
rngA user-provided random number generator object that inherits from the default RNG class.

Definition at line 143 of file Network.h.

◆ ~Network()

MiniDNN::Network::~Network ( )
inline

Destructor that frees the added hidden layers and output layer

Definition at line 154 of file Network.h.

Member Function Documentation

◆ add_layer()

void MiniDNN::Network::add_layer ( Layer layer)
inline

Add a hidden layer to the neural network

Parameters
layerA pointer to a Layer object, typically constructed from layer classes such as FullyConnected and Convolutional. NOTE: the pointer will be handled and freed by the network object, so do not delete it manually.

Definition at line 174 of file Network.h.

◆ set_output()

void MiniDNN::Network::set_output ( Output output)
inline

Set the output layer of the neural network

Parameters
outputA pointer to an Output object, typically constructed from output layer classes such as RegressionMSE and MultiClassEntropy. NOTE: the pointer will be handled and freed by the network object, so do not delete it manually.

Definition at line 187 of file Network.h.

◆ num_layers()

int MiniDNN::Network::num_layers ( ) const
inline

Number of hidden layers in the network

Definition at line 198 of file Network.h.

◆ get_layers()

std::vector<const Layer*> MiniDNN::Network::get_layers ( ) const
inline

Get the list of hidden layers of the network

Definition at line 203 of file Network.h.

◆ get_output()

const Output* MiniDNN::Network::get_output ( ) const
inline

Get the output layer

Definition at line 214 of file Network.h.

◆ set_callback()

void MiniDNN::Network::set_callback ( Callback callback)
inline

Set the callback function that can be called during model fitting

Parameters
callbackA user-provided callback function object that inherits from the default Callback class.

Definition at line 222 of file Network.h.

◆ set_default_callback()

void MiniDNN::Network::set_default_callback ( )
inline

Set the default silent callback function

Definition at line 229 of file Network.h.

◆ init()

void MiniDNN::Network::init ( const Scalar &  mu = Scalar(0),
const Scalar &  sigma = Scalar(0.01),
int  seed = -1 
)
inline

Initialize layer parameters in the network using normal distribution

Parameters
muMean of the normal distribution.
sigmaStandard deviation of the normal distribution.
seedSet the random seed of the RNG if seed > 0, otherwise use the current random state.

Definition at line 242 of file Network.h.

◆ get_parameters()

std::vector< std::vector<Scalar> > MiniDNN::Network::get_parameters ( ) const
inline

Get the serialized layer parameters

Definition at line 259 of file Network.h.

◆ set_parameters()

void MiniDNN::Network::set_parameters ( const std::vector< std::vector< Scalar > > &  param)
inline

Set the layer parameters

Parameters
paramSerialized layer parameters

Definition at line 277 of file Network.h.

◆ get_derivatives()

std::vector< std::vector<Scalar> > MiniDNN::Network::get_derivatives ( ) const
inline

Get the serialized derivatives of layer parameters

Definition at line 292 of file Network.h.

◆ check_gradient()

template<typename TargetType >
void MiniDNN::Network::check_gradient ( const Matrix &  input,
const TargetType &  target,
int  npoints,
int  seed = -1 
)
inline

Debugging tool to check parameter gradients

Definition at line 309 of file Network.h.

◆ fit()

template<typename DerivedX , typename DerivedY >
bool MiniDNN::Network::fit ( Optimizer opt,
const Eigen::MatrixBase< DerivedX > &  x,
const Eigen::MatrixBase< DerivedY > &  y,
int  batch_size,
int  epoch,
int  seed = -1 
)
inline

Fit the model based on the given data

Parameters
optAn object that inherits from the Optimizer class, indicating the optimization algorithm to use.
xThe predictors. Each column is an observation.
yThe response variable. Each column is an observation.
batch_sizeMini-batch size.
epochNumber of epochs of training.
seedSet the random seed of the RNG if seed > 0, otherwise use the current random state.

Definition at line 369 of file Network.h.

◆ predict()

Matrix MiniDNN::Network::predict ( const Matrix &  x)
inline

Use the fitted model to make predictions

Parameters
xThe predictors. Each column is an observation.

Definition at line 425 of file Network.h.


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