Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QcmpCompressionLibrary
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BioinformaticDataCompression
QcmpCompressionLibrary
Commits
2c5fcbc5
Commit
2c5fcbc5
authored
5 years ago
by
Vojtech Moravec
Browse files
Options
Downloads
Patches
Plain Diff
Simplifid memory update.
parent
9e022a6a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/quantization/de/shade/LShadeSolver.java
+21
-16
21 additions, 16 deletions
src/main/java/quantization/de/shade/LShadeSolver.java
src/main/java/quantization/utilities/Utils.java
+8
-0
8 additions, 0 deletions
src/main/java/quantization/utilities/Utils.java
with
29 additions
and
16 deletions
src/main/java/quantization/de/shade/LShadeSolver.java
+
21
−
16
View file @
2c5fcbc5
...
@@ -68,7 +68,7 @@ public class LShadeSolver extends DESolverWithArchive {
...
@@ -68,7 +68,7 @@ public class LShadeSolver extends DESolverWithArchive {
initializeMemory
(
0.5
);
initializeMemory
(
0.5
);
ArrayList
<
Double
>
successfulCr
=
new
ArrayList
<
Double
>();
ArrayList
<
Double
>
successfulCr
=
new
ArrayList
<
Double
>();
ArrayList
<
Double
>
successfulF
=
new
ArrayList
<
Double
>();
ArrayList
<
Double
>
successfulF
=
new
ArrayList
<
Double
>();
ArrayList
<
Integer
>
successfulIndices
=
new
ArrayList
<
Integer
>();
ArrayList
<
Double
>
absDelta
=
new
ArrayList
<
Double
>();
generateInitialPopulation
();
generateInitialPopulation
();
double
avgFitness
=
calculateFitnessForPopulationParallel
(
currentPopulation
);
double
avgFitness
=
calculateFitnessForPopulationParallel
(
currentPopulation
);
...
@@ -84,7 +84,7 @@ public class LShadeSolver extends DESolverWithArchive {
...
@@ -84,7 +84,7 @@ public class LShadeSolver extends DESolverWithArchive {
successfulCr
.
clear
();
successfulCr
.
clear
();
successfulF
.
clear
();
successfulF
.
clear
();
successfulIndices
.
clear
();
absDelta
.
clear
();
StringBuilder
generationLog
=
new
StringBuilder
(
String
.
format
(
"%s\nGeneration: %d\n"
,
delimiter
,
(
generation
+
1
)));
StringBuilder
generationLog
=
new
StringBuilder
(
String
.
format
(
"%s\nGeneration: %d\n"
,
delimiter
,
(
generation
+
1
)));
currentPopulationSorted
=
createSortedCopyOfCurrentPopulation
();
currentPopulationSorted
=
createSortedCopyOfCurrentPopulation
();
...
@@ -122,7 +122,7 @@ public class LShadeSolver extends DESolverWithArchive {
...
@@ -122,7 +122,7 @@ public class LShadeSolver extends DESolverWithArchive {
if
(
offsprings
[
i
].
getFitness
()
<
old
.
getFitness
())
{
if
(
offsprings
[
i
].
getFitness
()
<
old
.
getFitness
())
{
archive
.
add
(
old
);
archive
.
add
(
old
);
successfulIndices
.
add
(
i
);
absDelta
.
add
(
Math
.
abs
(
offsprings
[
i
].
getFitness
()
-
currentPopulation
[
i
].
getFitness
())
);
successfulCr
.
add
(
old
.
getCrossoverProbability
());
successfulCr
.
add
(
old
.
getCrossoverProbability
());
successfulF
.
add
(
old
.
getMutationFactor
());
successfulF
.
add
(
old
.
getMutationFactor
());
}
}
...
@@ -131,7 +131,7 @@ public class LShadeSolver extends DESolverWithArchive {
...
@@ -131,7 +131,7 @@ public class LShadeSolver extends DESolverWithArchive {
}
}
}
}
updateMemory
(
successfulIndices
,
successfulCr
,
successfulF
,
offsprings
);
updateMemory
(
successfulCr
,
successfulF
,
absDelta
);
currentPopulation
=
nextPopulation
;
currentPopulation
=
nextPopulation
;
applyLinearReductionOfPopulationSize
(
nfe
,
maxNfe
);
applyLinearReductionOfPopulationSize
(
nfe
,
maxNfe
);
avgFitness
=
getMseFromCalculatedFitness
(
currentPopulation
);
avgFitness
=
getMseFromCalculatedFitness
(
currentPopulation
);
...
@@ -171,25 +171,19 @@ public class LShadeSolver extends DESolverWithArchive {
...
@@ -171,25 +171,19 @@ public class LShadeSolver extends DESolverWithArchive {
return
newPopulationSize
;
return
newPopulationSize
;
}
}
private
void
updateMemory
(
final
ArrayList
<
Integer
>
successfulIndices
,
private
void
updateMemory
(
final
ArrayList
<
Double
>
successfulCr
,
final
ArrayList
<
Double
>
successfulCr
,
final
ArrayList
<
Double
>
successfulF
,
final
ArrayList
<
Double
>
successfulF
,
final
DEIndividual
[]
offsprings
)
{
final
ArrayList
<
Double
>
absDelta
)
{
if
((!
successfulCr
.
isEmpty
())
&&
(!
successfulF
.
isEmpty
()))
{
if
((!
successfulCr
.
isEmpty
())
&&
(!
successfulF
.
isEmpty
()))
{
assert
((
successfulIndices
.
size
()
==
successfulCr
.
size
())
&&
(
successfulCr
.
size
()
==
successfulF
.
size
()));
assert
((
absDelta
.
size
()
==
successfulCr
.
size
())
&&
(
successfulCr
.
size
()
==
successfulF
.
size
()));
int
kCount
=
successfulCr
.
size
();
int
kCount
=
successfulCr
.
size
();
double
[]
weights
=
new
double
[
kCount
];
double
[]
weights
=
new
double
[
kCount
];
for
(
int
k
=
0
;
k
<
kCount
;
k
++)
{
for
(
int
k
=
0
;
k
<
kCount
;
k
++)
{
final
int
successfulIndex
=
successfulIndices
.
get
(
k
);
double
numerator
=
Math
.
abs
(
offsprings
[
successfulIndex
].
getFitness
()
-
currentPopulation
[
successfulIndex
].
getFitness
());
double
denominator
=
0.0
;
for
(
int
l
=
0
;
l
<
kCount
;
l
++)
{
denominator
+=
Math
.
abs
(
offsprings
[
successfulIndices
.
get
(
l
)].
getFitness
()
-
currentPopulation
[
successfulIndices
.
get
(
l
)].
getFitness
());
}
final
double
numerator
=
absDelta
.
get
(
k
);
final
double
denominator
=
Utils
.
arrayListSum
(
absDelta
);
weights
[
k
]
=
(
numerator
/
denominator
);
weights
[
k
]
=
(
numerator
/
denominator
);
}
}
...
@@ -203,8 +197,19 @@ public class LShadeSolver extends DESolverWithArchive {
...
@@ -203,8 +197,19 @@ public class LShadeSolver extends DESolverWithArchive {
if
(
memoryIndex
>=
memorySize
)
{
if
(
memoryIndex
>=
memorySize
)
{
memoryIndex
=
0
;
memoryIndex
=
0
;
}
}
}
}
// StringBuilder sb = new StringBuilder();
// sb.append("MEMORY F: ");
// for (int i = 0; i < memoryF.length; i++) {
// sb.append(String.format("%.5f ", memoryF[i]));
// }
// sb.append("\n");
// sb.append("MEMORY Cr: ");
// for (int i = 0; i < memoryCr.length; i++) {
// sb.append(String.format("%.5f ", memoryCr[i]));
// }
// System.out.println(sb.toString());
}
}
public
int
getMemorySize
()
{
public
int
getMemorySize
()
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/quantization/utilities/Utils.java
+
8
−
0
View file @
2c5fcbc5
...
@@ -63,4 +63,12 @@ public class Utils {
...
@@ -63,4 +63,12 @@ public class Utils {
}
}
return
values
;
return
values
;
}
}
public
static
double
arrayListSum
(
final
ArrayList
<
Double
>
array
)
{
double
sum
=
0.0
;
for
(
final
double
val
:
array
)
{
sum
+=
val
;
}
return
sum
;
}
}
}
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