Search code examples
javaencog

Is it possible to specify minimum and maximum weight values in encog?


I tried to specify the minimum and maximum weight constraints of a BasicNetwork, but I simply can't find a way to do it. Is it possible to set these constraints?


Solution

  • You could do something like this, the following code clamps the weights to between -10 and +10. You could place this right into the HelloWorldXOR example. The flat.getWeights is just a 1D array of the weights, so you can modify them as you wish.

        VectorAlgebra va = new VectorAlgebra();
        FlatNetwork flat = network.getFlat();
        do {
            train.iteration();
            va.clampComponents(flat.getWeights(), 5);
            System.out.println("Epoch #" + epoch + " Error:" + train.getError());
            epoch++;
        } while(train.getError() > 0.01);