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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations