コード例 #1
0
ファイル: NeuralWrapper.cs プロジェクト: zurus93/SN_Proj1
        public NeuralWrapper(NeuralSettings settings, int inputSize, int outputSize)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _settings        = settings;
            _inputLayerSize  = inputSize;
            _outputLayerSize = outputSize;
        }
コード例 #2
0
        public static NeuralSettings ApplyArguments(string[] arguments)
        {
            var parser = new CommandLineParser(new List <CommandLineOption>
            {
                new CommandLineOption {
                    ShortNotation = 'i', LongNotation = "iterations", ParameterRequired = true
                },
                new CommandLineOption {
                    ShortNotation = 'h', LongNotation = "hidden-layers", ParameterRequired = true
                },
                new CommandLineOption {
                    ShortNotation = 't', LongNotation = "problem-type", ParameterRequired = true
                },
                new CommandLineOption {
                    ShortNotation = 'f', LongNotation = "activation-function", ParameterRequired = true
                },
                new CommandLineOption {
                    ShortNotation = 'b', LongNotation = "bias", ParameterRequired = true
                },
                new CommandLineOption {
                    ShortNotation = 'l', LongNotation = "learning-rate", ParameterRequired = true
                },
                new CommandLineOption {
                    ShortNotation = 'm', LongNotation = "momentum", ParameterRequired = true
                },
                new CommandLineOption {
                    ShortNotation = 'd', LongNotation = "training-data", ParameterRequired = true
                },
                new CommandLineOption {
                    ShortNotation = 'o', LongNotation = "test-data", ParameterRequired = true
                }
            });

            parser.Parse(arguments);
            var settings = new NeuralSettings {
                HiddenLayers = new int[0], HasBias = true
            };

            string value = null;

            if (parser.TryGet("iterations", out value))
            {
                settings.Iterations = int.Parse(value);
            }
            else
            {
                settings.Iterations = 200;
            }

            if (parser.TryGet("momentum", out value))
            {
                settings.Momentum = double.Parse(value);
            }
            else
            {
                settings.Momentum = 0.3;
            }

            if (parser.TryGet("learning-rate", out value))
            {
                settings.LearningRate = double.Parse(value);
            }
            else
            {
                settings.LearningRate = 0.07;
            }

            if (parser.TryGet("bias", out value))
            {
                settings.HasBias = bool.Parse(value);
            }
            else
            {
                settings.HasBias = true;
            }

            if (parser.TryGet("activation-function", out value))
            {
                ActivationFunction tmp;
                Enum.TryParse(value, true, out tmp);
                settings.ActivationFunction = tmp;
            }
            else
            {
                settings.ActivationFunction = ActivationFunction.Unipolar;
            }

            if (parser.TryGet("problem-type", out value))
            {
                ProblemType tmp;
                Enum.TryParse(value, true, out tmp);
                settings.Type = tmp;
            }
            else
            {
                settings.Type = ProblemType.Classification;
            }

            if (parser.TryGet("hidden-layers", out value))
            {
                settings.HiddenLayers = value.Split(',').Select(int.Parse).ToArray();
            }
            else
            {
                settings.HiddenLayers = new int[] { 40, 30 }
            };

            if (parser.TryGet("training-data", out value))
            {
                FILENAME = value;
            }

            if (parser.TryGet("test-data", out value))
            {
                TEST_FILENAME = value;
            }

            return(settings);
        }
    }