Search in sources :

Example 11 with BasicNetwork

use of org.encog.neural.networks.BasicNetwork in project shifu by ShifuML.

the class NNTrainerTest method computeScore.

private void computeScore(File modelFile, MLDataPair dataPair0, MLDataPair dataPair1, MLDataPair dataPair2, MLDataPair dataPair3) {
    BasicNetwork model = (BasicNetwork) EncogDirectoryPersistence.loadObject(modelFile);
    System.out.println((int) (model.compute(dataPair0.getInput()).getData(0) * 1000));
    System.out.println((int) (model.compute(dataPair1.getInput()).getData(0) * 1000));
    System.out.println((int) (model.compute(dataPair2.getInput()).getData(0) * 1000));
    System.out.println((int) (model.compute(dataPair3.getInput()).getData(0) * 1000));
}
Also used : BasicNetwork(org.encog.neural.networks.BasicNetwork)

Example 12 with BasicNetwork

use of org.encog.neural.networks.BasicNetwork in project shifu by ShifuML.

the class DTrainTest method setup.

@BeforeTest
public void setup() {
    network = new BasicNetwork();
    network.addLayer(new BasicLayer(DTrainTest.INPUT_COUNT));
    network.addLayer(new BasicLayer(DTrainTest.HIDDEN_COUNT));
    network.addLayer(new BasicLayer(DTrainTest.OUTPUT_COUNT));
    network.getStructure().finalizeStructure();
    network.reset();
    weights = network.getFlat().getWeights();
    training = RandomTrainingFactory.generate(1000, 10000, INPUT_COUNT, OUTPUT_COUNT, -1, 1);
}
Also used : BasicNetwork(org.encog.neural.networks.BasicNetwork) BasicLayer(org.encog.neural.networks.layers.BasicLayer) BeforeTest(org.testng.annotations.BeforeTest)

Example 13 with BasicNetwork

use of org.encog.neural.networks.BasicNetwork in project shifu by ShifuML.

the class NNModelSpecTest method testModelStructureCompare.

@Test
public void testModelStructureCompare() {
    BasicML basicML = BasicML.class.cast(EncogDirectoryPersistence.loadObject(new File("src/test/resources/model/model0.nn")));
    BasicNetwork basicNetwork = (BasicNetwork) basicML;
    FlatNetwork flatNetwork = basicNetwork.getFlat();
    BasicML extendedBasicML = BasicML.class.cast(EncogDirectoryPersistence.loadObject(new File("src/test/resources/model/model1.nn")));
    BasicNetwork extendedBasicNetwork = (BasicNetwork) extendedBasicML;
    FlatNetwork extendedFlatNetwork = extendedBasicNetwork.getFlat();
    Assert.assertEquals(new NNStructureComparator().compare(flatNetwork, extendedFlatNetwork), -1);
    Assert.assertEquals(new NNStructureComparator().compare(flatNetwork, flatNetwork), 0);
    Assert.assertEquals(new NNStructureComparator().compare(extendedFlatNetwork, flatNetwork), 1);
    BasicML diffBasicML = BasicML.class.cast(EncogDirectoryPersistence.loadObject(new File("src/test/resources/model/model2.nn")));
    BasicNetwork diffBasicNetwork = (BasicNetwork) diffBasicML;
    FlatNetwork diffFlatNetwork = diffBasicNetwork.getFlat();
    Assert.assertEquals(new NNStructureComparator().compare(flatNetwork, diffFlatNetwork), -1);
    Assert.assertEquals(new NNStructureComparator().compare(diffFlatNetwork, flatNetwork), -1);
    Assert.assertEquals(new NNStructureComparator().compare(extendedFlatNetwork, diffFlatNetwork), 1);
    Assert.assertEquals(new NNStructureComparator().compare(diffFlatNetwork, extendedFlatNetwork), -1);
    BasicML deepBasicML = BasicML.class.cast(EncogDirectoryPersistence.loadObject(new File("src/test/resources/model/model3.nn")));
    BasicNetwork deppBasicNetwork = (BasicNetwork) deepBasicML;
    FlatNetwork deepFlatNetwork = deppBasicNetwork.getFlat();
    Assert.assertEquals(new NNStructureComparator().compare(deepFlatNetwork, flatNetwork), 1);
    Assert.assertEquals(new NNStructureComparator().compare(flatNetwork, deepFlatNetwork), -1);
}
Also used : FlatNetwork(org.encog.neural.flat.FlatNetwork) BasicNetwork(org.encog.neural.networks.BasicNetwork) NNStructureComparator(ml.shifu.shifu.core.dtrain.nn.NNStructureComparator) BasicML(org.encog.ml.BasicML) File(java.io.File) Test(org.testng.annotations.Test)

