Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
21-22J-056
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21-22J-056
21-22J-056
Commits
f722cc6b
Commit
f722cc6b
authored
Jan 12, 2022
by
Kaarunyan sritharan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simulate the dass
parent
72e3c7db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
simulate.py
simulate.py
+72
-0
No files found.
simulate.py
0 → 100644
View file @
f722cc6b
"""..."""
from
logic.states
import
init
,
progress
,
absorbing
,
verify_states
from
logic.ads
import
verify_ads
,
eligible_in_state
from
util.validate
import
verify
,
seq
,
prob
from
util.stats
import
describe
def
sample_impressibilites
(
impress_function_per_add
,
n
):
"""
:param impress_function_per_add: dictionary of functions for each ad that will
sample impressibility for given user numbers
:param n: number of users to sample for
"""
imp
=
{
ad
:
f
(
n
)
for
ad
,
f
in
impress_function_per_add
.
items
()}
verify
(
seq
(
seq
(
prob
)),
list
(
imp
.
values
()))
return
imp
def
streams
(
states
,
ads
,
impress
,
n
=
10
):
"""Generate n streams based on states
:param states: dictionary as defined verify_states
:param ads: dictionary as defined in verify_ads
:param impress: input function for sample_impressibilites
:param n: number of streams"""
verify_states
(
states
)
verify_ads
(
ads
)
# impressibility per ad per user
impress_ad_user
=
sample_impressibilites
(
impress
,
n
)
absorbing_states
=
absorbing
(
states
)
streams_all_users
=
[]
views_all_users
=
[]
for
user
in
range
(
n
):
state
=
init
(
states
)
# current state
stream
=
[
state
]
# names of states user traverses
views
=
[]
# ad views as (ad,index)
i
=
0
while
state
not
in
absorbing_states
:
# pick first ad eligible in current state
ad_options
=
eligible_in_state
(
ads
,
states
[
'names'
][
state
])
if
ad_options
:
ad
=
ad_options
[
0
]
ad_name
=
ads
[
'names'
][
ad
]
# If user targeted by ad type?"
# print(ad, user, impress_ad_user)
if
impress_ad_user
[
ad_name
][
user
]
>=
ads
[
'min_impress'
][
ad
]:
views
.
append
((
ad_name
,
i
))
state
=
progress
(
state
,
states
)
stream
.
append
(
state
)
i
+=
1
streams_all_users
.
append
(
stream
)
views_all_users
.
append
(
views
)
views_stats
=
describe
(
list
(
map
(
len
,
views_all_users
)))
return
{
'stats'
:
{
'users'
:
n
,
'views'
:
views_stats
},
'streams'
:
streams_all_users
,
'views'
:
views_all_users
,
'impressibilities'
:
impress_ad_user
}
Write
Preview
Markdown
is supported
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