-
Notifications
You must be signed in to change notification settings - Fork 0
C# Implementation
Documentation of the functionality of each section of the managed C# code. Refer to the source code for the exact implementations of the systems described here.
All activation functions are implemented as classes inheriting from the abstract Activation class. This provides a modular and easily extensible system for building neural networks with various activation functions without any significant architectural modifications. Each activation subclass implements the same API for processing input tensors and delegates its corresponding mathematical operation to the native C++ code.
- Activation - abstract class defining the interface of all activation function classes
- Linear - activation subclass implementing the functionality of a linear activation function - equivalent to not applying any activation function
- Sigmoid - activation subclass implementing the functionality of the sigmoid activation function
- Tanh - activation subclass implementing the functionality of the hyperbolic tangent activation function
- ReLU - activation subclass implementing the functionality of the Rectified Linear Unit activation function
- LeakyReLU - activation subclass implementing the functionality of the Leaky Rectified Linear Unit activation function
- Softmax - activation function subclass implementing the functionality of the softmax activation function
Automatic differentiation is handled via an autograd-style engine similar to that used by PyTorch. All functionality directly relating to automatic differentiation is implemented through the native C++ code. Hence, the C# code only implements a thin wrapper representing the systems involved in the autograd engine.
- Tensor - C# class wrapping the native C++ tensor data structure - represents the fundamental unit of data used by the autograd engine - provides all operations and functions involved in building an autograd graph for automatic differentiation - must be explicitly disposed when going out of scope to prevent memory leaks
Includes standard data structure implementations used to store data across the framework. Primarily used to store and manage data used during the training of neural networks, both during standard supervised training and reinforcement learning (RL). Automatically handle releasing of any native C++ memory when applicable.
- BatchBuffer - data structure for storing input-target pairs for standard supervised training datasets - provides functionality for randomly sampling training batches from the contained dataset
- FIFOBuffer - standard First-In First-Out buffer implementation
- ReplayBuffer - data structure for storing Deep Q-Learning (DQN) training experiences for replay during neural network training - provides functionality for sampling training batches via Prioritized Experience Replay (PER) - stores experiences using an internal SumTree instance
- SumTree - standard sum tree implementation specialized for use with Prioritized Experience Replay (PER) sampling
Includes any C# code required to enable necessary functionality within the .NET Standard 2.1 framework and C#9.0.
- IsExternalInit - enables record data structures and init properties for C#9.0
All cost functions are implemented as classes inheriting from the abstract Cost class. This provides a modular and easily extensible system for using various cost functions during neural network training without any significant architectural changes. Each cost subclass implements the same API for processing prediction and target tensors, and delegates its corresponding mathematical operation to the native C++ code.
- Cost - abstract class defining the interface of all cost function classes
- MSE - cost subclass implementing the functionality of the Mean Squared Error cost function
- Huber - cost subclass implementing the functionality of the pseudo-Huber cost function
- SoftmaxCrossEntropy - cost subclass implementing the functionality of the Softmax Cross-Entropy cost function
Includes various discrete environments for Deep Q-Learning (DQN) training. All DQN environments inherit from the abstract DQNEnvironment class. This provides a modular and easily extensible system for defining custom DQN training environments which are fully compatible with the existing DQN training systems. Each DQN environment implements the same API for training neural networks via DQN training.
- DQNEnvironment - abstract class defining the core interface of all DQN training environment classes
- ISelfPlay - interface for DQN training environments in which the agent trains by playing against itself
- MovementGrid2D - DQN environment subclass representing a 2D grid in which the agent moves towards a target position
- TicTacToe - Self-play DQN environment subclass implementing the complete functionality of the Tic-Tac-Toe game
- Snake - DQN environment subclass implementing the complete functionality of the Snake game
Includes data structures for storing Deep Q-Learning (DQN) training episodes and experiences. Automatically handle releasing of any native C++ memory when applicable.
- Episode - record data structure representing a single DQN training episode - stores the underlying list of experiences - must be explicitly disposed when going out of scope to prevent memory leaks - automatically disposes all contained experiences when disposed
- Experience - record data structure representing a single DQN training experience - must be explicitly disposed when going out of scope to prevent memory leaks
Contains functionality for interoperability between the managed C# code and native C++ code.
- NativeMethods - contains C# imports for all functions exported by the native C++ DLL
- TensorSafeHandle - SafeHandle subclass wrapping tensor handles received from the native C++ code
Includes classes for representing neural network models. Each model is defined as containing a series of neuron layers, each of which is represented by a specialized 'layer' class.
- Model - represents a complete neural network model - contains a sequence of layers which process inputs sequentially - provides functionality for initializing internal layers to process inputs with given formats - must be explicitly disposed when going out of scope to prevent memory leaks - automatically disposes all contained layers when disposed
Neural network layers are implemented as separate classes inheriting from the abstract Layer class. This provides a modular and easily-extensible system for building neural networks with various combinations of internal layers, as well as a more idiomatic approach to defining neural network architectures. Each layer subclass implements the same API for processing input tensors as well as for initializing internal parameters. All layer subclasses contain a bias parameter tensor, activation function subclass instance, and parameter dropout rate, along with layer type-specific parameters.
- Layer - abstract class defining the interface and core parameters of all layer subclasses - must be explicitly disposed when going out of scope to prevent memory leaks - automatically disposes all internal parameter tensors
- Dense - layer subclass representing a fully connected neural network layer - must be explicitly disposed when going out of scope to prevent memory leaks - automatically disposes all internal parameter tensors
- Conv - layer subclass representing a convolutional neural network layer - must be explicitly disposed when going out of scope to prevent memory leaks - automatically disposes all internal parameter tensors
All neural network parameter optimizers are implemented as classes inheriting from the abstract Optimizer class. This provides a modular and easily extensible system for using various optimizer functions during neural network training without any significant architectural changes. Each optimizer subclass implements the same API for updating neural network model parameters and delegates its internal step function to the native C++ code.
- Optimizer - abstract class defining the interface of all optimizer classes
- SGD - optimizer subclass implementing the Stochastic Gradient Descent optimizer functionality
- Adam - optimizer subclass implementing the Adaptive Moment Estimation optimizer functionality
Includes classes for training neural network models using various training algorithms. Each trainer class implements the complete functionality necessary for training a given neural network for a given number of epochs using a given dataset. Trainer classes do not have a shared parent class and are thus not interchangeable within the Neural Network Notions architecture.
- Trainer - provides standard supervised training functionality - allows training of neural network models using a predefined dataset
- DQNTrainer - provides Deep Q-Learning (DQN) training functionality - allows training of neural network agents using discrete DQN environments
Contains various static classes implementing various utility functions used throughout the framework.
- UIUtils - provides various functions for reading user input under various conditions
- NNNLog - provides functionality for writing to the set output target
- MathUtils - provides various mathematical functions for use within the C# section of the framework
- IDManager - provides functions for getting .nnn file ID's of various framework classes and for getting various framework classes based on their .nnn file ID's
- ArrayUtils - provides various functions for manipulating C# arrays
Contains static classes for loading various neural network training datasets.
- MNISTLoader - provides functions for loading the MNIST dataset from files
Contains static classes for saving/loading neural network models and reading/writing the .nnn file format.
- Saver - provides functions for saving neural networks to .nnn files and loading neural network models from .nnn files
- FileUtils - provides functions for reading, writing, and printing the contents of .nnn files