Пример #1
0
 public static Layer createLayer(int neuronsCount, TransferFunctionType transferFunctionType)
 {
     NeuronProperties neuronProperties = new NeuronProperties();
     neuronProperties.SetProperty("transferFunction", transferFunctionType);
     Layer layer = createLayer(neuronsCount, neuronProperties);
     return layer;
 }
        /// <summary>
        /// Creates an instance of Supervised Hebbian Network with specified number
        /// of neurons in input layer, output layer and transfer function
        /// </summary>
        /// <param name="inputNeuronsNum">number of neurons in input layer</param>
        /// <param name="outputNeuronsNum">number of neurons in output layer</param>
        /// <param name="transferFunctionType">transfer function type</param>
        private void CreateNetwork(int inputNeuronsNum, int outputNeuronsNum,
            TransferFunctionType transferFunctionType)
        {
            // init neuron properties
            NeuronProperties neuronProperties = new NeuronProperties();
            neuronProperties.SetProperty("transferFunction", transferFunctionType);
            neuronProperties.SetProperty("transferFunction.slope", 1);
            neuronProperties.SetProperty("transferFunction.yHigh", 1);
            neuronProperties.SetProperty("transferFunction.xHigh", 1);
            neuronProperties.SetProperty("transferFunction.yLow", -1);
            neuronProperties.SetProperty("transferFunction.xLow", -1);

            // set network type code
            this.NetworkType = NeuralNetworkType.SUPERVISED_HEBBIAN_NET;

            // createLayer input layer
            Layer inputLayer = LayerFactory.createLayer(inputNeuronsNum,
                neuronProperties);
            this.AddLayer(inputLayer);

            // createLayer output layer
            Layer outputLayer = LayerFactory.createLayer(outputNeuronsNum,
                neuronProperties);
            this.AddLayer(outputLayer);

            // createLayer full conectivity between input and output layer
            ConnectionFactory.FullConnect(inputLayer, outputLayer);

            // set input and output cells for this network
            NeuralNetworkFactory.SetDefaultIO(this);

            // set appropriate learning rule for this network
            this.LearningRule = new SupervisedHebbianLearning(this);
        }
Пример #3
0
 public NeuronProperties(Type neuronClass, TransferFunctionType transferFunctionType)
 {
     initKeys();
     this.setProperty("inputFunction", typeof(WeightedSum));
     this.setProperty("transferFunction", transferFunctionType.ToString());
     this.setProperty("neuronType", neuronClass);
 }
Пример #4
0
        /// <summary>
        /// Creates perceptron architecture with specified number of neurons in input
        /// and output layer, specified transfer function
        /// </summary>
        /// <param name="inputNeuronsCount">number of neurons in input layer</param>
        /// <param name="outputNeuronsCount">number of neurons in output layer</param>
        /// <param name="transferFunctionType">neuron transfer function type</param>
        private void CreateNetwork(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType)
        {
            // set network type
            this.NetworkType = NeuralNetworkType.PERCEPTRON;

            // init neuron settings for input layer
            NeuronProperties inputNeuronProperties = new NeuronProperties();
            inputNeuronProperties.SetProperty("transferFunction", TransferFunctionType.LINEAR);

            // create input layer
            Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, inputNeuronProperties);
            this.AddLayer(inputLayer);

            NeuronProperties outputNeuronProperties = new NeuronProperties();
            outputNeuronProperties.SetProperty("neuronType", typeof(ThresholdNeuron));
            outputNeuronProperties.SetProperty("thresh", Math.Abs(ThreadSafeRandom.NextDouble()));
            outputNeuronProperties.SetProperty("transferFunction", transferFunctionType);
            // for sigmoid and tanh transfer functions set slope propery
            outputNeuronProperties.SetProperty("transferFunction.slope", 1);

            // createLayer output layer
            Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, outputNeuronProperties);
            this.AddLayer(outputLayer);

            // create full conectivity between input and output layer
            ConnectionFactory.FullConnect(inputLayer, outputLayer);

            // set input and output cells for this network
            NeuralNetworkFactory.SetDefaultIO(this);

            this.LearningRule = new BinaryDeltaRule();
        }
Пример #5
0
        /// <summary>
        /// Creates and returns a new instance of Multi Layer Perceptron </summary>
        /// <param name="layersStr"> space separated number of neurons in layers </param>
        /// <param name="transferFunctionType"> transfer function type for neurons </param>
        /// <returns> instance of Multi Layer Perceptron </returns>
        public static MultiLayerPerceptron createMLPerceptron(string layersStr, TransferFunctionType transferFunctionType)
        {
            List <int>           layerSizes = VectorParser.parseInteger(layersStr);
            MultiLayerPerceptron nnet       = new MultiLayerPerceptron(layerSizes, transferFunctionType);

            return(nnet);
        }
        /// <summary>
        /// Creates an instance of Unsuervised Hebian net with specified number
        /// of neurons in input layer and output layer, and transfer function 
        /// </summary>
        /// <param name="inputNeuronsNum">number of neurons in input layer</param>
        /// <param name="outputNeuronsNum">number of neurons in output layer</param>
        /// <param name="transferFunctionType">transfer function type</param>
        private void CreateNetwork(int inputNeuronsNum, int outputNeuronsNum,
            TransferFunctionType transferFunctionType)
        {
            // init neuron properties
            NeuronProperties neuronProperties = new NeuronProperties();
            //		neuronProperties.setProperty("bias", new Double(-Math
            //				.abs(Math.random() - 0.5))); // Hebbian network cann not work
            // without bias
            neuronProperties.SetProperty("transferFunction", transferFunctionType);
            neuronProperties.SetProperty("transferFunction.slope", 1);

            // set network type code
            this.NetworkType = NeuralNetworkType.UNSUPERVISED_HEBBIAN_NET;

            // createLayer input layer
            Layer inputLayer = LayerFactory.createLayer(inputNeuronsNum,
                neuronProperties);
            this.AddLayer(inputLayer);

            // createLayer output layer
            Layer outputLayer = LayerFactory.createLayer(outputNeuronsNum,
                neuronProperties);
            this.AddLayer(outputLayer);

            // createLayer full conectivity between input and output layer
            ConnectionFactory.FullConnect(inputLayer, outputLayer);

            // set input and output cells for this network
            NeuralNetworkFactory.SetDefaultIO(this);

            // set appropriate learning rule for this network
            this.LearningRule = new UnsupervisedHebbianLearning(this);
            //this.setLearningRule(new OjaLearning(this));
        }
Пример #7
0
 public NeuronProperties(Type neuronClass, TransferFunctionType transferFunctionType)
 {
     //		this.setProperty("weightsFunction", WeightedInput.class);
     //		this.setProperty("summingFunction", Sum.class);
     this.SetProperty("inputFunction", typeof(WeightedSum));
     this.SetProperty("transferFunction", transferFunctionType.getTypeClass());
     this.SetProperty("neuronType", neuronClass);
 }
Пример #8
0
 public NeuronProperties(TransferFunctionType transferFunctionType, bool useBias)
 {
     //		this.setProperty("weightsFunction", WeightedInput.class);
     //		this.setProperty("summingFunction", Sum.class);
     this.SetProperty("inputFunction", typeof(WeightedSum));
     this.SetProperty("transferFunction", transferFunctionType.getTypeClass());
     this.SetProperty("useBias", useBias);
     this.SetProperty("neuronType", typeof(Neuron));
 }
Пример #9
0
        public static Layer createLayer(int neuronsCount, TransferFunctionType transferFunctionType)
        {
            NeuronProperties neuronProperties = new NeuronProperties();

            neuronProperties.setProperty("transferFunction", transferFunctionType.ToString());
            Layer layer = new Layer(neuronsCount, neuronProperties);

            return(layer);
        }
Пример #10
0
        public MultiLayerPerceptron(List <int> neuronsInLayers, TransferFunctionType transferFunctionType)
        {
            // init neuron settings
            NeuronProperties neuronProperties = new NeuronProperties();

            neuronProperties.setProperty("useBias", true);
            neuronProperties.setProperty("transferFunction", transferFunctionType.ToString());

            this.createNetwork(neuronsInLayers, neuronProperties);
        }
Пример #11
0
 public NeuronProperties(TransferFunctionType transferFunctionType, bool useBias)
 {
     initKeys();
     //		this.setProperty("weightsFunction", WeightedInput.class);
     //		this.setProperty("summingFunction", Sum.class);
     this.setProperty("inputFunction", typeof(WeightedSum));
     this.setProperty("transferFunction", transferFunctionType.ToString());
     this.setProperty("useBias", useBias);
     this.setProperty("neuronType", typeof(Neuron));
 }
