예제 #1
0
 /// <summary>
 /// Destroy internal network object
 /// </summary>
 public override void Destroy()
 {
     try
     {
         LibsannInvoke.MlpDelete(_network);
     } catch (Exception e) { throw e; }
 }
예제 #2
0
        /// <summary>
        /// Training the network
        /// </summary>
        /// <param name="inputPatterns">Input patterns set</param>
        /// <param name="outputPatterns">Output patterns set</param>
        /// <param name="errorTarget">Target error</param>
        /// <param name="maxEpochs">Maximum number of epochs</param>
        /// <param name="mode">Weights initialization mode</param>
        /// <param name="learningRate">Learning rate</param>
        /// <returns>Returns true if the training is successful, otherwise it returns false</returns>
        public bool Training(
            double[][] inputPatterns,
            double[][] outputPatterns,
            double errorTarget  = 0.01,
            uint maxEpochs      = 100000,
            SynInitMode mode    = SynInitMode.FAN_IN,
            double learningRate = 0.25
            )
        {
            IntPtr p_in;
            IntPtr p_out;

            // Conversion to unmanaged types
            LibsannInvoke.MatrixConversion(inputPatterns, out p_in);
            LibsannInvoke.MatrixConversion(outputPatterns, out p_out);

            _currentError = LibsannInvoke.mAdelineTrainingWithWindrowHoff(
                _network, p_in, p_out, (uint)inputPatterns.Count(), _inputSize, _outputSize, errorTarget, maxEpochs, learningRate, mode);

            if (errorTarget < _currentError)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #3
0
 /// <summary>
 /// Instantiate structure of the network
 /// </summary>
 public override void Instantiate()
 {
     try
     {
         _network = LibsannInvoke.MlpInstantiate(_inputSize, _hiddenLayers, _hiddenUnits, _outputSize, useBias, _transferFunction);
     } catch (Exception e) { throw e; }
 }
예제 #4
0
 /// <summary>
 /// Build internal stats listener
 /// </summary>
 public void BuildStatsListener()
 {
     try
     {
         stats = LibsannInvoke.BuildStatsListener(trainAlg);
     } catch (Exception e) { throw e; }
 }
예제 #5
0
 public void InstantiateBackPropagationAlgorithm(
     double errorTarget  = 0.01,
     uint maxEpochs      = 100000,
     double learningRate = 0.2,
     double beta         = 0.2)
 {
     trainAlg = LibsannInvoke.InstantiateBackPropagationTraininglgorithm(_network, errorTarget, maxEpochs, learningRate, beta);
 }
예제 #6
0
 /// <summary>
 /// Destroy the stats listener
 /// </summary>
 public void DestroyStatsListener()
 {
     try
     {
         LibsannInvoke.DestroyPropStatsListener(trainAlg);
         stats = null;
     } catch (Exception e) { throw e; }
 }
예제 #7
0
 /// <summary>
 /// Set synapses weights
 /// </summary>
 /// <param name="vector">Weights values</param>
 public void SetSynapsesWeights(List <double> vector)
 {
     try
     {
         LibsannInvoke.MlpLoadWeights(_network, vector.ToArray(), vector.Count);
     } catch (Exception e)
     {
         throw e;
     }
 }
예제 #8
0
 public void InstantiateResilientPropagationAlgorithm(
     double errorTarget    = 0.01,
     uint maxEpochs        = 100000,
     double maxUpdateValue = 50.0,
     double minUpdateValue = 0.001,
     double growthFactor   = 1.2,
     double decreaseFactor = 0.5
     )
 {
     trainAlg = LibsannInvoke.InstantiateResilientPropagationTrainingAlgorithm(_network, errorTarget, maxEpochs, maxUpdateValue, minUpdateValue, growthFactor, decreaseFactor);
 }
예제 #9
0
        /// <summary>
        /// Network execution, with 'pattern' inputs. Return the output values
        /// </summary>
        /// <param name="pattern">Input values</param>
        /// <returns>Network output values</returns>
        public virtual double[] Exec(double[] pattern)
        {
            // Set input
            LibsannInvoke.NetSetInput(_network, pattern, pattern.Count());
            // Execution
            IntPtr result = LibsannInvoke.NetExec(_network, _outputSize);

            // Pass output to unmanaged to managed array
            double[] ret = new double[_outputSize];
            Marshal.Copy(result, ret, 0, ret.Count());

            return(ret);
        }
예제 #10
0
 /// <summary>
 /// Get number of synapses of the network
 /// </summary>
 /// <returns>Weights values</returns>
 public double[] GetSynapsesWeights()
 {
     try
     {
         IntPtr   result = LibsannInvoke.MlpGetWeights(_network);
         double[] ret    = new double[LibsannInvoke.MlpGetWeightsNumber(_network)];
         Marshal.Copy(result, ret, 0, ret.Count());
         return(ret);
     } catch (Exception e)
     {
         throw e;
     }
 }
예제 #11
0
        /// <summary>
        /// Get all output values of the current training session
        /// </summary>
        /// <returns>Output values through time</returns>
        public List <double[][]> GetOutputValues()
        {
            try
            {
                if (stats == null)
                {
                    throw new Exception("Stats listener not initialized.");
                }

                int    patterns_count;
                IntPtr outputs = LibsannInvoke.GetPropOutputValues(stats.Value, out patterns_count);

                int cols = Convert.ToInt32(_outputSize);

                List <double[][]> results;
                LibsannInvoke.MatrixConversion(outputs, patterns_count, 2, cols, out results);

                return(results);
            } catch (Exception e) { throw e; }
        }
예제 #12
0
        /// <summary>
        /// Training the network
        /// </summary>
        /// <param name="inputPatterns">Input patterns set</param>
        /// <param name="outputPatterns">Output patterns set</param>
        /// <param name="errorTarget">Target error</param>
        /// <param name="mode">Initialization mode</param>
        /// <returns>Returns true if the training is successful, otherwise it returns false</returns>
        public bool Training(
            double[][] inputPatterns,
            double[][] outputPatterns,
            double errorTarget,
            SynInitMode mode = SynInitMode.NGUYEN_WINDROW
            )
        {
            IntPtr p_in;
            IntPtr p_out;

            try
            {
                if (trainAlg == null)
                {
                    throw new Exception("Training algorithm not initialized.");
                }

                if (stats != null)
                {
                    LibsannInvoke.ResetPropStats(stats.Value);
                }

                // Conversion to unmanaged types
                LibsannInvoke.MatrixConversion(inputPatterns, out p_in);
                LibsannInvoke.MatrixConversion(outputPatterns, out p_out);

                _currentError = LibsannInvoke.MlpTrainingWithPropagation(
                    _network, p_in, p_out, (uint)inputPatterns.Count(), _inputSize, _outputSize, trainAlg, mode);

                if (errorTarget < _currentError)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            } catch (Exception e) { throw e; }
        }
예제 #13
0
        /// <summary>
        /// Get error values through time
        /// </summary>
        /// <returns>Error values</returns>
        public double[] GetErrorValues()
        {
            try
            {
                if (stats == null)
                {
                    throw new Exception("Stats listener not initialized.");
                }

                int    size;
                IntPtr errors = LibsannInvoke.GetPropErrorValue(stats.Value, out size);

                double[] results = new double[size];
                if (errors.ToInt32() != 0)
                {
                    Marshal.Copy(errors, results, 0, results.Count());
                }

                return(results);
            } catch (Exception e)
            {
                throw e;
            }
        }
예제 #14
0
 /// <summary>
 /// Destroy internal network object
 /// </summary>
 public override void Destroy()
 {
     LibsannInvoke.EMlpDelete(_network);
 }
예제 #15
0
 /// <summary>
 /// Instantiate structure of the network
 /// </summary>
 public override void Instantiate()
 {
     _network = LibsannInvoke.EMlpInstantiate(_inputSize, _hiddenLayers, _hiddenUnits, _outputSize, useBias, _transferFunction);
 }
예제 #16
0
 /// <summary>
 /// Destroy internal network object
 /// </summary>
 public override void Destroy()
 {
     LibsannInvoke.mAdelineDelete(_network);
 }
예제 #17
0
 /// <summary>
 /// Instantiate structure of the network
 /// </summary>
 public override void Instantiate()
 {
     _network = LibsannInvoke.mAdelineInstantiate(_inputSize, _outputSize, useBias, _transferFunction);
 }