Search in sources :

Example 1 with Linear

use of org.nd4j.linalg.api.ops.impl.layers.Linear in project nd4j by deeplearning4j.

the class SameDiffTests method testLinearModule.

@Test
public void testLinearModule() {
    int nIn = 5;
    Linear linear = Linear.execBuilder().nIn(nIn).nOut(4).weightInitScheme(new UniformInitScheme('f', nIn)).biasWeightInitScheme(new ZeroInitScheme('f')).build();
    linear.exec(Nd4j.linspace(1, 20, 20).reshape(4, 5));
    assertEquals(1, linear.numOutputArguments());
}
Also used : UniformInitScheme(org.nd4j.weightinit.impl.UniformInitScheme) ZeroInitScheme(org.nd4j.weightinit.impl.ZeroInitScheme) Linear(org.nd4j.linalg.api.ops.impl.layers.Linear) Test(org.junit.Test)

Example 2 with Linear

use of org.nd4j.linalg.api.ops.impl.layers.Linear in project nd4j by deeplearning4j.

the class SameDiffTests method testLinearModule2.

@Test
public void testLinearModule2() {
    Linear linear = Linear.execBuilder().nIn(3).nOut(2).weightInitScheme(new OneInitScheme('f')).biasWeightInitScheme(new ZeroInitScheme('f')).build();
    linear.exec(Nd4j.linspace(1, 6, 6).reshape(2, 3));
    INDArray assertion = Nd4j.create(new double[][] { { 6, 6 }, { 15, 15 } });
    assertEquals(assertion, linear.outputArguments()[0]);
}
Also used : OneInitScheme(org.nd4j.weightinit.impl.OneInitScheme) ZeroInitScheme(org.nd4j.weightinit.impl.ZeroInitScheme) INDArray(org.nd4j.linalg.api.ndarray.INDArray) Linear(org.nd4j.linalg.api.ops.impl.layers.Linear) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Linear (org.nd4j.linalg.api.ops.impl.layers.Linear)2 ZeroInitScheme (org.nd4j.weightinit.impl.ZeroInitScheme)2 INDArray (org.nd4j.linalg.api.ndarray.INDArray)1 OneInitScheme (org.nd4j.weightinit.impl.OneInitScheme)1 UniformInitScheme (org.nd4j.weightinit.impl.UniformInitScheme)1