Пример #1
0
        static void Main(string[] args)
        {
            int[] layout = { 1, 6, 1 };
            ActivationFunction[] activationFunctions = { Sigmoid(), Sigmoid() };
            FFANN ffann = new FFANN(layout, activationFunctions);

            int n = ffann.WeightCount();

            double[] weights = new double[n];
            Random   rnd     = new Random();

            for (int i = 0; i < n; ++i)
            {
                weights[i] = rnd.NextDouble();
            }
            ffann.SetWeights(weights);

            Dataset dataset = new Dataset();

            dataset.Read("dummyData.txt");
            Console.WriteLine(ffann.CalculateError(dataset));

            Backpropagation train = new Backpropagation(ffann, 0.1, dataset);

            train.MaxIteration = 100000;
            train.MaxError     = 1e-6;
            train.Train(1);

            for (int i = 0; i < dataset.Size; ++i)
            {
                Console.WriteLine(ffann.GetOutput(dataset.GetInput(i))[0].ToString("0.0000") + "  " + dataset.GetOutput(i)[0]);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            int[] layout = ReadLayout(args[1]);
            var   activationFunctions = new ActivationFunction[layout.Length - 1];

            for (int i = 0; i < layout.Length - 1; ++i)
            {
                activationFunctions[i] = Sigmoid();
            }

            FFANN ffann = new FFANN(layout, activationFunctions);

            Console.WriteLine(ffann.WeightCount());

            int n = ffann.WeightCount();

            double[] weights = new double[n];
            Random   rnd     = new Random();

            for (int i = 0; i < n; ++i)
            {
                weights[i] = rnd.NextDouble();
            }
            ffann.SetWeights(weights);

            Dataset dataset = new PointDataset(layout[0] / 2);

            dataset.Read(args[0]);
            Console.WriteLine(ffann.CalculateError(dataset));

            Backpropagation train = new Backpropagation(ffann, 0.2, dataset);

            train.MaxIteration = 5000;
            train.MaxError     = 1e-6;

            int batchSize;

            switch (args[2])
            {
            case "1":
                batchSize = dataset.Size;
                break;

            case "2":
                batchSize = 1;
                break;

            default:
                batchSize = 20;
                break;
            }
            train.Train(batchSize);

            Application.Run(new Recognition(ffann));
        }
Пример #3
0
        public Evaluator(string path, FFANN ffann)
        {
            _ffann = ffann;
            _data  = new List <Data>();
            string[] lines = System.IO.File.ReadAllLines(path);

            foreach (var line in lines)
            {
                _data.Add(new Data(line.Trim()));
            }
        }
Пример #4
0
        static EliminationGA()
        {
            Ffann          = new FFANN(new[] { 2, 8, 3 }, new[] { ActivationFunctions.Sigmoid(), ActivationFunctions.Sigmoid() });
            ChromosomeSize = Ffann.WeightCount();

            Evaluator = new Evaluator(DataPath, Ffann);
            Selection = new TournamentSelection(TournamentSize);

            var discreteRecombination = new DiscreteRecombination();
            var simpleArithmetic      = new SimpleArithmeticRecombination();
            var singleArithmetic      = new SingleArithmeticRecombination();

            Crossover = new MixedCrossover(discreteRecombination, simpleArithmetic, singleArithmetic);

            var gausMutation    = new GausMutation(Sigma1, P1);
            var newGausMutation = new NewGausMutation(Sigma2, P2);

            Mutation = new MixedMutation(gausMutation, newGausMutation, P);
        }
Пример #5
0
        public Recognition(FFANN ffann)
        {
            InitializeComponent();

            _ffann = ffann;
        }