如何使用encog AI进行3D数据集

时间:2016-01-11 16:25:54

标签: java artificial-intelligence accelerometer encog

dataset的{​​{1}}由3个向量accelerometer组成 问题是Encog库上的示例用于(x, y, z)问题并使用2维,而XOR只接受一个维度 - double []。

任何人都可以帮助我解释MLData或 指向我可以利用3D数据集的任何其他库吗?

EDITED

好的我做了什么才能让它发挥作用

3D dataset

无论如何,我现在会尝试校准网络,因为结果很糟糕 - 就像对抗率低于50%,DTW算法约为80%-90%。

Basicaly我做了

public float compareTwoSequences(HashMap<Integer,List<Float>> base,
                                          HashMap<Integer,List<Float>> compare){
    Log.i("NN alg", "comparing two Sequences");

    List<Float> baseX = base.get(SensorData.X_axis);
    List<Float> baseY = base.get(SensorData.Y_axis);
    List<Float> baseZ = base.get(SensorData.Z_axis);
    List<Float> compareX = compare.get(SensorData.X_axis);
    List<Float> compareY = compare.get(SensorData.Y_axis);
    List<Float> compareZ = compare.get(SensorData.Z_axis);

    int baseSize = baseX.size();
    int compSize = compareX.size();
    int minSize = Math.min(baseSize, compSize);

    double[][] dataSet = new double[6][minSize];
    double[][] testSet = new double[3][minSize];
    double[][] ideal = new double[][]{
            {2.0},
            {2.0},
            {2.0},
            {0.0},
            {0.0},
            {0.0}
    };
    double[][] idealTest = new double[][]{
            {1.0},
            {1.0},
            {1.0}
    };

    Iterator<Float> xIter = baseX.iterator();
    Iterator<Float> yIter = baseY.iterator();
    Iterator<Float> zIter = baseZ.iterator();
    Iterator<Float> xIter1 = compareX.iterator();
    Iterator<Float> yIter1 = compareY.iterator();
    Iterator<Float> zIter1 = compareZ.iterator();
    for(int i = 0; i < minSize; i++){
        testSet[0][i] = dataSet[0][i] = xIter.next();
        testSet[1][i] = dataSet[1][i] = yIter.next();
        testSet[2][i] = dataSet[2][i] = zIter.next();
        dataSet[3][i] = xIter1.next();
        dataSet[4][i] = yIter1.next();
        dataSet[5][i] = zIter1.next();
    }


    NeuralDataSet trainingSet = new BasicNeuralDataSet(dataSet,ideal);

    network = new BasicNetwork();
    network.addLayer(new BasicLayer(null, false, baseSize));
    network.addLayer(new BasicLayer(new ActivationTANH(), true, 7));
    network.addLayer(new BasicLayer(new ActivationTANH(), true, 7));
    network.addLayer(new BasicLayer(new ActivationLinear(), false, 1));
    network.getStructure().finalizeStructure();
    network.reset();

    final Propagation train = new ResilientPropagation(network, trainingSet);



    int epochsCount = 100;
        for(int epoch = 1; epoch > epochsCount; epoch++ ){
            train.iteration();
        }
        Log.i("alg NN","Training error: "+train.getError()*100.0);
        train.finishTraining();

        int i=0;
        double error = 0.0;
        while(i<6){
            MLData input = new BasicMLData(dataSet[i]);
            MLData output = network.compute(input);
            if(i<3){
                error += Math.abs(output.getData(0));
            }
            Log.i("alg NN","Classification for i:"+i+" "+output.getData(0)+ " ideal "+ideal[i][0]);
            i++;
        }

        error = error/3.0*100.0;
        Log.i("alg NN","Final error is: "+error);
        return (float)(error);
}

1 个答案:

答案 0 :(得分:1)

这样的事情怎么样(这是C#,但Java应该类似)

    double[][] Input =
    {
            new[] {0.0, 0.0, 0.0},
            new[] {1.0, 0.0, 1.0},
            new[] {0.0, 1.0, 2.0},
            new[] {1.0, 1.0, 3.0}
    };

    double[][] Ideal =
    {
            new[] {0.0},
            new[] {1.0},
            new[] {1.0},
            new[] {0.0}
    };

    Encog.ML.Data.Basic.BasicMLDataSet TrainingSet = new Encog.ML.Data.Basic.BasicMLDataSet(Input, Ideal);

请注意,每个输入都包含三个值。这是根据XOR问题改编的,但我为每个问题添加了一个额外的值,以便每行模拟一个加速度计输入。