Пример #12
0
    public static TransferFunctionType getTransferFunctionType()
    {
        TransferFunctionType tft = new TransferFunctionType();

        tft.BOOLEAN_AND     = 0;
        tft.BOOLEAN_OR      = 1;
        tft.BOOLEAN_CIRCUIT = 2;
        tft.NUMERIC_ADD     = 3;
        tft.NUMERIC_MAX     = 4;
        tft.NUMERIC_MIN     = 5;
        return(tft);
    }
Пример #13
0
        public MultiLayerPerceptron(TransferFunctionType transferFunctionType, params int[] neuronsInLayers)
        {
            // init neuron settings
            NeuronProperties neuronProperties = new NeuronProperties();
            neuronProperties.SetProperty("useBias", true);
            neuronProperties.SetProperty("transferFunction", transferFunctionType);
            neuronProperties.SetProperty("inputFunction", typeof(WeightedSum));

            IList<int> neuronsInLayersVector = new List<int>();
            for (int i = 0; i < neuronsInLayers.Length; i++)
                neuronsInLayersVector.Add(neuronsInLayers[i]);

            this.CreateNetwork(neuronsInLayersVector, neuronProperties);
        }
Пример #14
0
        /// <summary>
        /// Creates perceptron architecture with specified number of neurons in input
        /// and output layer, specified transfer function
        /// </summary>
        /// <param name="inputNeuronsCount">
        ///            number of neurons in input layer </param>
        /// <param name="outputNeuronsCount">
        ///            number of neurons in output layer </param>
        /// <param name="transferFunctionType">
        ///            neuron transfer function type </param>
        private void createNetwork(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType)
        {
            // set network type
            this.NetworkType = NeuralNetworkType.PERCEPTRON;

            // init neuron settings for input layer
            NeuronProperties inputNeuronProperties = new NeuronProperties();

            inputNeuronProperties.setProperty("transferFunction", TransferFunctionType.Linear.ToString());

            // create input layer
            Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, inputNeuronProperties);

            this.addLayer(inputLayer);

            NeuronProperties outputNeuronProperties = new NeuronProperties();

            outputNeuronProperties.setProperty("neuronType", typeof(ThresholdNeuron));
            outputNeuronProperties.setProperty("thresh", Math.Abs(new Random(1).NextDouble()));
            outputNeuronProperties.setProperty("transferFunction", transferFunctionType.ToString());
            // for sigmoid and tanh transfer functions set slope propery
            outputNeuronProperties.setProperty("transferFunction.slope", 1);

            // createLayer output layer
            Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, outputNeuronProperties);

            this.addLayer(outputLayer);

            // create full conectivity between input and output layer
            ConnectionFactory.fullConnect(inputLayer, outputLayer);

            // set input and output cells for this network
            NeuralNetworkFactory.DefaultIO = this;

            this.LearningRule = new BinaryDeltaRule();
            // set appropriate learning rule for this network
            //		if (transferFunctionType == TransferFunctionType.STEP) {
            //			this.setLearningRule(new BinaryDeltaRule(this));
            //		} else if (transferFunctionType == TransferFunctionType.SIGMOID) {
            //			this.setLearningRule(new SigmoidDeltaRule(this));
            //		} else if (transferFunctionType == TransferFunctionType.TANH) {
            //			this.setLearningRule(new SigmoidDeltaRule(this));
            //		} else {
            //			this.setLearningRule(new PerceptronLearning(this));
            //		}
        }
Пример #15
0
        public MultiLayerPerceptron(TransferFunctionType transferFunctionType, params int[] neuronsInLayers)
        {
            // init neuron settings
            NeuronProperties neuronProperties = new NeuronProperties();

            neuronProperties.setProperty("useBias", true);
            neuronProperties.setProperty("transferFunction", transferFunctionType.ToString());
            neuronProperties.setProperty("inputFunction", typeof(WeightedSum));


            List <int> neuronsInLayersVector = new List <int>();

            for (int i = 0; i < neuronsInLayers.Length; i++)
            {
                neuronsInLayersVector.Add(Convert.ToInt32(neuronsInLayers[i]));
            }

            this.createNetwork(neuronsInLayersVector, neuronProperties);
        }
