我正在尝试使用它们的适合度对TreeMap进行神经网络排序。这是我的代码。
private double[][] sort(){
double[][] populationFitnesses = new double[populationNumber][populationSize];
for (int i = 0; i < populationSize; i++) {
NeuralNetwork[] networks = allInIndex(i);
double[] fitnesses = fitness(networks);
for (int j = 0; j < populationNumber; j++) {
populationFitnesses[j][i] = fitnesses[j];
}
}
for (int i = 0; i < populationNumber; i++) {
Map<Double, NeuralNetwork> sorted = new TreeMap<>();
for (int j = 0; j < populationSize; j++) {
System.out.println(sorted.size());
sorted.put(populationFitnesses[i][j], populations[i][j]);
System.out.println(sorted.size());
}
ArrayList<Double> keys = new ArrayList<>(sorted.keySet());
for (int j = 0; j < populationSize; j++) {
populations[i][j] = sorted.get(keys.get(j));
populationFitnesses[i][j] = keys.get(j);
}
}
return populationFitnesses;
}
出于某种原因,当我调用TreeMap.put时,似乎没有向它添加任何内容。有人可以解释一下如何解决这个问题吗? 感谢。