public static Layer createLayer(int neuronsCount, Type transferFunctionClass) { NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.setProperty("transferFunction", transferFunctionClass.Name); Layer layer = new Layer(neuronsCount, neuronProperties); return(layer); }
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); }
/// <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); }
/// <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; System.Type inputFunctionClass = neuronProperties.InputFunction; if (inputFunctionClass != null) { inputFunction = createInputFunction(inputFunctionClass); } TransferFunction transferFunction = createTransferFunction(neuronProperties.TransferFunctionProperties); Neuron neuron = null; System.Type neuronClass = neuronProperties.NeuronType; // use two param System.Reflection.ConstructorInfo to create neuron try { object[] paramList = new object[2]; paramList[0] = inputFunction; paramList[1] = transferFunction; neuron = (Neuron)Activator.CreateInstance(neuronClass, paramList); } catch (java.lang.NoSuchMethodException) { // throw new NeurophException("NoSuchMethod while creating Neuron!", e); } catch (java.lang.InstantiationException e) { throw new NeurophException("InstantiationException while creating Neuron!", e); } catch (java.lang.IllegalAccessException e) { throw new NeurophException("IllegalAccessException while creating Neuron!", e); } catch (InvocationTargetException e) { throw new NeurophException("InvocationTargetException while creating Neuron!", e); } if (neuron == null) { // use System.Reflection.ConstructorInfo without params to create neuron try { System.Reflection.ConstructorInfo con = neuronClass.GetConstructor(new System.Type[] { }); neuron = (Neuron)con.Invoke(new object[] { }); } catch (java.lang.IllegalAccessException e) { Console.Error.WriteLine("InstantiationException while creating Neuron!"); System.Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } catch (java.lang.InstantiationException e) { Console.Error.WriteLine("InstantiationException while creating Neuron!"); System.Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } } 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); }
/// <summary> /// Creates and returns instance of Layer with specified number of neurons with specified properties </summary> /// <param name="neuronsCount"> </param> /// <param name="neuronProperties"> </param> /// <returns> </returns> public static Layer createLayer(int neuronsCount, NeuronProperties neuronProperties) { Layer layer = new Layer(neuronsCount, neuronProperties); return(layer); }