Search in sources :

Example 11 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class ModelInspectorTest method testValidateStats.

@Test
public void testValidateStats() throws Exception {
    ModelConfig config = CommonUtils.loadModelConfig();
    ValidateResult result = instance.probe(config, ModelStep.STATS);
    Assert.assertTrue(result.getStatus());
}
Also used : ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) ValidateResult(ml.shifu.shifu.container.meta.ValidateResult) Test(org.testng.annotations.Test)

Example 12 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class ModelInspectorTest method testValidatePostTrain.

@Test
public void testValidatePostTrain() throws Exception {
    ModelConfig config = CommonUtils.loadModelConfig();
    ValidateResult result = instance.probe(config, ModelStep.POSTTRAIN);
    Assert.assertTrue(result.getStatus());
}
Also used : ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) ValidateResult(ml.shifu.shifu.container.meta.ValidateResult) Test(org.testng.annotations.Test)

Example 13 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class NNTrainerTest method testXorOperation.

// @Test
public void testXorOperation() throws IOException {
    ModelConfig config = ModelConfig.createInitModelConfig(".", ALGORITHM.NN, ".", false);
    config.getTrain().setBaggingSampleRate(1.0);
    config.getTrain().setValidSetRate(0.1);
    config.getTrain().getParams().put("Propagation", "Q");
    config.getTrain().getParams().put("NumHiddenLayers", 1);
    config.getTrain().getParams().put("LearningRate", 1);
    List<Integer> nodes = new ArrayList<Integer>();
    nodes.add(5);
    List<String> func = new ArrayList<String>();
    func.add("tanh");
    config.getTrain().getParams().put("NumHiddenNodes", nodes);
    config.getTrain().getParams().put("ActivationFunc", func);
    config.getTrain().setNumTrainEpochs(100);
    NNTrainer trainer = new NNTrainer(config, 0, false);
    trainer.setTrainSet(xor_Trainset);
    trainer.setValidSet(xor_Validset);
    trainer.train();
    BasicNetwork bn = trainer.getNetwork();
    boolean[] cases = { true, false, false, true };
    int i = 0;
    for (MLDataPair data : xor_Validset) {
        double[] score = bn.compute(data.getInput()).getData();
        Assert.assertEquals(score[0] * 1000 < 500, cases[i]);
        i++;
    }
    Assert.assertEquals(bn.getLayerCount(), (Integer) (config.getTrain().getParams().get("NumHiddenLayers")) + 2);
}
Also used : BasicMLDataPair(org.encog.ml.data.basic.BasicMLDataPair) MLDataPair(org.encog.ml.data.MLDataPair) ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) BasicNetwork(org.encog.neural.networks.BasicNetwork) NNTrainer(ml.shifu.shifu.core.alg.NNTrainer) ArrayList(java.util.ArrayList)

Example 14 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class SVMTrainerTest method setUp.

// MLDataSet dataSet;
// MLDataSet trainSet;
// MLDataSet validSet, testSet;
// Random random;
@BeforeClass
public void setUp() throws IOException {
    // .createInitModelConfig("./", "./");
    config = new ModelConfig();
    config.getTrain().setAlgorithm("SVM");
    config.getDataSet().setSource(SourceType.LOCAL);
    config.getVarSelect().setFilterNum(2);
    config.getDataSet().setDataDelimiter(",");
    config.getDataSet().setSource(SourceType.HDFS);
    config.getTrain().setParams(new HashMap<String, Object>());
    config.getTrain().getParams().put("Const", 1.1);
    config.getTrain().getParams().put("Gamma", 0.95);
    config.getTrain().getParams().put("Kernel", "rbf");
    config.getTrain().setBaggingSampleRate(1.0);
    config.getTrain().setBaggingWithReplacement(false);
    trainer = new SVMTrainer(config, 0, false);
    trainer.setTrainSet(xor_Trainset);
    trainer.setValidSet(xor_Validset);
}
Also used : ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) SVMTrainer(ml.shifu.shifu.core.alg.SVMTrainer) BeforeClass(org.testng.annotations.BeforeClass)

Example 15 with ModelConfig

use of ml.shifu.shifu.container.obj.ModelConfig in project shifu by ShifuML.

the class AbstractTrainerTest method testLoad1.

