예제 #1
0
        /// <summary>
        /// Creates and returns neuron instance according to the given specification in neuronProperties.
        /// </summary>
        /// <param name="neuronProperties">specification of neuron properties</param>
        /// <returns>returns instance of neuron with specified properties</returns>
        public static Neuron CreateNeuron(NeuronProperties neuronProperties)
        {
            InputFunction inputFunction = null;
            Type inputFunctionClass = neuronProperties.InputFunction;

            if (!inputFunctionClass.Equals(" "))
            {
                inputFunction = CreateInputFunction(inputFunctionClass);
            }
            else
            {
                WeightsFunction weightsFunction = CreateWeightsFunction(neuronProperties.WeightsFunction);
                SummingFunction summingFunction = CreateSummingFunction(neuronProperties.SummingFunction);

                inputFunction = new InputFunction(weightsFunction, summingFunction);
            }

            TransferFunction transferFunction = CreateTransferFunction(neuronProperties.GetTransferFunctionProperties());

            Neuron neuron = null;
            Type neuronClass = neuronProperties.NeuronType;

            // use two param constructor to create neuron
            Type[] paramTypes = {
                typeof(InputFunction),
                typeof(TransferFunction) };

            ConstructorInfo con = neuronClass.GetConstructor(paramTypes);

            if (con != null)
            {
                Object[] paramList = new Object[2];
                paramList[0] = inputFunction;
                paramList[1] = transferFunction;

                object o = con.Invoke(paramList);
                neuron = (Neuron)o;
            }

            if (neuron == null)
            {
                neuron = (Neuron)Activator.CreateInstance(neuronClass);
            }

            if (neuronProperties.HasProperty("thresh"))
            {
                ((ThresholdNeuron)neuron).Thresh = ((Double)neuronProperties.GetProperty("thresh"));
            }
            else if (neuronProperties.HasProperty("bias"))
            {
                ((InputOutputNeuron)neuron).Bias = ((Double)neuronProperties.GetProperty("bias"));
            }

            return neuron;
        }
예제 #2
0
        /// <summary>
        /// Creates MultiLayerPerceptron Network architecture - fully connected
        /// feedforward with specified number of neurons in each layer
        /// </summary>
        /// <param name="neuronsInLayers">collection of neuron numbers in getLayersIterator</param>
        /// <param name="neuronProperties">neuron propreties</param>
        protected void CreateNetwork(IList<int> neuronsInLayers, NeuronProperties neuronProperties)
        {
            // set network type
            this.NetworkType = NeuralNetworkType.MULTI_LAYER_PERCEPTRON;

            // create input layer
            NeuronProperties inputNeuronProperties = new NeuronProperties(TransferFunctionType.LINEAR);
            Layer layer = LayerFactory.createLayer(neuronsInLayers[0], inputNeuronProperties);

            bool useBias = true; // use bias neurons by default
            if (neuronProperties.HasProperty("useBias"))
            {
                useBias = (Boolean)neuronProperties.GetProperty("useBias");
            }

            if (useBias)
            {
                layer.AddNeuron(new BiasNeuron());
            }

            this.AddLayer(layer);

            // create layers
            Layer prevLayer = layer;

            //for(Integer neuronsNum : neuronsInLayers)
            for (int layerIdx = 1; layerIdx < neuronsInLayers.Count; layerIdx++)
            {
                int neuronsNum = neuronsInLayers[layerIdx];
                // createLayer layer
                layer = LayerFactory.createLayer(neuronsNum, neuronProperties);

                if (useBias && (layerIdx < (neuronsInLayers.Count - 1)))
                {
                    layer.AddNeuron(new BiasNeuron());
                }

                // add created layer to network
                this.AddLayer(layer);
                // createLayer full connectivity between previous and this layer
                if (prevLayer != null)
                    ConnectionFactory.FullConnect(prevLayer, layer);

                prevLayer = layer;
            }

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

            // set learnng rule
            //this.setLearningRule(new BackPropagation(this));
            this.LearningRule = new MomentumBackpropagation();
            // this.setLearningRule(new DynamicBackPropagation());
        }