Exemple #1
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);
        }
Exemple #2
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);
        }