Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon
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
Container registry
Model registry
Operate
Environments
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
Franck Dary
macaon
Commits
dadc0e9a
Commit
dadc0e9a
authored
4 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Entropy is divided by states
parent
7be95e0f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
reading_machine/src/Action.cpp
+52
-6
52 additions, 6 deletions
reading_machine/src/Action.cpp
with
52 additions
and
6 deletions
reading_machine/src/Action.cpp
+
52
−
6
View file @
dadc0e9a
...
@@ -188,9 +188,30 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
...
@@ -188,9 +188,30 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
{
{
auto
apply
=
[
colName
,
lineIndex
,
addition
](
Config
&
config
,
Action
&
)
auto
apply
=
[
colName
,
lineIndex
,
addition
](
Config
&
config
,
Action
&
)
{
{
std
::
string
totalStr
=
config
.
getLastNotEmptyHypConst
(
colName
,
lineIndex
).
get
();
if
(
totalStr
.
empty
()
||
totalStr
==
"_"
)
totalStr
=
fmt
::
format
(
"{}={}|{}"
,
config
.
getState
(),
0.0
,
0
);
auto
byStates
=
util
::
split
(
totalStr
,
','
);
int
index
=
-
1
;
for
(
unsigned
int
i
=
0
;
i
<
byStates
.
size
();
i
++
)
{
auto
state
=
util
::
split
(
byStates
[
i
],
'='
)[
0
];
if
(
state
==
config
.
getState
())
{
index
=
i
;
break
;
}
}
if
(
index
==
-
1
)
{
byStates
.
emplace_back
(
fmt
::
format
(
"{}={}|{}"
,
config
.
getState
(),
0.0
,
0
));
index
=
byStates
.
size
()
-
1
;
}
// Knuth’s algorithm for online mean
// Knuth’s algorithm for online mean
auto
curStr
=
config
.
getLastNotEmptyHypConst
(
colName
,
lineIndex
).
get
();
auto
splited
=
util
::
split
(
util
::
split
(
byStates
[
index
],
'='
)[
1
],
'|'
);
auto
splited
=
util
::
split
(
curStr
,
'|'
);
float
curVal
=
0.0
;
float
curVal
=
0.0
;
int
curNb
=
0
;
int
curNb
=
0
;
if
(
splited
.
size
()
==
2
)
if
(
splited
.
size
()
==
2
)
...
@@ -203,14 +224,37 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
...
@@ -203,14 +224,37 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
float
delta
=
addition
-
curVal
;
float
delta
=
addition
-
curVal
;
curVal
+=
delta
/
curNb
;
curVal
+=
delta
/
curNb
;
config
.
getLastNotEmptyHyp
(
colName
,
lineIndex
)
=
fmt
::
format
(
"{}|{}"
,
curVal
,
curNb
);
byStates
[
index
]
=
fmt
::
format
(
"{}={}|{}"
,
config
.
getState
(),
curVal
,
curNb
);
config
.
getLastNotEmptyHyp
(
colName
,
lineIndex
)
=
util
::
join
(
","
,
byStates
);
};
};
auto
undo
=
[
colName
,
lineIndex
,
addition
](
Config
&
config
,
Action
&
)
auto
undo
=
[
colName
,
lineIndex
,
addition
](
Config
&
config
,
Action
&
)
{
{
std
::
string
totalStr
=
config
.
getLastNotEmptyHypConst
(
colName
,
lineIndex
).
get
();
if
(
totalStr
.
empty
()
||
totalStr
==
"_"
)
totalStr
=
fmt
::
format
(
"{}={}|{}"
,
config
.
getState
(),
0.0
,
0
);
auto
byStates
=
util
::
split
(
totalStr
,
','
);
int
index
=
-
1
;
for
(
unsigned
int
i
=
0
;
i
<
byStates
.
size
();
i
++
)
{
auto
state
=
util
::
split
(
byStates
[
i
],
'='
)[
0
];
if
(
state
==
config
.
getState
())
{
index
=
i
;
break
;
}
}
if
(
index
==
-
1
)
{
byStates
.
emplace_back
(
fmt
::
format
(
"{}={}|{}"
,
config
.
getState
(),
0.0
,
0
));
index
=
byStates
.
size
()
-
1
;
}
// Knuth’s algorithm for online mean
// Knuth’s algorithm for online mean
auto
curStr
=
config
.
getLastNotEmptyHypConst
(
colName
,
lineIndex
).
get
();
auto
splited
=
util
::
split
(
util
::
split
(
byStates
[
index
],
'='
)[
1
],
'|'
);
auto
splited
=
util
::
split
(
curStr
,
'|'
);
float
curVal
=
0.0
;
float
curVal
=
0.0
;
int
curNb
=
0
;
int
curNb
=
0
;
if
(
splited
.
size
()
==
2
)
if
(
splited
.
size
()
==
2
)
...
@@ -222,7 +266,9 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
...
@@ -222,7 +266,9 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
curNb
-=
1
;
curNb
-=
1
;
curVal
=
(
curNb
*
curVal
-
addition
)
/
(
curNb
-
1
);
curVal
=
(
curNb
*
curVal
-
addition
)
/
(
curNb
-
1
);
config
.
getLastNotEmptyHyp
(
colName
,
lineIndex
)
=
fmt
::
format
(
"{}|{}"
,
curVal
,
curNb
);
byStates
[
index
]
=
fmt
::
format
(
"{}={}|{}"
,
config
.
getState
(),
curVal
,
curNb
);
config
.
getLastNotEmptyHyp
(
colName
,
lineIndex
)
=
util
::
join
(
","
,
byStates
);
};
};
auto
appliable
=
[
colName
,
lineIndex
,
addition
](
const
Config
&
config
,
const
Action
&
)
auto
appliable
=
[
colName
,
lineIndex
,
addition
](
const
Config
&
config
,
const
Action
&
)
...
...
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