Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i insert an array List as input of my neural network? #123

Open
kunaca opened this issue Jul 14, 2019 · 0 comments
Open

How can i insert an array List as input of my neural network? #123

kunaca opened this issue Jul 14, 2019 · 0 comments

Comments

@kunaca
Copy link

kunaca commented Jul 14, 2019

I have multiples inputs , but most of them are List array and i dont know how can i configure my neural network to accept list array as an input.
Here i have a example XOR(but the inputs are just floats and i cant change to List array):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Encog.Engine.Network.Activation;
using Encog.Neural.Networks;
using Encog.Neural.Networks.Layers;
using Encog.Neural.Networks.Structure;
using Encog.Neural.Networks.Training.Propagation.Back;
using Encog.ML.Data.Basic;
using Encog.ML.Data.Versatile;
using Encog.ML.Data;

namespace Encog
{
class Program
{
static void Main(string[] args)
{
#region Create DataSet
//previsao soma 0.5+0.5 para gerar saida 1.0
double[][] x =
{
new double []{0.1, 0.2},
new double []{0.4, 0.3},
new double []{0.0, 0.0},
new double []{0.15, 0.25}
};

        double[][] y =
        {
            new double []{0.3}, // soma do 1 array
            new double []{0.7},
            new double []{0.0},
            new double []{0.4}
        };
        IMLDataSet dataset = new BasicMLDataSet(x, y); // criar interface dataset

        #endregion

        #region Create neuralNetwork
        BasicNetwork network = new BasicNetwork();
        //Adiconar camadas
        network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 2)); // contador de neuronios - ultimo parametro. temos 2 numeros na 1ª camada de entrada
        //camada oculta, com mais neuronios que a camada principal
        network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 3));
        //camada de saida so com 1 neuronio
        network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 1));
        network.Structure.FinalizeStructure();
        network.Reset();//randomizar os pesos

        #endregion

        #region Create BackPropagation instance(tem outros algoritmos de treinamento sem ser backpropagation)

        // classe para treinamento
        Backpropagation train = new Backpropagation(network, dataset, 0.5, 0.1);
        #endregion

        #region Train the network
        // precisamos de 2 variaveis para treinar ou 

        int epoch = 0;
        do
        {
            train.Iteration();
            //mostrar erro a cada 100 epoch
            if (epoch % 100 == 0)
                Console.WriteLine("Error: {0}   Epoch: {1}", train.Error, epoch);

            epoch++; // sentinela  , contador
        }
        while (epoch < 6000);
        #endregion

        #region Test Network

        //vamos gerar 2 numeros
        for (int i = 0; i <= 10; i++) // 0.1 0.1 ->resultado: 0.2
                                     // 0.2 0.2 ->resultado: 0.4 etc...
        {
            //converter o n para double
            double num = 1.0 / (double)i;

            //entrada para rede neuronal
            double[] d = new double[] { num, num };
            IMLData input = new BasicMLData(d); // so aceita double

            IMLData output = network.Compute(input);
            // resultado
            double[] result = new double[output.Count];
            output.CopyTo(result, 0, output.Count);

            Console.WriteLine("{0} + {1} = {2}", num, num, result[0]);

        }
        Console.ReadKey();    
        #endregion
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant