Search in sources :

Example 6 with TransferFunction

use of org.gitia.froog.transferfunction.TransferFunction in project froog by mroodschild.

the class Backpropagation method derivadaOutputLayers.

/**
 * El input y la Ycalc entran en formato vertical<br>
 * calcula el delta de la salida (-1) * (Yobs - Ycalc) .* f'(z)
 *
 * @param yCalc
 * @param yObs salida
 */
protected void derivadaOutputLayers(SimpleMatrix yCalc, SimpleMatrix yObs) {
    // System.out.println("DERIVADA OUTPUT");
    // vemos que número de capa es
    int lastLayer = net.getLayers().size() - 1;
    // obtenemos su función de transferencia para la derivada
    TransferFunction function = net.getLayers().get(lastLayer).getFunction();
    // obtenemos la salida de la red, el "a" calculado
    // SimpleMatrix yCalc = net.output(input);//mejorar rendimiento
    SimpleMatrix d = function.derivative(yCalc, yObs);
    // ponemos la derivada de la salida en la posición de la salida
    deriv.set(lastLayer, d);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) TransferFunction(org.gitia.froog.transferfunction.TransferFunction)

Example 7 with TransferFunction

use of org.gitia.froog.transferfunction.TransferFunction in project froog by mroodschild.

the class Backpropagation method derivadaHiddenLayers.

/**
 * primero se debe calcular el delta de salida<br>
 * d_i = (W_i+1)^t * d_i+1 .* f'(z_i)
 *
 * @param outputs
 */
protected void derivadaHiddenLayers(List<SimpleMatrix> outputs) {
    // iniciamos en la penúltima capa
    if ((deriv.size() - 2) >= 0) {
        for (int i = deriv.size() - 2; i >= 0; i--) {
            TransferFunction function = net.getLayers().get(i).getFunction();
            SimpleMatrix W = net.getLayers().get(i + 1).getW();
            // en la softmax la derivada sale del gradiente parcial
            // cual es la derivada de la softmax? aqui falta aclarar
            SimpleMatrix d = deriv.get(i + 1);
            SimpleMatrix f_a = function.derivative(outputs.get(i));
            deriv.set(i, W.transpose().mult(d).elementMult(f_a));
        }
    }
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) TransferFunction(org.gitia.froog.transferfunction.TransferFunction)

Example 8 with TransferFunction

use of org.gitia.froog.transferfunction.TransferFunction in project froog by mroodschild.

the class PurelimTest method testToString.

/**
 * Test of toString method, of class Purelim.
 */
@Test
public void testToString() {
    TransferFunction tansig = FunctionFactory.getFunction("purelim");
    String expResult = "purelim";
    String result = tansig.toString();
    assertEquals(expResult, result);
}
Also used : TransferFunction(org.gitia.froog.transferfunction.TransferFunction) Test(org.junit.Test)

Example 9 with TransferFunction

use of org.gitia.froog.transferfunction.TransferFunction in project froog by mroodschild.

the class SoftmaxTest method testOutput2.

/**
 * Test of output method, of class Softmax.
 */
@Test
public void testOutput2() {
    TransferFunction softmax = FunctionFactory.getFunction("softmax");
    SimpleMatrix z = new SimpleMatrix(3, 1, true, 1, 2, 3);
    double[] expResult = { 0.090030573, 0.244728471, 0.665240956 };
    double[] result = softmax.output(z).getMatrix().getData();
    // softmax.output(z).print();
    assertArrayEquals(expResult, result, 0.000000001);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) TransferFunction(org.gitia.froog.transferfunction.TransferFunction) Test(org.junit.Test)

Example 10 with TransferFunction

use of org.gitia.froog.transferfunction.TransferFunction in project froog by mroodschild.

the class TansigTest method testToString.

/**
 * Test of toString method, of class Tansig.
 */
@Test
public void testToString() {
    TransferFunction tansig = FunctionFactory.getFunction("tansig");
    String expResult = "tansig";
    String result = tansig.toString();
    assertEquals(expResult, result);
}
Also used : TransferFunction(org.gitia.froog.transferfunction.TransferFunction) Test(org.junit.Test)

Aggregations

TransferFunction (org.gitia.froog.transferfunction.TransferFunction)13 Test (org.junit.Test)11 SimpleMatrix (org.ejml.simple.SimpleMatrix)10