Пример #16
0
        /// <summary>
        /// Creates and returns a new instance of Multi Layer Perceptron </summary>
        /// <param name="layersStr"> space separated number of neurons in layers </param>
        /// <param name="transferFunctionType"> transfer function type for neurons </param>
        /// <returns> instance of Multi Layer Perceptron </returns>
        public static MultiLayerPerceptron createMLPerceptron(string layersStr, TransferFunctionType transferFunctionType, Type learningRule, bool useBias, bool connectIO)
        {
            List <int>           layerSizes       = VectorParser.parseInteger(layersStr);
            NeuronProperties     neuronProperties = new NeuronProperties(transferFunctionType, useBias);
            MultiLayerPerceptron nnet             = new MultiLayerPerceptron(layerSizes, neuronProperties);

            // set learning rule - TODO: use reflection here
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            if (learningRule.FullName.Equals(typeof(BackPropagation).FullName))
            {
                nnet.LearningRule = new BackPropagation();
            }
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            else if (learningRule.FullName.Equals(typeof(MomentumBackpropagation).FullName))
            {
                nnet.LearningRule = new MomentumBackpropagation();
            }
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            else if (learningRule.FullName.Equals(typeof(DynamicBackPropagation).FullName))
            {
                nnet.LearningRule = new DynamicBackPropagation();
            }
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            else if (learningRule.FullName.Equals(typeof(ResilientPropagation).FullName))
            {
                nnet.LearningRule = new ResilientPropagation();
            }

            // connect io
            if (connectIO)
            {
                nnet.connectInputsToOutputs();
            }

            return(nnet);
        }
Пример #17
0
 /// <summary>
 /// Creates new Perceptron with specified number of neurons in input and
 /// output layer, and specified transfer function
 /// </summary>
 /// <param name="inputNeuronsCount">
 ///            number of neurons in input layer </param>
 /// <param name="outputNeuronsCount">
 ///            number of neurons in output layer </param>
 /// <param name="transferFunctionType">
 ///            transfer function type </param>
 public Perceptron(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType)
 {
     this.createNetwork(inputNeuronsCount, outputNeuronsCount, transferFunctionType);
 }
Пример #18
0
        /// <summary>
        /// Creates and returns new neural network for image recognition.
        /// Assumes that all of the FractionRgbData objects in the given map have identical
        /// length arrays in them so that the input layer of the neural network can be
        /// created here.
        /// </summary>
        /// <param name="label"> neural network label </param>
        /// <param name="samplingResolution"> sampling resolution (image size) </param>
        /// <param name="imageLabels"> image labels </param>
        /// <param name="layersNeuronsCount"> neuron counts in hidden layers </param>
        /// <param name="transferFunctionType"> type of transfer function to use for neurons in network </param>
        /// <param name="colorMode"> color mode </param>
        /// <returns>  </returns>
        public static NeuralNetwork createNewNeuralNetwork(string label, Dimension samplingResolution, ColorMode colorMode, List <string> imageLabels, List <int?> layersNeuronsCount, TransferFunctionType transferFunctionType)
        {
            int numberOfInputNeurons;

            if ((colorMode == ColorMode.COLOR_RGB) || (colorMode == ColorMode.COLOR_HSL))                             // for full color rgb or hsl
            {
                numberOfInputNeurons = 3 * samplingResolution.Width * samplingResolution.Height;
            }                             // for black n white network
            else
            {
                numberOfInputNeurons = samplingResolution.Width * samplingResolution.Height;
            }

            int numberOfOuputNeurons = imageLabels.Count;

            layersNeuronsCount.Insert(0, numberOfInputNeurons);
            layersNeuronsCount.Add(numberOfOuputNeurons);

            Console.WriteLine("Neuron layer size counts vector = " + layersNeuronsCount);

            NeuralNetwork neuralNetwork = new MultiLayerPerceptron(layersNeuronsCount, transferFunctionType);

            neuralNetwork.Label = label;
            PluginBase imageRecognitionPlugin = new ImageRecognitionPlugin(samplingResolution, colorMode);

            neuralNetwork.addPlugin(imageRecognitionPlugin);

            assignLabelsToOutputNeurons(neuralNetwork, imageLabels);
            neuralNetwork.LearningRule = new MomentumBackpropagation();

            return(neuralNetwork);
        }
Пример #19
0
 /// <summary>
 /// Creates and returns a new instance of Unsupervised Hebbian Network
 /// </summary>
 /// <param name="inputNeuronsCount">number of neurons in input layer</param>
 /// <param name="outputNeuronsCount">number of neurons in output layer</param>
 /// <param name="transferFunctionType">neuron's transfer function type</param>
 /// <returns>instance of Unsupervised Hebbian Network</returns>
 public static UnsupervisedHebbianNetwork CreateUnsupervisedHebbian(int inputNeuronsCount,
     int outputNeuronsCount, TransferFunctionType transferFunctionType)
 {
     UnsupervisedHebbianNetwork nnet = new UnsupervisedHebbianNetwork(inputNeuronsCount,
             outputNeuronsCount, transferFunctionType);
     return nnet;
 }
Пример #20
0
        /// <summary>
        /// Creates and returns a new instance of Unsupervised Hebbian Network </summary>
        /// <param name="inputNeuronsCount"> number of neurons in input layer </param>
        /// <param name="outputNeuronsCount"> number of neurons in output layer </param>
        /// <param name="transferFunctionType"> neuron's transfer function type </param>
        /// <returns> instance of Unsupervised Hebbian Network </returns>
        public static UnsupervisedHebbianNetwork createUnsupervisedHebbian(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType)
        {
            UnsupervisedHebbianNetwork nnet = new UnsupervisedHebbianNetwork(inputNeuronsCount, outputNeuronsCount, transferFunctionType);

            return(nnet);
        }
Пример #21
0
 /// <summary>
 /// Creates  and returns a new instance of Perceptron network
 /// </summary>
 /// <param name="inputNeuronsCount">number of neurons in input layer</param>
 /// <param name="outputNeuronsCount">number of neurons in output layer</param>
 /// <param name="transferFunctionType">type of transfer function to use</param>
 /// <returns>instance of Perceptron network</returns>
 public static Perceptron CreatePerceptron(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType)
 {
     Perceptron nnet = new Perceptron(inputNeuronsCount, outputNeuronsCount, transferFunctionType);
     return nnet;
 }
Пример #22
0
        /// <summary>
        /// Creates  and returns a new instance of Perceptron network
        /// </summary>
        /// <param name="inputNeuronsCount">number of neurons in input layer</param>
        /// <param name="outputNeuronsCount">number of neurons in output layer</param>
        /// <param name="transferFunctionType">type of transfer function to use</param>
        /// <param name="learningRule">learning rule class</param>
        /// <returns>instance of Perceptron network</returns>
        public static Perceptron CreatePerceptron(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType, Type learningRule)
        {
            Perceptron nnet = new Perceptron(inputNeuronsCount, outputNeuronsCount, transferFunctionType);

            if (learningRule.Name.Equals(typeof(PerceptronLearning).Name))
            {
                nnet.LearningRule = new PerceptronLearning();
            }
            else if (learningRule.Name.Equals(typeof(BinaryDeltaRule).Name))
            {
                nnet.LearningRule = new BinaryDeltaRule();
            }

            return nnet;
        }
Пример #23
0
 /// <summary>
 /// Creates and returns a new instance of Multi Layer Perceptron
 /// </summary>
 /// <param name="layersStr">space separated number of neurons in layers</param>
 /// <param name="transferFunctionType">transfer function type for neurons</param>
 /// <returns>instance of Multi Layer Perceptron</returns>
 public static MultiLayerPerceptron CreateMLPerceptron(String layersStr, TransferFunctionType transferFunctionType)
 {
     IList<int> layerSizes = VectorParser.ParseInteger(layersStr);
     MultiLayerPerceptron nnet = new MultiLayerPerceptron(layerSizes,
             transferFunctionType);
     return nnet;
 }
Пример #24
0
        /// <summary>
        /// Creates and returns a new instance of Multi Layer Perceptron
        /// </summary>
        /// <param name="layersStr">space separated number of neurons in layers</param>
        /// <param name="transferFunctionType">transfer function type for neurons</param>
        /// <param name="learningRule">instance of Multi Layer Perceptron</param>
        /// <param name="useBias"></param>
        /// <param name="connectIO"></param>
        /// <returns></returns>
        public static MultiLayerPerceptron CreateMLPerceptron(String layersStr, TransferFunctionType transferFunctionType, Type learningRule, bool useBias, bool connectIO)
        {
            IList<int> layerSizes = VectorParser.ParseInteger(layersStr);
            NeuronProperties neuronProperties = new NeuronProperties(transferFunctionType, useBias);
            MultiLayerPerceptron nnet = new MultiLayerPerceptron(layerSizes, neuronProperties);

            // set learning rule
            if (learningRule.Name.Equals(typeof(BackPropagation).Name))
            {
                nnet.LearningRule = new BackPropagation();
            }
            else if (learningRule.Name.Equals(typeof(MomentumBackpropagation).Name))
            {
                nnet.LearningRule = new MomentumBackpropagation();
            }
            else if (learningRule.Name.Equals(typeof(DynamicBackPropagation).Name))
            {
                nnet.LearningRule = new DynamicBackPropagation();
            }

            // connect io
            if (connectIO)
            {
                nnet.ConnectInputsToOutputs();
            }

            return nnet;
        }
Пример #25
0
 /// <summary>
 /// Creates new Perceptron with specified number of neurons in input and
 /// output layer, and specified transfer function
 /// </summary>
 /// <param name="inputNeuronsCount">number of neurons in input layer</param>
 /// <param name="outputNeuronsCount">number of neurons in output layer</param>
 /// <param name="transferFunctionType">transfer function type</param>
 public Perceptron(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType)
 {
     this.CreateNetwork(inputNeuronsCount, outputNeuronsCount, transferFunctionType);
 }
Пример #26
0
        /// <summary>
        /// Creates  and returns a new instance of Perceptron network </summary>
        /// <param name="inputNeuronsCount"> number of neurons in input layer </param>
        /// <param name="outputNeuronsCount"> number of neurons in output layer </param>
        /// <param name="transferFunctionType"> type of transfer function to use </param>
        /// <returns> instance of Perceptron network </returns>
        public static Perceptron createPerceptron(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType)
        {
            Perceptron nnet = new Perceptron(inputNeuronsCount, outputNeuronsCount, transferFunctionType);

            return(nnet);
        }
Пример #27
0
        public MultiLayerPerceptron(IList<int> neuronsInLayers, TransferFunctionType transferFunctionType)
        {
            // init neuron settings
            NeuronProperties neuronProperties = new NeuronProperties();
            neuronProperties.SetProperty("useBias", true);
            neuronProperties.SetProperty("transferFunction", transferFunctionType);

            this.CreateNetwork(neuronsInLayers, neuronProperties);
        }
Пример #28
0
        /// <summary>
        /// Creates  and returns a new instance of Perceptron network </summary>
        /// <param name="inputNeuronsCount"> number of neurons in input layer </param>
        /// <param name="outputNeuronsCount"> number of neurons in output layer </param>
        /// <param name="transferFunctionType"> type of transfer function to use </param>
        /// <param name="learningRule"> learning rule class </param>
        /// <returns> instance of Perceptron network </returns>
        public static Perceptron createPerceptron(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType, Type learningRule)
        {
            Perceptron nnet = new Perceptron(inputNeuronsCount, outputNeuronsCount, transferFunctionType);

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            if (learningRule.FullName.Equals(typeof(PerceptronLearning).FullName))
            {
                nnet.LearningRule = new PerceptronLearning();
            }
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            else if (learningRule.FullName.Equals(typeof(BinaryDeltaRule).FullName))
            {
                nnet.LearningRule = new BinaryDeltaRule();
            }

            return(nnet);
        }
Пример #29
0
        public void Init(int imgDim, double learnRate, int microBatchsize, int loadBatchsize, string imgFolder, TransferFunctionType funcType, int inputHeight, int outputHeight, int[] hiddenHeights)
        {
            switch(funcType) {
                case TransferFunctionType.Sigmoid:
                TransferFunc = new SigmoidFunction();
                break;

                case TransferFunctionType.HyperbolicTangent:
                TransferFunc = new HyperbolicTangentFunction();
                break;
            }
            ImageDimensions = imgDim;

            ImgLoader = new LazyTrainImgLoader(imgFolder, TransferFunc, true, true, imgDim, loadBatchsize/*, TODO: Support non-digits*/);
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ImgCount"));
            InitNetwork(learnRate, microBatchsize, inputHeight, outputHeight, hiddenHeights);
        }
 /// <summary>
 /// Creates an instance of Supervised Hebbian Network  with specified number
 /// of neurons in input layer and output layer, and transfer function 
 /// </summary>
 /// <param name="inputNeuronsNum">number of neurons in input layer</param>
 /// <param name="outputNeuronsNum">number of neurons in output layer</param>
 /// <param name="transferFunctionType">transfer function type id</param>
 public SupervisedHebbianNetwork(int inputNeuronsNum, int outputNeuronsNum,
     TransferFunctionType transferFunctionType)
 {
     this.CreateNetwork(inputNeuronsNum, outputNeuronsNum,
         transferFunctionType);
 }
