gpt4 book ai didi

java - 如何使用 encog AI 处理 3D 数据集

转载 作者:行者123 更新时间:2023-12-01 10:36:02 27 4
gpt4 key购买 nike

我有来自加速度计数据集,其中包含3个 vector (x, y, z)问题在于,Encog 库上的示例适用于 XOR 问题并使用二维,而 MLData 只接受一维 - double[]。

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

已编辑

好吧,我所做的就是让它发挥作用

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

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

基本上我做到了

input[][]=new double[][]{
{1,2,3,4,5,6,7,8,9}, // x Axis - first gesture
{1,2,3,4,5,6,7,8,9}, // y Axis - first gesture
{1,2,3,4,5,6,7,8,9}, // z Axis - first gesture
{1,2,3,4,5,6,7,8,9}, // x Axis - second gesture
{1,2,3,4,5,6,7,8,9}, // y Axis - second gesture
{1,2,3,4,5,6,7,8,9}, // z Axis - second gesture
}

最佳答案

像这样的怎么样(这是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 问题改编的,但我为每个问题添加了一个额外的值,以便每一行模拟一个加速度计输入。

关于java - 如何使用 encog AI 处理 3D 数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34726409/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com