Example 14 with BasicNetwork

use of org.encog.neural.networks.BasicNetwork in project shifu by ShifuML.

the class NNModelSpecTest method testFitExistingModelIn.

@Test
public void testFitExistingModelIn() {
    BasicML basicML = BasicML.class.cast(EncogDirectoryPersistence.loadObject(new File("src/test/resources/model/model0.nn")));
    BasicNetwork basicNetwork = (BasicNetwork) basicML;
    FlatNetwork flatNetwork = basicNetwork.getFlat();
    NNMaster master = new NNMaster();
    Set<Integer> fixedWeightIndexSet = master.fitExistingModelIn(flatNetwork, flatNetwork, Arrays.asList(new Integer[] { 6 }));
    List<Integer> indexList = new ArrayList<Integer>(fixedWeightIndexSet);
    Collections.sort(indexList);
    Assert.assertEquals(indexList.size(), 31);
    fixedWeightIndexSet = master.fitExistingModelIn(flatNetwork, flatNetwork, Arrays.asList(new Integer[] { 1 }));
    indexList = new ArrayList<Integer>(fixedWeightIndexSet);
    Collections.sort(indexList);
    Assert.assertEquals(indexList.size(), 930);
    BasicML extendedBasicML = BasicML.class.cast(EncogDirectoryPersistence.loadObject(new File("src/test/resources/model/model1.nn")));
    BasicNetwork extendedBasicNetwork = (BasicNetwork) extendedBasicML;
    FlatNetwork extendedFlatNetwork = extendedBasicNetwork.getFlat();
    fixedWeightIndexSet = master.fitExistingModelIn(flatNetwork, extendedFlatNetwork, Arrays.asList(new Integer[] { 1 }));
    indexList = new ArrayList<Integer>(fixedWeightIndexSet);
    Collections.sort(indexList);
    Assert.assertEquals(indexList.size(), 930);
    fixedWeightIndexSet = master.fitExistingModelIn(flatNetwork, extendedFlatNetwork, Arrays.asList(new Integer[] { 1 }), false);
    indexList = new ArrayList<Integer>(fixedWeightIndexSet);
    Collections.sort(indexList);
    Assert.assertEquals(indexList.size(), 900);
}
Also used : FlatNetwork(org.encog.neural.flat.FlatNetwork) NNMaster(ml.shifu.shifu.core.dtrain.nn.NNMaster) BasicNetwork(org.encog.neural.networks.BasicNetwork) ArrayList(java.util.ArrayList) BasicML(org.encog.ml.BasicML) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

BasicNetwork (org.encog.neural.networks.BasicNetwork)14 ArrayList (java.util.ArrayList)6 BasicML (org.encog.ml.BasicML)5 FlatNetwork (org.encog.neural.flat.FlatNetwork)5 File (java.io.File)4 BasicLayer (org.encog.neural.networks.layers.BasicLayer)4 List (java.util.List)3 ActivationSigmoid (org.encog.engine.network.activation.ActivationSigmoid)3 Test (org.testng.annotations.Test)3 NNMaster (ml.shifu.shifu.core.dtrain.nn.NNMaster)2 ActivationLinear (org.encog.engine.network.activation.ActivationLinear)2 MLDataPair (org.encog.ml.data.MLDataPair)2 Comparator (java.util.Comparator)1 Callable (java.util.concurrent.Callable)1 ScoreObject (ml.shifu.shifu.container.ScoreObject)1 ModelConfig (ml.shifu.shifu.container.obj.ModelConfig)1 MSEWorker (ml.shifu.shifu.core.MSEWorker)1 NNTrainer (ml.shifu.shifu.core.alg.NNTrainer)1 BasicFloatNetwork (ml.shifu.shifu.core.dtrain.dataset.BasicFloatNetwork)1 FloatFlatNetwork (ml.shifu.shifu.core.dtrain.dataset.FloatFlatNetwork)1