Table of Contents

Class RadialBasisFunctionNetwork<T>

Namespace
AiDotNet.NeuralNetworks
Assembly
AiDotNet.dll

Represents a Radial Basis Function Network, which is a type of neural network that uses radial basis functions as activation functions.

public class RadialBasisFunctionNetwork<T> : NeuralNetworkBase<T>, INeuralNetworkModel<T>, INeuralNetwork<T>, IFullModel<T, Tensor<T>, Tensor<T>>, IModel<Tensor<T>, Tensor<T>, ModelMetadata<T>>, IModelSerializer, ICheckpointableModel, IParameterizable<T, Tensor<T>, Tensor<T>>, IFeatureAware, IFeatureImportance<T>, ICloneable<IFullModel<T, Tensor<T>, Tensor<T>>>, IGradientComputable<T, Tensor<T>, Tensor<T>>, IJitCompilable<T>, IInterpretableModel<T>, IInputGradientComputable<T>, IDisposable

Type Parameters

T

The numeric type used for calculations, typically float or double.

Inheritance
RadialBasisFunctionNetwork<T>
Implements
IFullModel<T, Tensor<T>, Tensor<T>>
IModel<Tensor<T>, Tensor<T>, ModelMetadata<T>>
IParameterizable<T, Tensor<T>, Tensor<T>>
ICloneable<IFullModel<T, Tensor<T>, Tensor<T>>>
IGradientComputable<T, Tensor<T>, Tensor<T>>
Inherited Members
Extension Methods

Remarks

A Radial Basis Function Network (RBFN) is a specialized type of neural network that uses radial basis functions as activation functions. Unlike traditional neural networks, RBFNs typically have only one hidden layer with a non-linear radial basis function, followed by a linear output layer. This architecture makes them particularly effective for function approximation, classification, and systems control problems.

For Beginners: A Radial Basis Function Network is a special type of neural network designed to learn patterns differently than standard networks.

Think of it like a weather prediction system:

  • Traditional neural networks might look at many factors and gradually learn weather patterns
  • An RBFN instead has "weather experts" (the radial basis functions) who each specialize in a specific weather pattern
  • When new data comes in, each expert reports how similar the current conditions are to their specialty
  • The network combines these similarity reports to make a prediction

For example, one expert might specialize in "sunny summer days," another in "rainy spring mornings," and so on. When given new weather data, they each report how close it matches their expertise, and the network uses these reports to predict the weather.

RBFNs are particularly good at:

  • Learning complex patterns quickly
  • Function approximation (finding the shape of unknown mathematical functions)
  • Classification problems (determining which category something belongs to)

Constructors

RadialBasisFunctionNetwork(NeuralNetworkArchitecture<T>, IRadialBasisFunction<T>?, ILossFunction<T>?)

Initializes a new instance of the RadialBasisFunctionNetwork<T> class with the specified architecture and radial basis function.

public RadialBasisFunctionNetwork(NeuralNetworkArchitecture<T> architecture, IRadialBasisFunction<T>? radialBasisFunction = null, ILossFunction<T>? lossFunction = null)

Parameters

architecture NeuralNetworkArchitecture<T>

The neural network architecture to use for the RBFN.

radialBasisFunction IRadialBasisFunction<T>

The radial basis function to use. If null, a Gaussian RBF is used by default.

lossFunction ILossFunction<T>

Remarks

This constructor creates a new Radial Basis Function Network with the specified architecture and radial basis function. It extracts necessary parameters from the architecture, such as input shape, output size, and hidden layer size. If the architecture does not explicitly define a hidden layer size, a default of 64 is used. The default radial basis function is Gaussian if none is provided.

For Beginners: This sets up the Radial Basis Function Network with its basic components.

When creating a new RBFN:

  • architecture: Defines the overall structure of the neural network
  • radialBasisFunction: Sets the type of similarity formula the experts use (default is Gaussian)

The constructor figures out:

  • How many inputs the network will accept (_inputSize)
  • How many experts to create (_hiddenSize, default is 64 if not specified)
  • How many outputs the network will produce (_outputSize)

Then it initializes the layers of the network accordingly.

Exceptions

ArgumentException

Thrown when the architecture does not provide valid input shape or output size.

Methods

CreateNewInstance()

Creates a new instance of the radial basis function network with the same configuration.

protected override IFullModel<T, Tensor<T>, Tensor<T>> CreateNewInstance()

Returns

IFullModel<T, Tensor<T>, Tensor<T>>

A new instance of RadialBasisFunctionNetwork<T> with the same configuration as the current instance.

Remarks

This method creates a new radial basis function network that has the same configuration as the current instance. It's used for model persistence, cloning, and transferring the model's configuration to new instances. The new instance will have the same architecture and radial basis function type as the original, but will not share parameter values unless they are explicitly copied after creation.

For Beginners: This method makes a fresh copy of the current model with the same settings.

It's like creating a blueprint copy of your network that can be used to:

  • Save your model's settings
  • Create a new identical model
  • Transfer your model's configuration to another system

This is useful when you want to:

  • Create multiple similar radial basis function networks
  • Save a model's configuration for later use
  • Reset a model while keeping its settings

Note that while the settings are copied, the learned parameters (like the centers of the "experts" and the output weights) are not automatically transferred, so the new instance will need training or parameter copying to match the performance of the original.

DeserializeNetworkSpecificData(BinaryReader)

Deserializes network-specific data for the Radial Basis Function Network.

protected override void DeserializeNetworkSpecificData(BinaryReader reader)

Parameters

reader BinaryReader

The BinaryReader to read the data from.

Remarks

This method reads the specific configuration and state of the RBFN from a binary stream. It reconstructs the network's structural parameters and radial basis function type to match the state of the network when it was serialized.

