Skip to content

Blueteak/Unity-Neural-Network

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
September 19, 2022 01:36
February 19, 2018 02:58

Unity3D Neural Network

This is a C# implementation of a simple feedforward neural network.

This neural network can be used to solve any problems where an input vector of values from 0-1 results in an output vector of values from 0-1.
To use a neural network you must create a Network and a Dataset

private static NeuralNetwork.Network net;
private static List<DataSet> dataSets; 

//Initialize Network and Dataset
void Awake()
{
    int numInputs, numHiddenLayers, numOutputs;
    net = new NeuralNetwork.Network(numInputs, numHiddenLayers, numOutputs);
    dataSets = new List<DataSet>();
}

You can add data points to the dataset using

dataSets.Add(new DataSet(double[] inputs, double[] desiredOutputs));

Train the network with by calling

net.Train(dataSets, MinimumError);

MinimumError is the mimimum desired error for the network (The network will run the same dataset multiple times if it does not have enough datapoints to hit the minimum error with one trial).

Finally, you can test an input

double[] testInput = {0, 1, 0.2, 0.13};
double[] results = net.Compute(testInput);



Sample Scenes

Color picking

This project has a demo scene showing the power of the network by using it to determine which color text is easiest to read on randomly colored backgrounds.
Alt text

Users can select the color easiest to read, and after a few trials ( > 10 ) the Neural Network will show its pick for 'easiest to read color' for the given background.

Jump

Here's another demo scene. Train the network by jumping from platform to platform (Use space). After some collected datasets the network will decide if the player has to jump or not. Image

About

Simple neural network implemented in C# for Unity3D

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages