Skip to content

Commit

Permalink
feature/fix-style-with-pre-commit-all-files
Browse files Browse the repository at this point in the history
* Fix style in docs files with pre-commit
* Fix style in all python files with pre-commit
  • Loading branch information
dariodandrea committed Oct 16, 2023
1 parent 579355b commit 026b4c4
Show file tree
Hide file tree
Showing 14 changed files with 1,243 additions and 97 deletions.
26 changes: 13 additions & 13 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
import os
import sys

sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))


# -- Project information -----------------------------------------------------

project = 'PyBandits'
copyright = 'MIT License'
author = ''
project = "PyBandits"
copyright = "MIT License"
author = ""

# The full version, including alpha/beta/rc tags
release = '1.0'
release = "1.0"


# -- General configuration ---------------------------------------------------
Expand All @@ -32,15 +32,15 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'nbsphinx',
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.mathjax",
"nbsphinx",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -58,9 +58,9 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# A list of ignored prefixes for module index sorting.
modindex_common_prefix = ['pybandits.']
modindex_common_prefix = ["pybandits."]

nbsphinx_allow_errors = True
10 changes: 5 additions & 5 deletions docs/src/tutorials/cmab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"n_samples = 1000\n",
"n_features = 5\n",
"X = 2 * np.random.random_sample((n_samples, n_features)) - 1 # random float in the interval (-1, 1)\n",
"print('X: context matrix of shape (n_samples, n_features)')\n",
"print(\"X: context matrix of shape (n_samples, n_features)\")\n",
"print(X[:10])"
]
},
Expand All @@ -97,7 +97,7 @@
"outputs": [],
"source": [
"# define actions\n",
"actions_ids= ['action A', 'action B', 'action C']"
"actions_ids = [\"action A\", \"action B\", \"action C\"]"
]
},
{
Expand Down Expand Up @@ -140,8 +140,8 @@
],
"source": [
"# predict action\n",
"pred_actions, _ = cmab.predict(X) \n",
"print('Recommended action: {}'.format(pred_actions[:10]))"
"pred_actions, _ = cmab.predict(X)\n",
"print(\"Recommended action: {}\".format(pred_actions[:10]))"
]
},
{
Expand All @@ -167,7 +167,7 @@
"source": [
"# simulate reward from environment\n",
"simulated_rewards = np.random.randint(2, size=n_samples)\n",
"print('Simulated rewards: {}'.format(simulated_rewards[:10]))"
"print(\"Simulated rewards: {}\".format(simulated_rewards[:10]))"
]
},
{
Expand Down
27 changes: 11 additions & 16 deletions docs/src/tutorials/simulation_cmab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"n_groups = 3\n",
"n_updates = 5\n",
"n_jobs = 1\n",
"actions_ids = ['action A', 'action B', 'action C']\n",
"actions_ids = [\"action A\", \"action B\", \"action C\"]\n",
"n_features = 5\n",
"verbose = True"
]
Expand All @@ -66,11 +66,9 @@
"outputs": [],
"source": [
"# init context matrix and groups\n",
"X, group = make_classification(n_samples=batch_size*n_updates,\n",
" n_features=n_features, \n",
" n_informative=n_features,\n",
" n_redundant=0,\n",
" n_classes=n_groups)"
"X, group = make_classification(\n",
" n_samples=batch_size * n_updates, n_features=n_features, n_informative=n_features, n_redundant=0, n_classes=n_groups\n",
")"
]
},
{
Expand Down Expand Up @@ -155,10 +153,10 @@
],
"source": [
"# init probability of rewards from the environment\n",
"prob_rewards = pd.DataFrame([[0.05, 0.80, 0.05],\n",
" [0.80, 0.05, 0.05],\n",
" [0.80, 0.05, 0.80]], columns=actions_ids, index=range(n_groups))\n",
"print('Probability of positive reward for each group/action:') \n",
"prob_rewards = pd.DataFrame(\n",
" [[0.05, 0.80, 0.05], [0.80, 0.05, 0.05], [0.80, 0.05, 0.80]], columns=actions_ids, index=range(n_groups)\n",
")\n",
"print(\"Probability of positive reward for each group/action:\")\n",
"prob_rewards"
]
},
Expand Down Expand Up @@ -203,12 +201,9 @@
],
"source": [
"# init simulation\n",
"sim = SimulationCmab(cmab=cmab, X=X, \n",
" group=group, \n",
" batch_size=batch_size, \n",
" n_updates=n_updates,\n",
" prob_rewards=prob_rewards, \n",
" verbose=verbose)"
"sim = SimulationCmab(\n",
" cmab=cmab, X=X, group=group, batch_size=batch_size, n_updates=n_updates, prob_rewards=prob_rewards, verbose=verbose\n",
")"
]
},
{
Expand Down
14 changes: 8 additions & 6 deletions docs/src/tutorials/simulation_smab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"outputs": [],
"source": [
"# define actions\n",
"action_ids = ['Action A', 'Action B', 'Action C']"
"action_ids = [\"Action A\", \"Action B\", \"Action C\"]"
]
},
{
Expand Down Expand Up @@ -70,11 +70,13 @@
"outputs": [],
"source": [
"# init simulation\n",
"sim = SimulationSmab(smab=smab,\n",
" n_updates=20,\n",
" batch_size=2000,\n",
" probs_reward={'Action A': 0.6, 'Action B': 0.5, 'Action C': 0.8},\n",
" verbose=True)"
"sim = SimulationSmab(\n",
" smab=smab,\n",
" n_updates=20,\n",
" batch_size=2000,\n",
" probs_reward={\"Action A\": 0.6, \"Action B\": 0.5, \"Action C\": 0.8},\n",
" verbose=True,\n",
")"
]
},
{
Expand Down
18 changes: 6 additions & 12 deletions docs/src/tutorials/smab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"outputs": [],
"source": [
"# define actions\n",
"action_ids = ['Action A', 'Action B', 'Action C']"
"action_ids = [\"Action A\", \"Action B\", \"Action C\"]"
]
},
{
Expand All @@ -67,13 +67,9 @@
"outputs": [],
"source": [
"# define beta priors parameters\n",
"success_priors = {'Action A': 1,\n",
" 'Action B': 1,\n",
" 'Action C': 1}\n",
"success_priors = {\"Action A\": 1, \"Action B\": 1, \"Action C\": 1}\n",
"\n",
"failure_priors = {'Action A': 1,\n",
" 'Action B': 1,\n",
" 'Action C': 1}"
"failure_priors = {\"Action A\": 1, \"Action B\": 1, \"Action C\": 1}"
]
},
{
Expand All @@ -90,9 +86,7 @@
"outputs": [],
"source": [
"# init stochastic Multi-Armed Bandit model\n",
"smab = Smab(action_ids=action_ids, \n",
" success_priors=success_priors,\n",
" failure_priors=failure_priors)"
"smab = Smab(action_ids=action_ids, success_priors=success_priors, failure_priors=failure_priors)"
]
},
{
Expand All @@ -118,7 +112,7 @@
"source": [
"# predict actions\n",
"pred_actions, _ = smab.predict(n_samples=1000)\n",
"print('Recommended action: {}'.format(pred_actions[:10]))"
"print(\"Recommended action: {}\".format(pred_actions[:10]))"
]
},
{
Expand Down Expand Up @@ -149,7 +143,7 @@
"for a in action_ids:\n",
" n_successes[a] = random.randint(0, pred_actions.count(a))\n",
" n_failures[a] = pred_actions.count(a) - n_successes[a]\n",
" print('{}: n_successes={}, n_failures={}'.format(a, n_successes[a], n_failures[a]))"
" print(\"{}: n_successes={}, n_failures={}\".format(a, n_successes[a], n_failures[a]))"
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/cmab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"n_samples = 1000\n",
"n_features = 5\n",
"X = 2 * np.random.random_sample((n_samples, n_features)) - 1 # random float in the interval (-1, 1)\n",
"print('X: context matrix of shape (n_samples, n_features)')\n",
"print(\"X: context matrix of shape (n_samples, n_features)\")\n",
"print(X[:10])"
]
},
Expand All @@ -97,7 +97,7 @@
"outputs": [],
"source": [
"# define actions\n",
"actions_ids= ['action A', 'action B', 'action C']"
"actions_ids = [\"action A\", \"action B\", \"action C\"]"
]
},
{
Expand Down Expand Up @@ -140,8 +140,8 @@
],
"source": [
"# predict action\n",
"pred_actions, _ = cmab.predict(X) \n",
"print('Recommended action: {}'.format(pred_actions[:10]))"
"pred_actions, _ = cmab.predict(X)\n",
"print(\"Recommended action: {}\".format(pred_actions[:10]))"
]
},
{
Expand All @@ -167,7 +167,7 @@
"source": [
"# simulate reward from environment\n",
"simulated_rewards = np.random.randint(2, size=n_samples)\n",
"print('Simulated rewards: {}'.format(simulated_rewards[:10]))"
"print(\"Simulated rewards: {}\".format(simulated_rewards[:10]))"
]
},
{
Expand Down
Loading

0 comments on commit 026b4c4

Please sign in to comment.