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

Fix some style issues

parent 5f6a67f5
No related branches found
No related tags found
No related merge requests found
Pipeline #1034 failed
...@@ -6,11 +6,15 @@ import java.util.Collections; ...@@ -6,11 +6,15 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/**
* Class Trainer.
* Learn wowa weights based on training dataset
*/
public class Trainer { public class Trainer {
private final TrainerParameters parameters; private final TrainerParameters parameters;
public Trainer(TrainerParameters parameters) { public Trainer(final TrainerParameters parameters) {
this.parameters = parameters; this.parameters = parameters;
} }
...@@ -19,7 +23,7 @@ public class Trainer { ...@@ -19,7 +23,7 @@ public class Trainer {
* @param expected * @param expected
* @return * @return
*/ */
public SolutionDistance run(final List<double[]> data, final public SolutionDistance run(final List<double[]> data,
final double[] expected final double[] expected
) { ) {
List<SolutionDistance> current_population = List<SolutionDistance> current_population =
...@@ -46,8 +50,8 @@ public class Trainer { ...@@ -46,8 +50,8 @@ public class Trainer {
} }
//We found a new best solution //We found a new best solution
if (best_solution_of_current_population.getDistance() < if (best_solution_of_current_population.getDistance()
best_solution.getDistance()) { < best_solution.getDistance()) {
best_solution = best_solution_of_current_population; best_solution = best_solution_of_current_population;
} }
...@@ -74,18 +78,18 @@ public class Trainer { ...@@ -74,18 +78,18 @@ public class Trainer {
} }
/** /**
* @param numberOfWeights * @param number_of_weights
* @param populationSize * @param population_size
* @return * @return
*/ */
private List<SolutionDistance> generateInitialPopulation( private List<SolutionDistance> generateInitialPopulation(
int numberOfWeights, final int number_of_weights,
int populationSize final int population_size
) { ) {
List<SolutionDistance> population = new ArrayList<>(); List<SolutionDistance> population = new ArrayList<>();
for (int i = 0; i < populationSize; i++) { for (int i = 0; i < population_size; i++) {
SolutionDistance solution = new SolutionDistance(numberOfWeights); SolutionDistance solution = new SolutionDistance(number_of_weights);
for (int j = 0; j < numberOfWeights; j++) { for (int j = 0; j < number_of_weights; j++) {
solution.weights_p[j] = Math.random(); solution.weights_p[j] = Math.random();
solution.weights_w[j] = Math.random(); solution.weights_w[j] = Math.random();
} }
...@@ -102,9 +106,9 @@ public class Trainer { ...@@ -102,9 +106,9 @@ public class Trainer {
* @return * @return
*/ */
private List<SolutionDistance> computeDistances( private List<SolutionDistance> computeDistances(
List<SolutionDistance> solutions, final List<SolutionDistance> solutions,
List<double[]> data, final List<double[]> data,
double[] expected final double[] expected
) { ) {
for (SolutionDistance solution : solutions) { for (SolutionDistance solution : solutions) {
solution.computeScoreTo(data, expected); solution.computeScoreTo(data, expected);
...@@ -120,9 +124,9 @@ public class Trainer { ...@@ -120,9 +124,9 @@ public class Trainer {
* @return * @return
*/ */
private List<SolutionDistance> rouletteWheelSelection( private List<SolutionDistance> rouletteWheelSelection(
List<SolutionDistance> solutions, final List<SolutionDistance> solutions,
List<SolutionDistance> selected_elements, final List<SolutionDistance> selected_elements,
int count final int count
) { ) {
double max = Utils.findMaxDistance(solutions); double max = Utils.findMaxDistance(solutions);
double min = Utils.findMinDistance(solutions); double min = Utils.findMinDistance(solutions);
...@@ -158,9 +162,9 @@ public class Trainer { ...@@ -158,9 +162,9 @@ public class Trainer {
* @return * @return
*/ */
private List<SolutionDistance> tournamentSelection( private List<SolutionDistance> tournamentSelection(
List<SolutionDistance> solutions, final List<SolutionDistance> solutions,
List<SolutionDistance> selected_elements, final List<SolutionDistance> selected_elements,
int count final int count
) { ) {
while (selected_elements.size() < count) { while (selected_elements.size() < count) {
...@@ -191,13 +195,13 @@ public class Trainer { ...@@ -191,13 +195,13 @@ public class Trainer {
/** /**
* @param solutions * @param solutions
* @param count * @param count
* @param selectionMethod * @param selection_method
* @return * @return
*/ */
private List<SolutionDistance> selectParents( private List<SolutionDistance> selectParents(
List<SolutionDistance> solutions, final List<SolutionDistance> solutions,
int count, final int count,
int selectionMethod final int selection_method
) { ) {
List<SolutionDistance> selected_parents = new ArrayList<>(); List<SolutionDistance> selected_parents = new ArrayList<>();
//Select the two best current solutions //Select the two best current solutions
...@@ -211,13 +215,13 @@ public class Trainer { ...@@ -211,13 +215,13 @@ public class Trainer {
solutions.remove(0); solutions.remove(0);
solutions.remove(1); solutions.remove(1);
if (selectionMethod == TrainerParameters.SELECTION_METHOD_RWS) { if (selection_method == TrainerParameters.SELECTION_METHOD_RWS) {
return this.rouletteWheelSelection(solutions, return this.rouletteWheelSelection(solutions,
selected_parents, selected_parents,
count - 2 count - 2
); );
} else if (selectionMethod == TrainerParameters.SELECTION_METHOD_TOS) { } else if (selection_method == TrainerParameters.SELECTION_METHOD_TOS) {
return this.tournamentSelection(solutions, return this.tournamentSelection(solutions,
selected_parents, selected_parents,
count - 2 count - 2
...@@ -269,8 +273,8 @@ public class Trainer { ...@@ -269,8 +273,8 @@ public class Trainer {
* @param beta * @param beta
* @return * @return
*/ */
private List<SolutionDistance> reproduce(SolutionDistance dad, private List<SolutionDistance> reproduce(final SolutionDistance dad,
SolutionDistance mom, final SolutionDistance mom,
List<SolutionDistance> solutions, List<SolutionDistance> solutions,
int cutPosition, int cutPosition,
double beta double beta
......
package be.cylab.java.wowa.training; package be.cylab.java.wowa.training;
import javax.rmi.CORBA.Util;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
......
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