Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
old_macaon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Franck Dary
old_macaon
Commits
bf22fa5a
Commit
bf22fa5a
authored
6 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
GeneticAlgorithm now works with a mean to predict, and only save the best quarter of its population
parent
d9f848ff
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
neural_network/src/GeneticAlgorithm.cpp
+18
-4
18 additions, 4 deletions
neural_network/src/GeneticAlgorithm.cpp
with
18 additions
and
4 deletions
neural_network/src/GeneticAlgorithm.cpp
+
18
−
4
View file @
bf22fa5a
...
...
@@ -39,7 +39,19 @@ void GeneticAlgorithm::init(int nbInputs, const std::string & topology, int nbOu
std
::
vector
<
float
>
GeneticAlgorithm
::
predict
(
FeatureModel
::
FeatureDescription
&
fd
)
{
return
generation
[
0
]
->
mlp
.
predict
(
fd
);
std
::
vector
<
float
>
prediction
=
generation
[
0
]
->
mlp
.
predict
(
fd
);
for
(
unsigned
int
i
=
1
;
i
<
generation
.
size
();
i
++
)
{
auto
otherPred
=
generation
[
i
]
->
mlp
.
predict
(
fd
);
for
(
unsigned
int
j
=
0
;
j
<
prediction
.
size
();
j
++
)
prediction
[
j
]
+=
otherPred
[
j
];
}
for
(
unsigned
int
j
=
0
;
j
<
prediction
.
size
();
j
++
)
prediction
[
j
]
/=
generation
.
size
();
return
prediction
;
}
float
GeneticAlgorithm
::
update
(
FeatureModel
::
FeatureDescription
&
fd
,
int
gold
)
...
...
@@ -119,10 +131,12 @@ void GeneticAlgorithm::save(const std::string & filename)
fprintf
(
file
->
getDescriptor
(),
"%d %d %s
\n
"
,
nbInputs
,
nbOutputs
,
topology
.
c_str
());
delete
file
;
for
(
auto
&
individual
:
generation
)
unsigned
int
quarter
=
generation
.
size
()
/
4
;
for
(
unsigned
int
i
=
0
;
i
<
quarter
;
i
++
)
{
individual
->
mlp
.
saveStruct
(
filename
);
individual
->
mlp
.
saveParameters
(
filename
);
generation
[
i
]
->
mlp
.
saveStruct
(
filename
);
generation
[
i
]
->
mlp
.
saveParameters
(
filename
);
}
}
...
...
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