Ejemplo n.º 1
0
 /// <summary>Sets the input array and creates and sets the output array.</summary>
 /// <param name="inputArray">The input array to be set.</param>
 /// <param name="inputSkip">The index of the first entry of the input array to be used.</param>
 /// <returns>The created output array.</returns>
 public float[] SetInputGetOutput(float[] inputArray, int inputSkip)
 {
     this.input      = inputArray;
     this.inputSkip  = inputSkip;
     this.outputSkip = 0;
     return(this.output = Backbone.CreateArray <float>(this.Length));
 }
Ejemplo n.º 2
0
 /// <summary>Creates an instance of the <code>Autoencoder</code> class.</summary>
 /// <param name="encoder">The first part of the autoencoder.</param>
 /// <param name="decoder">The second part of the autoencoder.</param>
 /// <param name="codeSize">The lenght of the output of the first part of the autoencoder and the input of the second.</param>
 public Autoencoder(ILayer <TData, float[]> encoder, ILayer <float[], TData> decoder, int codeSize)
 {
     this.encoder   = encoder;
     this.decoder   = decoder;
     this.codeSize  = codeSize;
     this.error     = Backbone.CreateArray <float>(codeSize);
     this.siameseID = new object();
 }
Ejemplo n.º 3
0
        /// <summary>Creates an instance of the <code>FeedForwardNN</code> class.</summary>
        /// <param name="layers">The layers to be included in the network.</param>
        public FeedForwardNN(ICollection <IArraysLayer> layers) : base(layers.ToArray())
        {
            int maxLength = Math.Max(layers.Max(delegate(IArraysLayer layer)
            {
                return(layer.InputSize);
            }), layers.Last().OutputSize);

            this.error1          = Backbone.CreateArray <float>(maxLength);
            this.error2          = Backbone.CreateArray <float>(maxLength);
            this.layersConnected = false;
        }
Ejemplo n.º 4
0
        /// <summary>Either creates a siamese of the given <code>FeedForwardNN</code> instance or clones it.</summary>
        /// <param name="original">The original instance to be created a siamese of or cloned.</param>
        /// <param name="siamese"><code>true</code> if a siamese is to be created, <code>false</code> if a clone is.</param>
        protected FeedForwardNN(FeedForwardNN original, bool siamese) : base(original, siamese)
        {
            int maxLength = Math.Max(original.Layers.Max(delegate(IArraysLayer layer)
            {
                return(layer.InputSize);
            }), (original.LastLayer).OutputSize);

            this.error1          = Backbone.CreateArray <float>(maxLength);
            this.error2          = Backbone.CreateArray <float>(maxLength);
            this.layersConnected = false;
        }
Ejemplo n.º 5
0
 /// <summary>Creates an instance of the <code>NeuronsString</code> class.</summary>
 /// <param name="length">The lenght of the layer.</param>
 /// <param name="createIO">Whether the input array and the output array of the layer are to be created.</param>
 public NeuronsString(int length, bool createIO = false)
 {
     if (createIO)
     {
         this.input      = Backbone.CreateArray <float>(length);
         this.output     = Backbone.CreateArray <float>(length);
         this.inputSkip  = 0;
         this.outputSkip = 0;
     }
     this.length    = length;
     this.siameseID = new object();
 }
Ejemplo n.º 6
0
 /// <summary>Either creates a siamese of the given <code>BiasedConnectionMatrix</code> instance or clones it.</summary>
 /// <param name="original">The original instance to be created a siamese of or cloned.</param>
 /// <param name="siamese"><code>true</code> if a siamese is to be created, <code>false</code> if a clone is.</param>
 protected BiasedConnectionMatrix(BiasedConnectionMatrix original, bool siamese) : base(original, siamese)
 {
     if (siamese)
     {
         this.biases        = original.biases;
         this.biasGradients = original.biasGradients;
         this.biasMomentum  = original.biasMomentum;
     }
     else
     {
         this.biases        = Backbone.CreateArray <float>(original.OutputSize);
         this.biasGradients = Backbone.CreateArray <float>(original.OutputSize);
         this.biasMomentum  = Backbone.CreateArray <float>(original.OutputSize);
     }
 }
Ejemplo n.º 7
0
 /// <summary>Creates an instance of the <code>ConnectionMatrix</code> class.</summary>
 /// <param name="inputSize">The size of the input of the layer.</param>
 /// <param name="outputSize">The size of the output of the layer.</param>
 /// <param name="createIO">Whether the input array and the output array of the layer are to be created.</param>
 public ConnectionMatrix(int inputSize, int outputSize, bool createIO = false)
 {
     if (createIO)
     {
         this.input      = Backbone.CreateArray <float>(inputSize);
         this.output     = Backbone.CreateArray <float>(outputSize);
         this.inputSkip  = 0;
         this.outputSkip = 0;
     }
     this.inputSize  = inputSize;
     this.outputSize = outputSize;
     this.weights    = Backbone.CreateArray <float>(inputSize, outputSize);
     Backbone.RandomizeMatrix(this.weights, inputSize, outputSize, 2.0F / (inputSize + outputSize));
     this.gradients = Backbone.CreateArray <float>(inputSize, outputSize);
     this.momentum  = Backbone.CreateArray <float>(inputSize, outputSize);
     this.siameseID = new object();
 }