For Beginners: This method loads the unique settings of your RBFN.

It reads:

  • The number of inputs, hidden neurons, and outputs
  • Information about the specific type of radial basis function used

Loading these details allows you to recreate the exact same network structure that was previously saved. It's like following a recipe to recreate a dish exactly as it was made before.

GetModelMetadata()

Gets metadata about the Radial Basis Function Network model.

public override ModelMetadata<T> GetModelMetadata()

Returns

ModelMetadata<T>

A ModelMetaData object containing information about the model.

Remarks

This method returns metadata that describes the RBFN, including its type, architecture details, and other relevant information. This metadata can be useful for model management, documentation, and versioning.

For Beginners: This provides a summary of your network's setup and characteristics.

The metadata includes:

  • The type of model (Radial Basis Function Network)
  • How many inputs, hidden neurons, and outputs the network has
  • What type of radial basis function is being used
  • A description of the network's structure

This is useful for:

  • Keeping track of different versions of your model
  • Comparing different network configurations
  • Documenting your model's setup for future reference

Think of it like a spec sheet for a car, listing all its important features and capabilities.

InitializeLayers()

Initializes the neural network layers based on the provided architecture or default configuration.

protected override void InitializeLayers()

Remarks

This method sets up the neural network layers for the Radial Basis Function Network. If the architecture provides specific layers, those are used. Otherwise, a default configuration optimized for RBF networks is created. In a typical RBFN, this involves creating a hidden layer with radial basis functions and an output layer with linear activation.

For Beginners: This method sets up the building blocks of the neural network.

When initializing layers:

  • If the user provided specific layers, those are used
  • Otherwise, default layers suitable for RBF networks are created automatically
  • The system checks that any custom layers will work properly with the RBFN

A typical RBFN has just two main layers:

  1. A hidden layer with radial basis functions (our "experts")
  2. An output layer that combines the experts' outputs (usually with a simple linear function)

This simple structure is what makes RBFNs both powerful and efficient for certain types of problems.

Predict(Tensor<T>)

Makes a prediction using the current state of the Radial Basis Function Network.

public override Tensor<T> Predict(Tensor<T> input)

Parameters

input Tensor<T>

The input tensor to make a prediction for.

Returns

Tensor<T>

The predicted output tensor after passing through all layers of the network.

Remarks

This method performs a forward pass through the network, transforming the input data through each layer to produce a final prediction. It includes input validation to ensure the provided tensor matches the expected input shape of the network.

For Beginners: This is how the network makes predictions based on new data.

The prediction process:

  1. Checks if the input data is valid and has the correct shape
  2. Passes the input through each layer of the network
  3. Each layer transforms the data in some way
  4. The final layer produces the network's prediction

Think of it like a factory assembly line:

  • The input data enters the first station (layer)
  • Each station processes the data and passes it to the next
  • The last station outputs the final product (prediction)

Exceptions

ArgumentNullException

Thrown when the input tensor is null.

ArgumentException

Thrown when the input tensor has incorrect dimensions.

SerializeNetworkSpecificData(BinaryWriter)

Serializes network-specific data for the Radial Basis Function Network.

protected override void SerializeNetworkSpecificData(BinaryWriter writer)

Parameters

writer BinaryWriter

The BinaryWriter to write the data to.

Remarks

This method writes the specific configuration and state of the RBFN to a binary stream. It includes the network's structural parameters and the type of radial basis function used. This data is essential for later reconstruction of the network.

For Beginners: This method saves the unique settings of your RBFN.

It writes:

  • The number of inputs, hidden neurons, and outputs
  • Information about the specific type of radial basis function used

Saving these details allows you to recreate the exact same network structure later. It's like writing down a recipe so you can make the same dish again in the future.

Train(Tensor<T>, Tensor<T>)

Trains the Radial Basis Function Network using the provided input and expected output.

public override void Train(Tensor<T> input, Tensor<T> expectedOutput)

Parameters

input Tensor<T>

The input tensor used for training.

expectedOutput Tensor<T>

The expected output tensor for the given input.

Remarks

This method implements the training process for the RBFN. It performs a forward pass, calculates the error between the network's prediction and the expected output, and then backpropagates this error to adjust the network's parameters.

For Beginners: This is how the network learns from examples.

The training process:

  1. Takes an input and its correct answer (expected output)
  2. Makes a prediction using the current network state
  3. Compares the prediction to the correct answer to calculate the error
  4. Uses this error to adjust the network's internal settings (backpropagation)

It's like a student solving math problems:

  • The student (network) tries to solve a problem (make a prediction)
  • They check their answer against the correct one
  • If they're wrong, they figure out why and adjust their approach
  • Over time, they get better at solving similar problems

Exceptions

ArgumentNullException

Thrown when either input or expectedOutput is null.

UpdateParameters(Vector<T>)

Updates the parameters of the radial basis function network layers.

public override void UpdateParameters(Vector<T> parameters)

Parameters

parameters Vector<T>

The vector of parameter updates to apply.

Remarks

This method updates the parameters of each layer in the radial basis function network based on the provided parameter updates. The parameters vector is divided into segments corresponding to each layer's parameter count, and each segment is applied to its respective layer. In an RBFN, these parameters typically include the centers and widths of the RBFs in the hidden layer, and the weights in the output layer.

For Beginners: This method updates how the RBFN makes decisions based on training.

During training:

  • The network learns by adjusting its internal parameters
  • This method applies those adjustments
  • Each layer gets the portion of updates meant specifically for it

For an RBFN, these adjustments might include:

  • Updating what patterns each "expert" specializes in (their centers)
  • Changing how strictly each expert defines "similarity" (their widths)
  • Adjusting how much influence each expert has on the final prediction (output weights)

This process allows the RBFN to improve its performance over time by refining its experts and how it combines their opinions.