/// <summary> /// Initializes a new instance of the <see cref="SelfOptimizationMapLearning"/> class /// </summary> /// <param name="network">Neural network to train</param> /// <param name="width">Neural network's width</param> /// <param name="height">Neural network's height</param> /// <remarks>The constructor allows to pass network of arbitrary rectangular shape. /// The amount of neurons in the network should be equal to <b>width</b> * <b>height</b>. /// </remarks> public SelfOptimizationMapLearning( DistanceNetwork network, int width, int height ) { // check network size if ( network[0].NeuronsCount != width * height ) throw new ArgumentException( "Invalid network size" ); this._network = network; this._width = width; this._height = height; }
/// <summary> /// Initializes a new instance of the <see cref="SelfOptimizationMapLearning"/> class /// </summary> /// <param name="network">Neural network to train</param> /// <remarks>This constructor supposes that a square network will be passed for training - /// it should be possible to get square root of network's neurons amount.</remarks> public SelfOptimizationMapLearning( DistanceNetwork network ) { // network's dimension was not specified, let's try to guess var neuronsCount = network[0].NeuronsCount; _width = (int) System.Math.Sqrt( neuronsCount ); if ( _width * _width != neuronsCount ) throw new ArgumentException( "Invalid network size" ); // ok, we got it this._network = network; }
/// <summary> /// Initializes a new instance of the <see cref="ElasticNetworkLearning"/> class /// </summary> /// <param name="network">Neural network to train</param> public ElasticNetworkLearning( DistanceNetwork network ) { this._network = network; // precalculate distances array var neurons = network[0].NeuronsCount; var deltaAlpha = System.Math.PI * 2.0 / neurons; var alpha = deltaAlpha; _distance = new double[neurons]; _distance[0] = 0.0; // calculate all distance values for ( var i = 1; i < neurons; i++ ) { var dx = 0.5 * System.Math.Cos( alpha ) - 0.5; var dy = 0.5 * System.Math.Sin( alpha ); _distance[i] = dx * dx + dy * dy; alpha += deltaAlpha; } }