Encog output have values less that 0

100 Views Asked by At

I try to train the network to classify texts. At the entrance I submit a vector only from 0 and 1. Everything works well :) Noticed that Compute returns a vector of negative values like {0.56, -0.09, -0.01}. There can be only one negative value or several or none.

What am I doing wrong?

inputSize = 360

outputSize = 3

        var network = new BasicNetwork();

        network.AddLayer(new BasicLayer(null, true, inputSize));

        network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, inputSize / 6));
        network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, inputSize / 6 / 4));

        network.AddLayer(new BasicLayer(null, false, outputSize));

        network.Structure.FinalizeStructure();
        network.Reset();

Encog version 3.4.0

1

There are 1 best solutions below

0
HelloPleaseHelp On BEST ANSWER

Your network creation itself is fine, although it is recommended that your number of neurons in the hidden layer should be at least half, and you will be likely to see higher accuracy with more than that (Bayramet et al., 2013).

Negative values can often be the cause of an inaccurate network, you can see the mean squared error (MSe) when training the network, a good way to ensure you are getting the lowest error is:

//Train network on data set, parameters (Network, dataset, learning rate, momentum).
IMLTrain learner = new Backpropagation(EncogNetwork, data, lr, mom);
double lastError = double.PositiveInfinity;

//Training loop while error is decreasing by 0.0000001 or more every 1000 iterations.
do
{
     //Set last error as error if the network has trained before.
     if (learner.Error != 0)
     {
         lastError = learner.Error;
     }

     //Do 1000 learning iterations.
     int i = 0;
     while (i < 1000)
     {
          learner.Iteration();
          i++;
     }

} while (lastError - learner.Error > 0.0000001);

double error = learner.Error;

It is likely an error in the ones i.e 1.2 will produce poor results. You should also experiment with learning rate and momentum to help achieve a low error.

When computing it is easy to get negative outputs if you are inputting poor or unrelated values. This is all I can say with the amount of information you have given.