Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/lematt1991/RecLab into le…
Browse files Browse the repository at this point in the history
…matt1991-master
  • Loading branch information
Karl-Krauth committed Jun 28, 2021
2 parents b55832f + 7ba212a commit f02cfa7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,28 @@ which will install both the core reclab framework and the benchmark recommendati
### Example
The code below shows a simple use-case with random recommendations.
```python
import numpy as np
import reclab
env = reclab.make('topics-dynamic-v1')
items, users, ratings = env.reset()
for _ in range(1000):
online_users = env.online_users()
# Your recommendation algorithm here. This recommends 10 random items to each online user.
recommendations = np.random.choice(items, size=(len(online_users), 10))
items, users, ratings, info = env.step(recommendations)
n_users = 1000
n_topics = 10
n_items = 20
env = reclab.make(
"topics-dynamic-v1",
num_topics=n_topics,
num_users=n_users,
num_items=n_items,
num_init_ratings=n_users * n_topics,
)
users, items, ratings = env.reset()
assert len(users) == n_users
assert len(items) == n_items
for _ in range(1):
online_users = env.online_users
# Your recommendation algorithm here.
# This recommends 2 random items to each online user.
recommendations = np.random.choice(
len(items), size=(len(online_users), 2)
)
users, items, ratings, info = env.step(recommendations)

env.close()
```

Expand Down
34 changes: 34 additions & 0 deletions tests/test_simple_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Test the basic example found in the README
"""
import numpy as np
import reclab


def test_basic_example():
"""
Test the basic example in the READMe
"""
n_users = 1000
n_topics = 10
n_items = 20
env = reclab.make(
'topics-dynamic-v1',
num_topics=n_topics,
num_users=n_users,
num_items=n_items,
num_init_ratings=n_users * n_topics,
)
users, items, _ = env.reset()
assert len(users) == n_users
assert len(items) == n_items
for _ in range(1):
online_users = env.online_users
# Your recommendation algorithm here.
# This recommends 2 random items to each online user.
recommendations = np.random.choice(
len(items), size=(len(online_users), 2)
)
users, items, _, _ = env.step(recommendations)

env.close()

0 comments on commit f02cfa7

Please sign in to comment.