@Test
public void testLoad1() throws IOException {
    MLDataSet set = new BasicMLDataSet();
    ModelConfig modelConfig = CommonUtils.loadModelConfig("src/test/resources/example/cancer-judgement/ModelStore/ModelSet1/ModelConfig.json", SourceType.LOCAL);
    double[] input = new double[modelConfig.getVarSelectFilterNum()];
    for (int j = 0; j < 1000; j++) {
        for (int i = 0; i < modelConfig.getVarSelectFilterNum(); i++) {
            input[i] = random.nextDouble();
        }
        double[] ideal = new double[1];
        ideal[0] = random.nextInt(2);
        MLDataPair pair = new BasicMLDataPair(new BasicMLData(input), new BasicMLData(ideal));
        set.add(pair);
    }
    modelConfig.getTrain().setTrainOnDisk(false);
    AbstractTrainer trainer = new NNTrainer(modelConfig, 0, false);
    trainer.setDataSet(set);
    Assert.assertTrue(trainer.getTrainSet().getRecordCount() <= (1 - modelConfig.getValidSetRate()) * modelConfig.getBaggingSampleRate() * set.getRecordCount() * 1.05);
    Assert.assertTrue(trainer.getTrainSet().getRecordCount() >= (1 - modelConfig.getValidSetRate()) * modelConfig.getBaggingSampleRate() * set.getRecordCount() * 0.95);
    modelConfig.getTrain().setFixInitInput(true);
    trainer = new NNTrainer(modelConfig, 0, false);
    trainer.setDataSet(set);
    Assert.assertTrue(trainer.getTrainSet().getRecordCount() <= (1 - modelConfig.getValidSetRate()) * modelConfig.getBaggingSampleRate() * set.getRecordCount() * 1.05);
    Assert.assertTrue(trainer.getTrainSet().getRecordCount() >= (1 - modelConfig.getValidSetRate()) * modelConfig.getBaggingSampleRate() * set.getRecordCount() * 0.95);
    modelConfig.getTrain().setFixInitInput(false);
    modelConfig.getTrain().setBaggingWithReplacement(false);
    trainer = new NNTrainer(modelConfig, 0, false);
    trainer.setDataSet(set);
    Assert.assertTrue(trainer.getTrainSet().getRecordCount() <= (1 - modelConfig.getValidSetRate()) * modelConfig.getBaggingSampleRate() * set.getRecordCount() * 1.05);
    Assert.assertTrue(trainer.getTrainSet().getRecordCount() >= (1 - modelConfig.getValidSetRate()) * modelConfig.getBaggingSampleRate() * set.getRecordCount() * 0.95);
}
Also used : BasicMLDataPair(org.encog.ml.data.basic.BasicMLDataPair) MLDataPair(org.encog.ml.data.MLDataPair) ModelConfig(ml.shifu.shifu.container.obj.ModelConfig) NNTrainer(ml.shifu.shifu.core.alg.NNTrainer) MLDataSet(org.encog.ml.data.MLDataSet) BasicMLDataSet(org.encog.ml.data.basic.BasicMLDataSet) BasicMLDataPair(org.encog.ml.data.basic.BasicMLDataPair) BasicMLData(org.encog.ml.data.basic.BasicMLData) BasicMLDataSet(org.encog.ml.data.basic.BasicMLDataSet) Test(org.testng.annotations.Test)

Aggregations

ModelConfig (ml.shifu.shifu.container.obj.ModelConfig)33 Test (org.testng.annotations.Test)18 ArrayList (java.util.ArrayList)9 File (java.io.File)8 ValidateResult (ml.shifu.shifu.container.meta.ValidateResult)8 ColumnConfig (ml.shifu.shifu.container.obj.ColumnConfig)8 TrainingDataSet (ml.shifu.shifu.core.dvarsel.dataset.TrainingDataSet)4 IOException (java.io.IOException)3 EvalConfig (ml.shifu.shifu.container.obj.EvalConfig)3 NNTrainer (ml.shifu.shifu.core.alg.NNTrainer)3 BeforeClass (org.testng.annotations.BeforeClass)3 FileInputStream (java.io.FileInputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Properties (java.util.Properties)2 RawSourceData (ml.shifu.shifu.container.obj.RawSourceData)2 PathFinder (ml.shifu.shifu.fs.PathFinder)2 MLDataPair (org.encog.ml.data.MLDataPair)2 BasicMLDataPair (org.encog.ml.data.basic.BasicMLDataPair)2