Permalink
Browse files

created Unity 5.4.x project

  • Loading branch information...
GandhiGames committed Sep 21, 2016
1 parent ebbbc99 commit 8ef7ec4ed45fa319002e4aef6ec0d75c7be20933
Showing with 83,128 additions and 399 deletions.
  1. +1 −1 {NeuralNet → Neural Network/Assets}/Read Me.txt
  2. +2 −2 {NeuralNet → Neural Network/Assets}/Read Me.txt.meta
  3. +2 −2 {NeuralNet → Neural Network/Assets}/Scenes.meta
  4. BIN Neural Network/Assets/Scenes/Test Scene.unity
  5. +2 −2 {NeuralNet → Neural Network/Assets}/Scenes/Test Scene.unity.meta
  6. +2 −2 {NeuralNet → Neural Network/Assets}/Scripts.meta
  7. +24 −0 Neural Network/Assets/Scripts/ANNTest.cs
  8. 0 {NeuralNet → Neural Network/Assets}/Scripts/ANNTest.cs.meta
  9. 0 {NeuralNet → Neural Network/Assets}/Scripts/Neural Network.meta
  10. +264 −0 Neural Network/Assets/Scripts/Neural Network/NeuralNet.cs
  11. 0 {NeuralNet → Neural Network/Assets}/Scripts/Neural Network/NeuralNet.cs.meta
  12. +28 −0 Neural Network/Assets/Scripts/Neural Network/NeuralNetController.cs
  13. 0 {NeuralNet → Neural Network/Assets}/Scripts/Neural Network/NeuralNetController.cs.meta
  14. +39 −0 Neural Network/Assets/Scripts/Neural Network/Neuron.cs
  15. 0 {NeuralNet → Neural Network/Assets}/Scripts/Neural Network/Neuron.cs.meta
  16. +34 −0 Neural Network/Assets/Scripts/Neural Network/NeuronLayer.cs
  17. 0 {NeuralNet → Neural Network/Assets}/Scripts/Neural Network/NeuronLayer.cs.meta
  18. +60 −0 Neural Network/Assets/Scripts/Utilities.cs
  19. 0 {NeuralNet → Neural Network/Assets}/Scripts/Utilities.cs.meta
  20. BIN Neural Network/Library/AnnotationManager
  21. +1 −0 Neural Network/Library/AssetImportState
  22. BIN Neural Network/Library/AssetServerCacheV3
  23. 0 Neural Network/Library/BuildPlayer.prefs
  24. BIN Neural Network/Library/BuildSettings.asset
  25. BIN Neural Network/Library/CurrentLayout.dwlt
  26. BIN Neural Network/Library/EditorUserBuildSettings.asset
  27. BIN Neural Network/Library/EditorUserSettings.asset
  28. BIN Neural Network/Library/InspectorExpandedItems.asset
  29. +4 −0 Neural Network/Library/LastSceneManagerSetup.txt
  30. +2 −0 Neural Network/Library/LibraryFormatVersion.txt
  31. BIN Neural Network/Library/MonoManager.asset
  32. BIN Neural Network/Library/ProjectSettings.asset
  33. BIN Neural Network/Library/ScriptAssemblies/Assembly-CSharp.dll
  34. BIN Neural Network/Library/ScriptAssemblies/Assembly-CSharp.dll.mdb
  35. BIN Neural Network/Library/ScriptMapper
  36. BIN Neural Network/Library/ShaderCache/3/3fe78fd97c40c4790689e08a39b231f3.bin
  37. BIN Neural Network/Library/ShaderCache/5/58756e6566804f935178a53a3cda76b2.bin
  38. BIN Neural Network/Library/ShaderCache/c/cf55de8b55d6066eeb9acf04283cb607.bin
  39. BIN Neural Network/Library/ShaderCache/e/e34947141480be6a70ac0eeab68cff62.bin
  40. BIN Neural Network/Library/ShaderCache/e/e6042cf20e2d8b7e7ff73cadc8523b7a.bin
  41. BIN Neural Network/Library/ShaderCache/e/ec469ca656d785e256753ea8e3abea51.bin
  42. BIN Neural Network/Library/UnityAssemblies/UnityEditor.dll
  43. BIN Neural Network/Library/UnityAssemblies/UnityEditor.iOS.Extensions.Common.dll
  44. +14 −0 Neural Network/Library/UnityAssemblies/UnityEditor.iOS.Extensions.Common.xml
  45. BIN Neural Network/Library/UnityAssemblies/UnityEditor.iOS.Extensions.Xcode.dll
  46. +8 −0 Neural Network/Library/UnityAssemblies/UnityEditor.iOS.Extensions.Xcode.xml
  47. +22,949 −0 Neural Network/Library/UnityAssemblies/UnityEditor.xml
  48. BIN Neural Network/Library/UnityAssemblies/UnityEngine.Networking.dll
  49. +5,087 −0 Neural Network/Library/UnityAssemblies/UnityEngine.Networking.xml
  50. BIN Neural Network/Library/UnityAssemblies/UnityEngine.UI.dll
  51. +5,951 −0 Neural Network/Library/UnityAssemblies/UnityEngine.UI.xml
  52. BIN Neural Network/Library/UnityAssemblies/UnityEngine.dll
  53. +48,644 −0 Neural Network/Library/UnityAssemblies/UnityEngine.xml
  54. +8 −0 Neural Network/Library/UnityAssemblies/version.txt
  55. BIN Neural Network/Library/assetDatabase3
  56. BIN Neural Network/Library/expandedItems
  57. BIN Neural Network/Library/metadata/00/00000000000000001000000000000000
  58. BIN Neural Network/Library/metadata/00/00000000000000001000000000000000.info
  59. BIN Neural Network/Library/metadata/00/00000000000000002000000000000000
  60. BIN Neural Network/Library/metadata/00/00000000000000002000000000000000.info
  61. BIN Neural Network/Library/metadata/00/00000000000000003000000000000000
  62. BIN Neural Network/Library/metadata/00/00000000000000003000000000000000.info
  63. BIN Neural Network/Library/metadata/00/00000000000000004000000000000000
  64. BIN Neural Network/Library/metadata/00/00000000000000004000000000000000.info
  65. BIN Neural Network/Library/metadata/00/00000000000000004100000000000000
  66. BIN Neural Network/Library/metadata/00/00000000000000004100000000000000.info
  67. BIN Neural Network/Library/metadata/00/00000000000000005000000000000000
  68. BIN Neural Network/Library/metadata/00/00000000000000005000000000000000.info
  69. BIN Neural Network/Library/metadata/00/00000000000000005100000000000000
  70. BIN Neural Network/Library/metadata/00/00000000000000005100000000000000.info
  71. BIN Neural Network/Library/metadata/00/00000000000000006000000000000000
  72. BIN Neural Network/Library/metadata/00/00000000000000006000000000000000.info
  73. BIN Neural Network/Library/metadata/00/00000000000000006100000000000000
  74. BIN Neural Network/Library/metadata/00/00000000000000006100000000000000.info
  75. BIN Neural Network/Library/metadata/00/00000000000000007000000000000000
  76. BIN Neural Network/Library/metadata/00/00000000000000007000000000000000.info
  77. BIN Neural Network/Library/metadata/00/00000000000000007100000000000000
  78. BIN Neural Network/Library/metadata/00/00000000000000007100000000000000.info
  79. BIN Neural Network/Library/metadata/00/00000000000000008000000000000000
  80. BIN Neural Network/Library/metadata/00/00000000000000008000000000000000.info
  81. BIN Neural Network/Library/metadata/00/00000000000000008100000000000000
  82. BIN Neural Network/Library/metadata/00/00000000000000008100000000000000.info
  83. BIN Neural Network/Library/metadata/00/00000000000000009000000000000000
  84. BIN Neural Network/Library/metadata/00/00000000000000009000000000000000.info
  85. BIN Neural Network/Library/metadata/00/0000000000000000a000000000000000
  86. BIN Neural Network/Library/metadata/00/0000000000000000a000000000000000.info
  87. BIN Neural Network/Library/metadata/00/0000000000000000a100000000000000
  88. BIN Neural Network/Library/metadata/00/0000000000000000a100000000000000.info
  89. BIN Neural Network/Library/metadata/00/0000000000000000b000000000000000
  90. BIN Neural Network/Library/metadata/00/0000000000000000b000000000000000.info
  91. BIN Neural Network/Library/metadata/00/0000000000000000c000000000000000
  92. BIN Neural Network/Library/metadata/00/0000000000000000c000000000000000.info
  93. BIN Neural Network/Library/metadata/06/06ce28059757744f8804d7f97b2bcc01
  94. BIN Neural Network/Library/metadata/06/06ce28059757744f8804d7f97b2bcc01.info
  95. BIN Neural Network/Library/metadata/1a/1a57b1e857a344a25b140889187aaba4
  96. BIN Neural Network/Library/metadata/1a/1a57b1e857a344a25b140889187aaba4.info
  97. BIN Neural Network/Library/metadata/1d/1d2837f1113fbef47814149595973d39
  98. BIN Neural Network/Library/metadata/1d/1d2837f1113fbef47814149595973d39.info
  99. BIN Neural Network/Library/metadata/3c/3c0ad459c1534645b5d603b7cc258f97
  100. BIN Neural Network/Library/metadata/3c/3c0ad459c1534645b5d603b7cc258f97.info
  101. BIN Neural Network/Library/metadata/3c/3cfe9f4ba551648c6b7e4e7db3c0f46c
  102. BIN Neural Network/Library/metadata/3c/3cfe9f4ba551648c6b7e4e7db3c0f46c.info
  103. BIN Neural Network/Library/metadata/4a/4a6dfec36027d87498ee41bc3091e591
  104. BIN Neural Network/Library/metadata/4a/4a6dfec36027d87498ee41bc3091e591.info
  105. BIN Neural Network/Library/metadata/5f/5f32cd94baa94578a686d4b9d6b660f7
  106. BIN Neural Network/Library/metadata/5f/5f32cd94baa94578a686d4b9d6b660f7.info
  107. BIN Neural Network/Library/metadata/73/739bbd9f364b4268874f9fd86ab3beef
  108. BIN Neural Network/Library/metadata/73/739bbd9f364b4268874f9fd86ab3beef.info
  109. BIN Neural Network/Library/metadata/75/75e92ddfa78794de3b0b0df268cb2100
  110. BIN Neural Network/Library/metadata/75/75e92ddfa78794de3b0b0df268cb2100.info
  111. BIN Neural Network/Library/metadata/7c/7cbab2be89b54486bbd23a6fe637d30e
  112. BIN Neural Network/Library/metadata/7c/7cbab2be89b54486bbd23a6fe637d30e.info
  113. BIN Neural Network/Library/metadata/7f/7fb63750a15d1fa408313f53f2facf5c
  114. BIN Neural Network/Library/metadata/7f/7fb63750a15d1fa408313f53f2facf5c.info
  115. BIN Neural Network/Library/metadata/80/80a3616ca19596e4da0f10f14d241e9f
  116. BIN Neural Network/Library/metadata/80/80a3616ca19596e4da0f10f14d241e9f.info
  117. BIN Neural Network/Library/metadata/85/852e56802eb941638acbb491814497b0
  118. BIN Neural Network/Library/metadata/85/852e56802eb941638acbb491814497b0.info
  119. BIN Neural Network/Library/metadata/87/870353891bb340e2b2a9c8707e7419ba
  120. BIN Neural Network/Library/metadata/87/870353891bb340e2b2a9c8707e7419ba.info
  121. BIN Neural Network/Library/metadata/8e/8e0cd8ed44d4412cbe0642067abc9e44
  122. BIN Neural Network/Library/metadata/8e/8e0cd8ed44d4412cbe0642067abc9e44.info
  123. BIN Neural Network/Library/metadata/90/900d66d3d3c0644288852dc862ca52d3
  124. BIN Neural Network/Library/metadata/90/900d66d3d3c0644288852dc862ca52d3.info
  125. BIN Neural Network/Library/metadata/97/97decbdab0634cdd991f8d23ddf0dead
  126. BIN Neural Network/Library/metadata/97/97decbdab0634cdd991f8d23ddf0dead.info
  127. BIN Neural Network/Library/metadata/a0/a02a1551a415f4ebd91f2340b9233a66
  128. BIN Neural Network/Library/metadata/a0/a02a1551a415f4ebd91f2340b9233a66.info
  129. BIN Neural Network/Library/metadata/ad/ad9ce433e10c6467db8ba4fb729871d2
  130. BIN Neural Network/Library/metadata/ad/ad9ce433e10c6467db8ba4fb729871d2.info
  131. BIN Neural Network/Library/metadata/ad/adebbd281f1a4ef3a30be7f21937e02f
  132. BIN Neural Network/Library/metadata/ad/adebbd281f1a4ef3a30be7f21937e02f.info
  133. BIN Neural Network/Library/metadata/ec/ec6307e567e3c4346b3930d89cf43c26
  134. BIN Neural Network/Library/metadata/ec/ec6307e567e3c4346b3930d89cf43c26.info
  135. BIN Neural Network/Library/metadata/f5/f5f67c52d1564df4a8936ccd202a3bd8
  136. BIN Neural Network/Library/metadata/f5/f5f67c52d1564df4a8936ccd202a3bd8.info
  137. BIN Neural Network/ProjectSettings/AudioManager.asset
  138. BIN Neural Network/ProjectSettings/ClusterInputManager.asset
  139. BIN Neural Network/ProjectSettings/DynamicsManager.asset
  140. BIN Neural Network/ProjectSettings/EditorBuildSettings.asset
  141. BIN Neural Network/ProjectSettings/EditorSettings.asset
  142. BIN Neural Network/ProjectSettings/GraphicsSettings.asset
  143. BIN Neural Network/ProjectSettings/InputManager.asset
  144. BIN Neural Network/ProjectSettings/NavMeshAreas.asset
  145. BIN Neural Network/ProjectSettings/NetworkManager.asset
  146. BIN Neural Network/ProjectSettings/Physics2DSettings.asset
  147. BIN Neural Network/ProjectSettings/ProjectSettings.asset
  148. +2 −0 Neural Network/ProjectSettings/ProjectVersion.txt
  149. BIN Neural Network/ProjectSettings/QualitySettings.asset
  150. BIN Neural Network/ProjectSettings/TagManager.asset
  151. BIN Neural Network/ProjectSettings/TimeManager.asset
  152. BIN Neural Network/ProjectSettings/UnityAdsSettings.asset
  153. BIN Neural Network/ProjectSettings/UnityConnectSettings.asset
  154. BIN NeuralNet/Scenes/Test Scene.unity
  155. +0 −20 NeuralNet/Scripts/ANNTest.cs
  156. +0 −201 NeuralNet/Scripts/Neural Network/NeuralNet.cs
  157. +0 −30 NeuralNet/Scripts/Neural Network/NeuralNetController.cs
  158. +0 −41 NeuralNet/Scripts/Neural Network/Neuron.cs
  159. +0 −42 NeuralNet/Scripts/Neural Network/NeuronLayer.cs
  160. +0 −56 NeuralNet/Scripts/Utilities.cs
@@ -7,4 +7,4 @@ please email me at robert.wells@gandhigames.co.uk
and I will get back to you as soon as possible.
I have included a simple test scene that creates an ANN, provides it with random input each time-step and prints the output (see ANNTest script).
Not a very useful application but it shows you an ANN could be setup.
Not a very useful application but it shows you how the neural network could be setup.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Binary file not shown.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,24 @@
using UnityEngine;
[RequireComponent (typeof(NeuralNetController), typeof(Utilities))]
public class ANNTest : MonoBehaviour
{
private NeuralNetController _netController;
void Start ()
{
_netController = GetComponent<NeuralNetController> ();
}
void Update ()
{
// Create random input (this wouldn't be random in a real application).
var neuralNetInput = Utilities.instance.RandomInputBuilder(_netController);
// Runs the input throught the network and receives output.
var neuralNetworkOutput = _netController.UpdateNeuralNet(neuralNetInput);
// Print to console.
Utilities.instance.PrettyPrint (neuralNetworkOutput);
}
}
@@ -0,0 +1,264 @@
using System;
using System.Collections.Generic;
/// <summary>
/// Contains a list of layers: represents the whole neural net
/// </summary>
public class NeuralNet
{
private int _numOfInput; //Number of inputs for each neuron
public int numOfInput { get { return _numOfInput; } }
private int _numOfOutput; //Number of outputs of each neuron
public int numOfOutput { get { return _numOfOutput; } }
private int _numHiddenLayers; //Number of hidden layers
public int numOfHiddenLayers { get { return _numHiddenLayers; } }
private int _numOfNeuronsPerHiddenLayer; //Number of neurons per hidden layer
public int numOfNeuronsPerHiddenLayer { get { return _numOfNeuronsPerHiddenLayer; } }
List<NeuronLayer> layers; //List containing layers
public NeuralNet(int numOfInput, int numOfOutput, int numOfHiddenLayers, int numOfNeuronsPerHiddenLayer)
{
_numOfInput = numOfInput;
_numOfOutput = numOfOutput;
_numHiddenLayers = numOfHiddenLayers;
_numOfNeuronsPerHiddenLayer = numOfNeuronsPerHiddenLayer;
layers = new List<NeuronLayer>();
CreateNeuralNet();
}
public void CreateNeuralNet()
{
//If there are hidden layers
if (_numHiddenLayers > 0)
{
//Create first layer
layers.Add(new NeuronLayer(_numOfNeuronsPerHiddenLayer, _numOfInput));
//Create any other subsequent hidden layers
for (int i = 0; i < _numHiddenLayers - 1; i++)
{
//Input from first hidden layer
layers.Add(new NeuronLayer(_numOfNeuronsPerHiddenLayer,
_numOfNeuronsPerHiddenLayer));
}
//Output layer
//Input from subsequent or first hidden layer
layers.Add(new NeuronLayer(_numOfOutput, _numOfNeuronsPerHiddenLayer));
}
else
{ //If no hidden layers
//Input layer
layers.Add(new NeuronLayer(_numOfOutput, _numOfInput));
}
}
//Receives input and returns output: performs caluclations for neural net
public List<float> Update(params float[] inputs)
{
List<float> inputList = new List<float>();
inputList.AddRange(inputs);
//Output from each layer
List<float> outputs = new List<float>();
int weightCount = 0;
//Return empty if not corrent number of inputs
if (inputList.Count != _numOfInput)
{
Console.WriteLine("NeuralNet|Update|Size of inputs list not equal number of inputs");
return outputs;
}
//Each layer
for (int i = 0; i < _numHiddenLayers + 1; i++)
{
if (i > 0)
{
//Clear input and add output from previous layer
inputList.Clear();
inputList.AddRange(outputs);
}
outputs.Clear();
weightCount = 0;
for (int j = 0; j < layers[i].NumNeurons; ++j)
{
float netInput = 0.0f;
int NumInputs = layers[i].Neurons[j].NumInputs;
//Each weight
for (int k = 0; k < NumInputs - 1; ++k)
{
//Sum the weights x inputs
netInput += layers[i].Neurons[j].Weight[k] *
inputList[weightCount++];
}
//Add in the bias
netInput += layers[i].Neurons[j].Weight[NumInputs - 1] *
Utilities.instance.bias;
//Store result in output
outputs.Add(Sigmoid(netInput));
weightCount = 0;
}
}
return outputs;
}
//Gets weights from network
public List<float> GetWeights()
{
//Temporarily store wights
List<float> weights = new List<float>();
//Each layer
for (int i = 0; i < _numHiddenLayers + 1; ++i)
{
//Each neuron
for (int j = 0; j < layers[i].NumNeurons; ++j)
{
//Each weight
for (int k = 0; k < layers[i].Neurons[j].NumInputs; ++k)
{
weights.Add(layers[i].Neurons[j].Weight[k]);
}
}
}
return weights;
}
//Gets number of weights
public int GetNumberOfWeights()
{
int weights = 0;
//Each layer
for (int i = 0; i < _numHiddenLayers + 1; ++i)
{
//Eeach neuron
for (int j = 0; j < layers[i].NumNeurons; ++j)
{
//Each weight
for (int k = 0; k < layers[i].Neurons[j].NumInputs; ++k)
weights++;
}
}
return weights;
}
//Sets weights for network (initially set to random values)
public void SetWeights(ref List<float> weights)
{
//Used to cycle through received weights
int weightCount = 0;
//Each layer
for (int i = 0; i < _numHiddenLayers + 1; ++i)
{
//Each neuron
for (int j = 0; j < layers[i].NumNeurons; ++j)
{
//Each weight
for (int k = 0; k < layers[i].Neurons[j].NumInputs; ++k)
{
layers[i].Neurons[j].Weight[k] = weights[weightCount++];
}
}
}
}
//S shaped output
public float Sigmoid(float netInput)
{
return (float)(1 / (1 + Math.Exp(-netInput / Utilities.instance.activationResponse)));
}
public override bool Equals(object obj)
{
if(!(obj is NeuralNet))
{
return false;
}
if(obj == this)
{
return true;
}
NeuralNet other = (NeuralNet)obj;
return (other._numOfInput == this._numOfInput && other._numOfOutput == this._numOfOutput
&& other._numHiddenLayers == this._numHiddenLayers
&& other._numOfNeuronsPerHiddenLayer == this._numOfNeuronsPerHiddenLayer);
}
public override int GetHashCode()
{
return new HashCodeBuilder().
Add(numOfInput).
Add(numOfOutput).
Add(numOfHiddenLayers).
Add(numOfNeuronsPerHiddenLayer).
GetHashCode();
}
private int GetHash(int value)
{
return 31 + value;
}
}
public sealed class HashCodeBuilder
{
private int hash = 17;
public HashCodeBuilder Add(int value)
{
unchecked
{
hash = hash * 31 + value;
}
return this;
}
public HashCodeBuilder Add(object value)
{
return Add(value != null ? value.GetHashCode() : 0);
}
public HashCodeBuilder Add(float value)
{
return Add(value.GetHashCode());
}
public HashCodeBuilder Add(double value)
{
return Add(value.GetHashCode());
}
public override int GetHashCode()
{
return hash;
}
}
@@ -0,0 +1,28 @@
using UnityEngine;
using System.Collections.Generic;
public class NeuralNetController : MonoBehaviour
{
public int numOfInput;
public int numOfOutput;
public int numOfHiddenLayers;
public int numOfNeuronsPerHiddenLayer;
private NeuralNet _neuralNet;
void Awake()
{
_neuralNet = new NeuralNet(numOfInput, numOfOutput, numOfHiddenLayers, numOfNeuronsPerHiddenLayer);
}
// Update is called once per frame
public List<float> UpdateNeuralNet(params float[] input)
{
if (_neuralNet == null)
return null;
return _neuralNet.Update(input);
}
}
Oops, something went wrong.

0 comments on commit 8ef7ec4

Please sign in to comment.