Search in sources :

Example 6 with Layer

use of org.gitia.froog.layer.Layer in project froog by mroodschild.

the class LayerTest method testOutput_doubleArr.

/**
 * Test of output method, of class Layer.
 */
@Test
public void testOutput_doubleArr() {
    SimpleMatrix w1 = new SimpleMatrix(2, 2, true, 0.1, 0.2, 0.3, 0.4);
    SimpleMatrix b1 = new SimpleMatrix(2, 1, true, 0.5, 0.1);
    double[] a = { 0.2, 0.6 };
    Layer instance = new Layer(w1, b1, "tansig");
    double[] esperado = { 0.5648995528462, 0.3799489622552 };
    assertArrayEquals(esperado, instance.output(a).getMatrix().getData(), 0.0000001);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Layer(org.gitia.froog.layer.Layer) Test(org.junit.Test)

Example 7 with Layer

use of org.gitia.froog.layer.Layer in project froog by mroodschild.

the class LayerTest method testOutput_SimpleMatrix.

/**
 * Test of output method, of class Layer.
 */
@Test
public void testOutput_SimpleMatrix() {
    SimpleMatrix w1 = new SimpleMatrix(2, 2, true, 0.1, 0.2, 0.3, 0.4);
    SimpleMatrix b1 = new SimpleMatrix(2, 1, true, 0.5, 0.1);
    SimpleMatrix a = new SimpleMatrix(2, 1, true, 0.2, 0.6);
    Layer instance = new Layer(w1, b1, "tansig");
    double[] esperado = { 0.5648995528462, 0.3799489622552 };
    assertArrayEquals(esperado, instance.output(a).getMatrix().getData(), 0.0000001);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Layer(org.gitia.froog.layer.Layer) Test(org.junit.Test)

Example 8 with Layer

use of org.gitia.froog.layer.Layer in project froog by mroodschild.

the class LayerTest method testOutput_SimpleMatrix.

/**
 * Test of output method, of class Layer.
 */
@Test
public void testOutput_SimpleMatrix() {
    System.out.println("output");
    SimpleMatrix w = new SimpleMatrix(2, 3, true, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
    SimpleMatrix b = new SimpleMatrix(2, 1, true, 0.1, 0.2);
    SimpleMatrix input = new SimpleMatrix(3, 1, true, 0.2, 0.4, 0.6);
    Layer instance = new Layer(w, b, TransferFunction.LOGSIG);
    double[] expResult = { 0.5938731029341, 0.6984652160025 };
    double[] result = instance.output(input).getMatrix().getData();
    instance.output(input).print();
    assertArrayEquals(expResult, result, 0.0000000000001);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Layer(org.gitia.froog.layer.Layer) Test(org.junit.Test)

Example 9 with Layer

use of org.gitia.froog.layer.Layer in project froog by mroodschild.

the class LayerTest method testOutput_SimpleMatrixAll.

/**
 * Test of output method, of class Layer.
 */
@Test
public void testOutput_SimpleMatrixAll() {
    System.out.println("output");
    SimpleMatrix w = new SimpleMatrix(2, 3, true, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
    SimpleMatrix b = new SimpleMatrix(2, 1, true, 0.1, 0.2);
    SimpleMatrix input = new SimpleMatrix(3, 2, false, 0.2, 0.4, 0.6, 0.2, 0.4, 0.6);
    Layer instance = new Layer(w, b, TransferFunction.LOGSIG);
    double[] expResult = { 0.5938731029341, 0.5938731029341, 0.6984652160025, 0.6984652160025 };
    double[] result = instance.output(input).getMatrix().getData();
    assertArrayEquals(expResult, result, 0.0000000000001);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Layer(org.gitia.froog.layer.Layer) Test(org.junit.Test)

Example 10 with Layer

use of org.gitia.froog.layer.Layer in project froog by mroodschild.

the class Open method agregarCapas.

private static void agregarCapas() {
    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        // new File(archivo.getAbsolutePath()));
        Document doc = docBuilder.parse(archivo);
        doc.getDocumentElement().normalize();
        // creamos un listado de nodos Capa
        NodeList layers = doc.getElementsByTagName("layer");
        // recorremos capa por capa
        for (int i = 0; i < layers.getLength(); i++) {
            // creamos un Nodo para obtener el primer elemento
            Node layerNode = layers.item(i);
            if (layerNode.getNodeType() == Node.ELEMENT_NODE) {
                Element layerElement = (Element) layerNode;
                String function = obtenerNodoValor("transferFunction", layerElement);
                String bias = obtenerNodoValor("bias", layerElement);
                String weight = obtenerNodoValor("w", layerElement);
                double[] b = Arrays.stream(bias.split(",")).mapToDouble(Double::valueOf).toArray();
                double[] w = Arrays.stream(weight.split(",")).mapToDouble(Double::valueOf).toArray();
                net.addLayer(new Layer(new SimpleMatrix(b.length, w.length / b.length, true, w), new SimpleMatrix(b.length, 1, true, b), function));
            }
        // fin de creacion de las capas
        }
    } catch (SAXException | IOException | ParserConfigurationException ex) {
        Logger.getLogger(Open.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) Layer(org.gitia.froog.layer.Layer) SAXException(org.xml.sax.SAXException) SimpleMatrix(org.ejml.simple.SimpleMatrix) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

Layer (org.gitia.froog.layer.Layer)18 SimpleMatrix (org.ejml.simple.SimpleMatrix)14 Test (org.junit.Test)11 Feedforward (org.gitia.froog.Feedforward)4 IOException (java.io.IOException)2 Ignore (org.junit.Ignore)2 Random (java.util.Random)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Backpropagation (org.gitia.froog.trainingalgorithm.Backpropagation)1 STD (org.gitia.jdataanalysis.data.stats.STD)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1