Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gamarcad
Samba Demonstration
Commits
b8f3e537
Commit
b8f3e537
authored
Jan 11, 2022
by
gamarcad
Browse files
Addition of table in the message for the approximated probabilities
parent
481659ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
samba-app/src/app/samba/action-text/action-text.component.html
View file @
b8f3e537
<div
*ngIf=
"execution && execution.history"
>
Exact Probabilities:
<ul>
<li
*ngFor=
"let prob of execution.history.probs; let index=index"
>
DO{{index}}: {{formatProb(execution.history.probs[index])}}
</li>
</ul>
<!-- Table containing the exact probs and their approximations for each arm-->
<table
id=
"probs"
>
<tr>
<td></td>
<td>
Exact
</td>
<td>
Approx
</td>
</tr>
<tr
*ngFor=
"let prob of execution.history.probs; let index=index"
>
<td>
DO{{index}}
</td>
<td>
{{formatProb(execution.history.probs[index])}}
</td>
<td>
{{getApproximatedProbability(index)}}
</td>
</tr>
</table>
</div>
<span>
{{text}}
</span>
samba-app/src/app/samba/action-text/action-text.component.scss
View file @
b8f3e537
#probs
{
width
:
100%
;
tr
{
font-weight
:
bold
;
}
}
samba-app/src/app/samba/action-text/action-text.component.ts
View file @
b8f3e537
...
...
@@ -10,6 +10,7 @@ import {SambaChapter, SambaState} from "../state";
export
class
ActionTextComponent
implements
OnInit
,
OnChanges
{
text
:
string
;
approximatedProbability
:
number
[]
|
undefined
@
Input
()
execution
:
Execution
|
undefined
;
constructor
()
{
this
.
text
=
""
}
...
...
@@ -19,9 +20,34 @@ export class ActionTextComponent implements OnInit, OnChanges {
}
ngOnChanges
(
changes
:
SimpleChanges
):
void
{
// When a changes occur, the text must be updated as well as the
// approximated probabilities for each arm.
this
.
updateText
();
}
/**
* Returns the aproximated probability of the given arm index.
* @param armIndex
*/
getApproximatedProbability
(
armIndex
:
number
)
:
string
{
// if the current execution is not defined, abort the computation
if
(
!
this
.
execution
||
!
this
.
execution
.
currentTurn
)
return
"
-
"
// if the current chapter is not for the computation, skip it
if
(
this
.
execution
.
chapter
!=
SambaChapter
.
CORE_OF_PROTO
)
return
"
-
"
// compute the number of pulls and the number of rewards
let
numberOfPulls
=
this
.
execution
.
currentTurn
.
nb_pulls
[
armIndex
]
let
numberOfRewars
=
this
.
execution
.
currentTurn
.
nb_rewards
[
armIndex
]
return
(
numberOfRewars
/
numberOfPulls
).
toFixed
(
2
)
}
/**
* Update the displayed text explaining the action done in the inteface.
* @private
*/
private
updateText
()
{
if
(
this
.
execution
==
undefined
)
{
this
.
text
=
""
...
...
@@ -30,6 +56,12 @@ export class ActionTextComponent implements OnInit, OnChanges {
this
.
text
=
this
.
getMessage
(
this
.
execution
.
chapter
,
this
.
execution
.
state
)
}
/**
* Returns the "humanized" description of the current state.
* @param chapter
* @param state
* @private
*/
private
getMessage
(
chapter
:
SambaChapter
,
state
:
SambaState
)
:
string
{
switch
(
chapter
)
{
case
SambaChapter
.
BEGIN
:
return
""
...
...
@@ -55,12 +87,6 @@ export class ActionTextComponent implements OnInit, OnChanges {
throw
new
Error
(
"
Message not generated
"
)
}
formatProbs
(
probs
:
number
[])
{
return
probs
.
map
((
value
=>
{
return
value
.
toFixed
(
2
)
}))
}
formatProb
(
prob
:
number
)
{
return
prob
.
toFixed
(
2
)
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment