Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
java-wowa-training
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cylab
java-wowa-training
Commits
f9a13e53
Commit
f9a13e53
authored
6 years ago
by
a.croix
Browse files
Options
Downloads
Patches
Plain Diff
Fix some style issues
parent
5f6a67f5
No related branches found
No related tags found
No related merge requests found
Pipeline
#1034
failed
6 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/be/cylab/java/wowa/training/Trainer.java
+32
-28
32 additions, 28 deletions
src/main/java/be/cylab/java/wowa/training/Trainer.java
src/main/java/be/cylab/java/wowa/training/Utils.java
+0
-1
0 additions, 1 deletion
src/main/java/be/cylab/java/wowa/training/Utils.java
with
32 additions
and
29 deletions
src/main/java/be/cylab/java/wowa/training/Trainer.java
+
32
−
28
View file @
f9a13e53
...
@@ -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 number
OfW
eights
* @param number
_of_w
eights
* @param population
S
ize
* @param population
_s
ize
* @return
* @return
*/
*/
private
List
<
SolutionDistance
>
generateInitialPopulation
(
private
List
<
SolutionDistance
>
generateInitialPopulation
(
int
number
OfW
eights
,
final
int
number
_of_w
eights
,
int
population
S
ize
final
int
population
_s
ize
)
{
)
{
List
<
SolutionDistance
>
population
=
new
ArrayList
<>();
List
<
SolutionDistance
>
population
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
population
S
ize
;
i
++)
{
for
(
int
i
=
0
;
i
<
population
_s
ize
;
i
++)
{
SolutionDistance
solution
=
new
SolutionDistance
(
number
OfW
eights
);
SolutionDistance
solution
=
new
SolutionDistance
(
number
_of_w
eights
);
for
(
int
j
=
0
;
j
<
number
OfW
eights
;
j
++)
{
for
(
int
j
=
0
;
j
<
number
_of_w
eights
;
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 selection
M
ethod
* @param selection
_m
ethod
* @return
* @return
*/
*/
private
List
<
SolutionDistance
>
selectParents
(
private
List
<
SolutionDistance
>
selectParents
(
List
<
SolutionDistance
>
solutions
,
final
List
<
SolutionDistance
>
solutions
,
int
count
,
final
int
count
,
int
selection
M
ethod
final
int
selection
_m
ethod
)
{
)
{
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
(
selection
M
ethod
==
TrainerParameters
.
SELECTION_METHOD_RWS
)
{
if
(
selection
_m
ethod
==
TrainerParameters
.
SELECTION_METHOD_RWS
)
{
return
this
.
rouletteWheelSelection
(
solutions
,
return
this
.
rouletteWheelSelection
(
solutions
,
selected_parents
,
selected_parents
,
count
-
2
count
-
2
);
);
}
else
if
(
selection
M
ethod
==
TrainerParameters
.
SELECTION_METHOD_TOS
)
{
}
else
if
(
selection
_m
ethod
==
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
...
...
This diff is collapsed.
Click to expand it.
src/main/java/be/cylab/java/wowa/training/Utils.java
+
0
−
1
View file @
f9a13e53
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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment