我有这种感知器算法用于来自传感器的分类运动数据:
//vector data from sensors
double inputs[][] = new double[nofall_data.size() + fall_data.size()][nofall_data.get(0).length];
//sets fall or no fall for corresponding inputs
int outputs[] = new int[nofall_data.size() + fall_data.size()];
//initialize weights
for (int i = 0; i < n; i++) {
weights[i] = r.nextDouble();
}
for (int i = 0; i < maxIterations; i++) {
int totalError = 0;
for (int j = 0; j < outputs.length; j++) { // = ~5.000-10.000
//classifiy object
int output = classifyInt(inputs[j], false);
//calculate error
int error = output - outputs[j];
//sum of errors
totalError += error;
for (int k = 0; k < n; k++) { //n = 4
//weight is unchanged if there is no error, else change it
weights[k] += inputs[j][k] * lrate * error;
}
}
i++;
//done if there are no errors
if (totalError == 0) {
Log.i(LOG_TAG, String.valueOf(i));
Log.i(LOG_TAG, "classifying completed with no errors");
break;
}
}
and classifyInt:
private int classifyInt(double[] input, boolean b) {
double sum = 0.0;
for (int i = 0; i < input.length; i++) {
sum += weights[i] * input[i];
}
//(just for debugging)
if (b) {
System.out.println(sum);
}
if (sum > threshold)
return 1;
else
return 0;
}
如果我没有添加maxIterations条件,它将永远运行。如果我停下来让我们说50k迭代后结果不满意(几乎每个新数据都放在错误的类中)。系统从传感器获取加速数据,并且应该对跌倒检测系统的跌落或不跌落的新数据进行分类。 我已经尝试使用Java-ML库中的最近邻算法,它运行得很好。我想尝试将pereceptron与之相提并论。 我在算法中得到了什么错误吗? lrate始终设置为1,阈值设置为0。