Ejemplo n.º 8
0
 /// <summary>Either creates a siamese of the given <code>Autoencoder</code> instance or clones it.</summary>
 /// <param name="original">The original instance to be created a siamese of or cloned.</param>
 /// <param name="siamese"><code>true</code> if a siamese is to be created, <code>false</code> if a clone is.</param>
 protected Autoencoder(Autoencoder <TData, TErrFunc> original, bool siamese)
 {
     if (siamese)
     {
         this.encoder   = original.encoder.CreateSiamese();
         this.decoder   = original.decoder.CreateSiamese();
         this.codeSize  = original.CodeSize;
         this.error     = Backbone.CreateArray <float>(original.CodeSize);
         this.siameseID = original.SiameseID;
     }
     else
     {
         this.encoder   = original.encoder.Clone();
         this.decoder   = original.decoder.Clone();
         this.codeSize  = original.CodeSize;
         this.error     = Backbone.CreateArray <float>(original.CodeSize);
         this.siameseID = new object();
     }
 }
Ejemplo n.º 9
0
 /// <summary>Either creates a siamese of the given <code>ConnectionMatrix</code> instance or clones it.</summary>
 /// <param name="original">The original instance to be created a siamese of or cloned.</param>
 /// <param name="siamese"><code>true</code> if a siamese is to be created, <code>false</code> if a clone is.</param>
 protected ConnectionMatrix(ConnectionMatrix original, bool siamese)
 {
     this.inputSize  = original.InputSize;
     this.outputSize = original.OutputSize;
     if (siamese)
     {
         this.weights   = original.Weights;
         this.gradients = original.Gradients;
         this.momentum  = original.Momentum;
         this.siameseID = original.SiameseID;
     }
     else
     {
         this.weights = Backbone.CreateArray <float>(original.InputSize, original.OutputSize);
         Backbone.RandomizeMatrix(this.weights, original.InputSize, original.OutputSize, 2.0F / (original.InputSize + original.OutputSize));
         this.gradients = Backbone.CreateArray <float>(original.InputSize, original.OutputSize);
         this.momentum  = Backbone.CreateArray <float>(original.InputSize, original.OutputSize);
         this.siameseID = new object();
     }
 }
Ejemplo n.º 10
0
 /// <summary>Creates an instance of the <code>BiasedConnectionMatrix</code> class.</summary>
 /// <param name="inputSize">The length of the input of the layer.</param>
 /// <param name="outputSize">The lenght of the output of the layer.</param>
 /// <param name="createIO">Whether the input array and the output array are to be created.</param>
 public BiasedConnectionMatrix(int inputSize, int outputSize, bool createIO = false) : base(inputSize, outputSize, createIO)
 {
     this.biases        = Backbone.CreateArray <float>(this.OutputSize);
     this.biasGradients = Backbone.CreateArray <float>(this.OutputSize);
     this.biasMomentum  = Backbone.CreateArray <float>(this.OutputSize);
 }
Ejemplo n.º 11
0
 /// <summary>Creates an instance of the <code>DropoutLayer</code> class.</summary>
 /// <param name="length">The lenght of the layer.</param>
 /// <param name="dropChance">The dropout chance of the layer.</param>
 /// <param name="createIO">Whether the input array and the output array of the layer are to be created.</param>
 public DropoutLayer(int length, float dropChance, bool createIO = false) : base(length, createIO)
 {
     this.dropped    = Backbone.CreateArray <bool>(this.Length);
     this.dropChance = dropChance;
 }
Ejemplo n.º 12
0
 /// <summary>Either creates a siamese of the given <code>DropoutLayer</code> instance or clones it.</summary>
 /// <param name="original">The original instance to be created a siamese of or cloned.</param>
 /// <param name="siamese"><code>true</code> if a siamese is to be created, <code>false</code> if a clone is.</param>
 protected DropoutLayer(DropoutLayer original, bool siamese) : base(original, siamese)
 {
     this.dropped    = Backbone.CreateArray <bool>(original.Length);
     this.dropChance = original.DropChance;
 }
Ejemplo n.º 13
0
 /// <summary>Creates an array which can be used as output error.</summary>
 /// <returns>The created array.</returns>
 protected override float[] NewError()
 {
     return(Backbone.CreateArray <float>(this.OutputSize));
 }
Ejemplo n.º 14
0
 /// <summary>Sets the input array of the network and creates the output array.</summary>
 /// <param name="inputArray">The input array to be set.</param>
 /// <param name="inputSkip">The index of the first entry of the output array to be used.</param>
 /// <returns>The created output array.</returns>
 public float[] SetInputGetOutput(float[] inputArray, int inputSkip)
 {
     float[] retVal = Backbone.CreateArray <float>(this.OutputSize);
     this.SetInputAndOutput(inputArray, InputSkip, retVal, 0);
     return(retVal);
 }