Search in sources :

Example 91 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix 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)

Example 92 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project froog by mroodschild.

the class PreRelu method output.

@Override
public SimpleMatrix output(SimpleMatrix z) {
    double parm = 3;
    SimpleMatrix p = new SimpleMatrix(z.numRows(), z.numCols());
    for (int i = 0; i < p.getNumElements(); i++) {
        p.set(i, Math.max(z.get(i), z.get(i) * parm));
    }
    return p;
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 93 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project froog by mroodschild.

the class PreRelu method derivative.

@Override
public SimpleMatrix derivative(SimpleMatrix a) {
    double parm = 3;
    SimpleMatrix p = new SimpleMatrix(a.numRows(), a.numCols());
    for (int i = 0; i < p.getNumElements(); i++) {
        p.set(i, (a.get(i) >= 0) ? parm : -1);
    }
    return p;
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 94 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project froog by mroodschild.

the class Softplus method derivative.

/**
 * FunciĆ³n Derivada de la softplus
 *
 * @param z
 * @return 1 / (1 + e^(-z))
 */
@Override
public SimpleMatrix derivative(SimpleMatrix z) {
    SimpleMatrix div = z.scale(-1).elementExp().plus(1);
    SimpleMatrix b = new SimpleMatrix(z.numRows(), z.numCols());
    b.set(1);
    return b.elementDiv(div);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix)

Example 95 with SimpleMatrix

use of org.ejml.simple.SimpleMatrix in project froog by mroodschild.

the class LayerTest method testOutputZ.

/**
 * Test of outputZ method, of class Layer.
 */
@Test
public void testOutputZ() {
    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);
    Layer layer = new Layer(w1, b1, "tansig");
    SimpleMatrix entrada = new SimpleMatrix(2, 1, true, 0.2, 0.6);
    double[] esperado = { 0.64, 0.4 };
    assertArrayEquals(esperado, layer.outputZ(entrada).getMatrix().getData(), 0.0001);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Layer(org.gitia.froog.layer.Layer) Test(org.junit.Test)

Aggregations

SimpleMatrix (org.ejml.simple.SimpleMatrix)156 Test (org.junit.Test)30 Layer (org.gitia.froog.layer.Layer)14 Test (org.junit.jupiter.api.Test)13 Map (java.util.Map)12 ArrayList (java.util.ArrayList)11 TransferFunction (org.gitia.froog.transferfunction.TransferFunction)10 Tree (edu.stanford.nlp.trees.Tree)9 TwoDimensionalMap (edu.stanford.nlp.util.TwoDimensionalMap)9 List (java.util.List)8 LexicalizedParser (edu.stanford.nlp.parser.lexparser.LexicalizedParser)7 Pair (edu.stanford.nlp.util.Pair)6 EmbeddingExtractor (edu.stanford.nlp.coref.neural.EmbeddingExtractor)5 Embedding (edu.stanford.nlp.neural.Embedding)5 DeepTree (edu.stanford.nlp.trees.DeepTree)5 CoreLabel (edu.stanford.nlp.ling.CoreLabel)4 SimpleTensor (edu.stanford.nlp.neural.SimpleTensor)4 DVModel (edu.stanford.nlp.parser.dvparser.DVModel)4 Logsig (org.gitia.froog.transferfunction.Logsig)4 Ignore (org.junit.Ignore)4