Пример #31
0
 public NeuronProperties(WeightsFunctionType weightsFunctionType,
     SummingFunctionType summingFunctionType,
     TransferFunctionType transferFunctionType)
 {
     this.SetProperty("weightsFunction", weightsFunctionType.getTypeClass());
     this.SetProperty("summingFunction", summingFunctionType.getTypeClass());
     this.SetProperty("transferFunction", transferFunctionType.getTypeClass());
     this.SetProperty("neuronType", typeof(Neuron));
 }
Пример #32
0
        /// <summary>
        /// Creates neural network for OCR, which contains OCR plugin. OCR plugin provides interface for character recognition. </summary>
        /// <param name="label"> neural network label </param>
        /// <param name="samplingResolution"> character size in pixels (all characters will be scaled to this dimensions during recognition) </param>
        /// <param name="colorMode"> color mode used fr recognition </param>
        /// <param name="characterLabels"> character labels for output neurons </param>
        /// <param name="layersNeuronsCount"> number of neurons ih hidden layers </param>
        /// <param name="transferFunctionType"> neurons transfer function type </param>
        /// <returns> returns NeuralNetwork with the OCR plugin </returns>
        public static NeuralNetwork createNewNeuralNetwork(string label, Dimension samplingResolution, ColorMode colorMode, List <string> characterLabels, List <int?> layersNeuronsCount, TransferFunctionType transferFunctionType)
        {
            NeuralNetwork neuralNetwork = ImageRecognitionHelper.createNewNeuralNetwork(label, samplingResolution, colorMode, characterLabels, layersNeuronsCount, transferFunctionType);

            neuralNetwork.addPlugin(new OcrPlugin(samplingResolution, colorMode));

            return(neuralNetwork);
        }
Пример #33
0
        /// <summary>
        /// Creates and returns instance of transfer function
        /// </summary>
        /// <param name="tfProperties">
        ///            transfer function properties </param>
        /// <returns> returns transfer function </returns>
        private static TransferFunction createTransferFunction(Properties tfProperties)
        {
            TransferFunction transferFunction = null;

            TransferFunctionType tfType = (TransferFunctionType)Enum.Parse(typeof(TransferFunctionType), (string)tfProperties.getProperty("transferFunction"));

            try
            {
                string      name    = "org.neuroph.core.transfer." + tfType.ToString();
                System.Type tfClass = System.Reflection.TypeInfo.GetType(name);

                System.Reflection.ParameterInfo[] paramTypes = null;

                System.Reflection.ConstructorInfo[] cons = tfClass.GetConstructors();
                for (int i = 0; i < cons.Length; i++)
                {
                    paramTypes = cons[i].GetParameters();

                    // use System.Reflection.ConstructorInfo with one parameter of Properties System.Type
                    if ((paramTypes.Length == 1) && (paramTypes[0].ParameterType == typeof(Properties)))
                    {
                        System.Type[] argTypes = new System.Type[1];
                        argTypes[0] = typeof(Properties);
                        System.Reflection.ConstructorInfo ct = tfClass.GetConstructor(argTypes);

                        object[] argList = new object[1];
                        argList[0]       = tfProperties;
                        transferFunction = (TransferFunction)ct.Invoke(argList);
                        break;
                    }                                             // use System.Reflection.ConstructorInfo without params
                    else if (paramTypes.Length == 0)
                    {
                        transferFunction = (TransferFunction)tfClass.GetConstructor(new System.Type[] { }).Invoke(new object[] { });
                        break;
                    }
                }

                return(transferFunction);
            }
            catch (java.lang.NoSuchMethodException e)
            {
                Console.Error.WriteLine("getConstructor() couldn't find the System.Reflection.ConstructorInfo while creating TransferFunction!");
                System.Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (java.lang.InstantiationException e)
            {
                Console.Error.WriteLine("InstantiationException while creating TransferFunction!");
                System.Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (java.lang.IllegalAccessException e)
            {
                Console.Error.WriteLine("No permission to invoke method while creating TransferFunction!");
                System.Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (InvocationTargetException e)
            {
                Console.Error.WriteLine("Method threw an: " + e.getTargetException() + " while creating TransferFunction!");
                System.Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }

            return(transferFunction);
        }