Radiate 1.3.7
See the version list below for details.
dotnet add package Radiate --version 1.3.7
NuGet\Install-Package Radiate -Version 1.3.7
<PackageReference Include="Radiate" Version="1.3.7" />
paket add Radiate --version 1.3.7
#r "nuget: Radiate, 1.3.7"
// Install Radiate as a Cake Addin #addin nuget:?package=Radiate&version=1.3.7 // Install Radiate as a Cake Tool #tool nuget:?package=Radiate&version=1.3.7
.NET port of Rust crate radiate.
Algorithms
- Random Forest
- Support Vector Machine
- MultiLayer Perceptron
- Dense Layer
- Dropout Layer
- Flatten Layer
- LSTM Layer
- RNN Layer
- Convolutional Layer
- MaxPooling Layer
- KMeans Clustering
- Evolution Engine
- Evolve any object which implements the Genome base class.
- Implementation of NEAT for evolving NeuralNetworks is included.
- Implementation of evolutionarily generated RandomForest/DecisionTree.
- Evolve any object which implements the Genome base class.
Callbacks
Similar to Keras Callbacks. Hook into the training loop with custom code. Create an object that implements any or all of the following:
- IEpochStartedCallback
- IBatchCompletedCallback
- IEpochCompletedCallback
- ITrainingCompletedCallback
- IGenerationEvolvedCallback
See this for example callbacks or this for a VerboseTrainingCallback
to print training progress to the Console.
Feature Engineering
Functional feature engineering with TensorDataSet
. Transform input data (featurs, targets) with specific options below.
- Batch - Set a batch size to train on.
- Layer - Layer data by n rows.
- Split - Split the data into a training set and testing set. Default is 75% split training, 25% testing.
- Reshape - Reshape the row vector to a shape of (height, width, depth), useful for images.
- Pad - Pad an image Tensor with n zeros.
- Shuffle - Shuffle the rows of the dataset randomly.
- Kernel - Add kernel transform for the features, possible options are RBF, Polynomial, and Linear (None).
- TransformFeatures - Transform the feature data. Options are Normalize, Standardize, OHE (One Hot Encode), and Image (divide data point by 255).
- TransformTargets - Transform the target data. Options same as above.
Model saving and loading
Save an Optimizer
model like
const int numTrees = 10;
const int maxDepth = 10;
const int minSampleSplit = 2;
var (rawFeatures, rawLabels) = await new IrisFlowers().GetDataSet();
var pair = new TensorDataSet(rawFeatures, rawLabels)
.Shuffle()
.Split()
.Batch(rawFeatures.Count);
var forest = new RandomForest(numTrees, new ForestInfo(minSampleSplit, maxDepth));
var optimizer = new Optimizer(forest, pair);
await optimizer.Train<RandomForest>();
// Generate a json serializable object.
var wrappedModel = optimizer.Save();
// The same model can be loaded back in for prediction/additional training.
var newOptimizer = new Optimizer(wrappedModel);
The Optimizer
is not Json serializable, but the OptimizerWrap
is, so the Optimizer
must be converted to a concrete object before serializing.
OptimizerWrap
contains three items:
- TensorDataSet options, the options used to transform the input features/targets. During predicion the Optimizer uses these options to transform the input vector so it matches the trained features in order to get accurate predictions.
- LossFunction, the loss function used during training. If you save a model mid training, the loss function is needed when loading back in the model to continue training.
- ModelWrap, the machine learning model being trained/used for prediction.
The Optimizer
can also be converted to a json string or a memory stream like so:
var optimizer = new Optimizer(forest, TensorDataSet);
var jsonString = ModelWriter.ToJson(optimizer);
var stream = ModelWriter.ToStream(optimizer);
Loading in an Opimizer<T>
from the above options:
var optimizer = ModelReader.FromJson(jsonString);
var optimizer = ModelReader.FromStream(stream);
Make predictions
Because the Optimizer
has TensorDataSet
, it can transform a given float[]
to acceptable input to the model even after saving/loading a model. This makes making predictions as easy as
var vectorToPredict = new float[] { 1f, 2f, 3f, 4f, 5f };
var prediction = trainedOptimizer.Predict(vectorToPredict);
Random
All random numbers are generated by calling RandomGenerator.Next
. This allows for random seeds to be set for model building.
RandomGenerator.Seed = 3;
Will set a random seed for the Optimizer
.
Loss functions
- CrossEntropy
- Difference
- Hinge
- MeanSquaredError
Activation Functions
- Sigmoid
- ReLu
- Tanh
- Linear
- SoftMax
- ExpSigmoid
Gradients
Only applies to MultiLayerPerceptron
and SupportVectorMachine
- Adam
- SGD
Examples
Datasets coming from Radiate.Data which provides easily accessable common machine learning datasets.
Convolutional Neural Network on MNist handwritten digets dataset
<img src="https://camo.githubusercontent.com/01c057a753e92a9bc70b8c45d62b295431851c09cffadf53106fc0aea7e2843f/687474703a2f2f692e7974696d672e636f6d2f76692f3051493378675875422d512f687164656661756c742e6a7067" width="300px">
const int featureLimit = 5000;
const int batchSize = 128;
const int maxEpochs = 10;
var (rawInputs, rawLabels) = await new Mnist(featureLimit).GetDataSet();
var pair = new TensorDataSet(rawInputs, rawLabels)
.Reshape(new Shape(28, 28, 1))
.TransformData(Norm.Image, Norm.OHE)
.Batch(batchSize)
.Split();
var neuralNetwork = new MultiLayerPerceptron()
.AddLayer(new ConvInfo(64, 3))
.AddLayer(new MaxPoolInfo(2))
.AddLayer(new FlattenInfo())
.AddLayer(new DenseInfo(64, Activation.Sigmoid))
.AddLayer(new DenseInfo(pair.OutputCategories, Activation.SoftMax));
var optimizer = new Optimizer(neuralNetwork, pair, new List<ITrainingCallback>
{
new VerboseTrainingCallback(pair, maxEpochs),
new ConfusionMatrixCallback()
});
await optimizer.Train<MultiLayerPerceptron>(epoch => maxEpochs == epoch.Index);
Random Forest on Iris Flowers dataset
<img src="https://upload.wikimedia.org/wikipedia/commons/5/56/Iris_dataset_scatterplot.svg" width="300px">
const int numTrees = 10;
const int maxDepth = 10;
const int minSampleSplit = 2;
var (rawFeatures, rawLabels) = await new IrisFlowers().GetDataSet();
var pair = new TensorDataSet(rawFeatures, rawLabels)
.Shuffle()
.Split()
.Batch(rawFeatures.Count);
var forest = new RandomForest(numTrees, new ForestInfo(minSampleSplit, maxDepth));
var optimizer = new Optimizer(forest, pair, new List<ITrainingCallback>
{
new VerboseTrainingCallback(pair),
new ModelWriterCallback(),
new ConfusionMatrixCallback()
});
await optimizer.Train<RandomForest>();
More
See the examples for how to use the API.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net7.0
- Newtonsoft.Json (>= 13.0.1)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Radiate:
Package | Downloads |
---|---|
Radiate.Extensions
Package Description |
|
Radiate.Data
Package Description |
|
Souk
Package Description |
|
Souk.Radiate
Package Description |
|
Radiate.Genetics
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.6.4 | 127 | 7/8/2024 |
1.6.3 | 105 | 6/6/2024 |
1.6.2 | 94 | 5/8/2024 |
1.6.1 | 114 | 4/27/2024 |
1.6.0 | 129 | 4/27/2024 |
1.5.9 | 125 | 4/27/2024 |
1.5.8 | 119 | 4/27/2024 |
1.5.7 | 123 | 4/22/2024 |
1.5.6 | 131 | 4/21/2024 |
1.5.5 | 135 | 4/11/2024 |
1.5.4 | 113 | 3/24/2024 |
1.5.3 | 159 | 2/27/2024 |
1.5.2 | 130 | 2/26/2024 |
1.5.1 | 138 | 2/26/2024 |
1.5.0 | 140 | 1/31/2024 |
1.4.9 | 130 | 1/25/2024 |
1.4.8 | 108 | 1/24/2024 |
1.4.7 | 100 | 1/24/2024 |
1.4.6 | 160 | 1/23/2024 |
1.4.5 | 209 | 12/17/2023 |
1.4.4 | 203 | 8/10/2023 |
1.4.3 | 193 | 8/6/2023 |
1.4.2 | 190 | 6/5/2023 |
1.4.1 | 254 | 3/14/2023 |
1.4.0 | 251 | 3/8/2023 |
1.3.9 | 265 | 3/2/2023 |
1.3.8 | 275 | 3/1/2023 |
1.3.7 | 278 | 2/27/2023 |
1.3.6 | 270 | 2/15/2023 |
1.3.5 | 342 | 11/29/2022 |
1.3.4 | 325 | 11/29/2022 |
1.3.3 | 426 | 11/28/2022 |
1.3.2 | 331 | 11/28/2022 |
1.3.1 | 345 | 11/28/2022 |
1.3.0 | 325 | 11/27/2022 |
1.2.9 | 349 | 11/27/2022 |
1.2.8 | 496 | 11/26/2022 |
1.2.7 | 340 | 11/26/2022 |
1.2.6 | 442 | 7/25/2022 |
1.2.5 | 436 | 7/25/2022 |
1.2.4 | 443 | 7/25/2022 |
1.2.3 | 440 | 7/25/2022 |
1.2.2 | 433 | 7/25/2022 |
1.2.1 | 453 | 6/22/2022 |
1.2.0 | 422 | 6/21/2022 |
1.1.9 | 460 | 6/21/2022 |
1.1.8 | 477 | 6/21/2022 |
1.1.7 | 447 | 6/20/2022 |
1.1.6 | 490 | 4/14/2022 |
1.1.5 | 452 | 4/14/2022 |
1.1.4 | 455 | 4/14/2022 |
1.1.3 | 456 | 4/14/2022 |
1.1.2 | 425 | 4/14/2022 |
1.1.1 | 454 | 4/14/2022 |
1.1.0 | 462 | 4/14/2022 |
1.0.9 | 478 | 2/14/2022 |
1.0.8 | 458 | 2/14/2022 |
1.0.7 | 449 | 2/14/2022 |
1.0.6 | 477 | 1/20/2022 |
1.0.5 | 314 | 1/15/2022 |
1.0.4 | 301 | 1/15/2022 |
1.0.3 | 520 | 1/12/2022 |
1.0.2 | 487 | 1/12/2022 |
1.0.1 | 360 | 1/12/2022 |
1.0.0 | 455 | 1/12/2022 |