Skip to content
Snippets Groups Projects
Commit 1d6457cd authored by a.croix's avatar a.croix
Browse files

Fix issue #3

parent 58cd9e95
No related branches found
No related tags found
No related merge requests found
Pipeline #1686 failed
......@@ -528,13 +528,13 @@ public class Trainer {
*/
private void checkAndCorrectNullWeightVector(final AbstractSolution child) {
if (Utils.sumListElements(child.getWeightsW()) == 0) {
int index = Utils.randomInteger(0, child.getWeightsW().size()) - 1;
int index = Utils.randomInteger(0, child.getWeightsW().size() - 1);
List<Double> w = child.getWeightsW();
w.set(index, 1.0);
child.setWeightsW(w);
}
if (Utils.sumListElements(child.getWeightsP()) == 0) {
int index = Utils.randomInteger(0, child.getWeightsP().size()) - 1;
int index = Utils.randomInteger(0, child.getWeightsP().size() - 1);
List<Double> p = child.getWeightsP();
p.set(index, 1.0);
child.setWeightsP(p);
......
......@@ -34,7 +34,7 @@ final class Utils {
* @return
*/
public static List<Double> normalizeWeights(final List<Double> weights) {
double sum_weight = Utils.sumListElements(weights);
Double sum_weight = Utils.sumListElements(weights);
List<Double> weights_normalized = new ArrayList<>();
for (int i = 0; i < weights.size(); i++) {
weights_normalized.add(weights.get(i) / sum_weight);
......@@ -97,8 +97,8 @@ final class Utils {
* @param array
* @return
*/
public static double sumListElements(final List<Double> array) {
float sum = 0;
public static Double sumListElements(final List<Double> array) {
Double sum = 0.0;
for (Double weight : array) {
sum += weight;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment