Added kernel svm algorithm code file - #12784
Conversation
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| class BanditAlgorithm(ABC): | ||
| """Base class for bandit algorithms""" | ||
|
|
||
| def __init__(self, n_arms): |
There was a problem hiding this comment.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: n_arms
| self.n_arms = n_arms | ||
| self.reset() | ||
|
|
||
| def reset(self): |
There was a problem hiding this comment.
Please provide return type hint for the function: reset. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/Multi-Armed Bandits .py, please provide doctest for the function reset
| self.t = 0 | ||
|
|
||
| @abstractmethod | ||
| def select_arm(self): |
There was a problem hiding this comment.
Please provide return type hint for the function: select_arm. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/Multi-Armed Bandits .py, please provide doctest for the function select_arm
| def select_arm(self): | ||
| pass | ||
|
|
||
| def update(self, arm, reward): |
There was a problem hiding this comment.
Please provide return type hint for the function: update. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: arm
Please provide type hint for the parameter: reward
As there is no test file in this pull request nor any test function or class in the file machine_learning/Multi-Armed Bandits .py, please provide doctest for the function update
| class EpsilonGreedy(BanditAlgorithm): | ||
| """Epsilon-Greedy Algorithm""" | ||
|
|
||
| def __init__(self, n_arms, epsilon=0.1): |
There was a problem hiding this comment.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: n_arms
Please provide type hint for the parameter: epsilon
| probs = exp_prefs / np.sum(exp_prefs) | ||
| return np.random.choice(self.n_arms, p=probs) | ||
|
|
||
| def update(self, arm, reward): |
There was a problem hiding this comment.
Please provide return type hint for the function: update. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: arm
Please provide type hint for the parameter: reward
As there is no test file in this pull request nor any test function or class in the file machine_learning/Multi-Armed Bandits .py, please provide doctest for the function update
| class BanditTestbed: | ||
| """Environment for testing bandit algorithms""" | ||
|
|
||
| def __init__(self, n_arms=10, true_rewards=None): |
There was a problem hiding this comment.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: n_arms
Please provide type hint for the parameter: true_rewards
| self.true_rewards = true_rewards | ||
| self.optimal_arm = np.argmax(self.true_rewards) | ||
|
|
||
| def get_reward(self, arm): |
There was a problem hiding this comment.
Please provide return type hint for the function: get_reward. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: arm
As there is no test file in this pull request nor any test function or class in the file machine_learning/Multi-Armed Bandits .py, please provide doctest for the function get_reward
| """Get noisy reward for pulling an arm""" | ||
| return np.random.normal(self.true_rewards[arm], 1) | ||
|
|
||
| def run_experiment(self, algorithm, n_steps=1000): |
There was a problem hiding this comment.
Please provide return type hint for the function: run_experiment. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: algorithm
Please provide type hint for the parameter: n_steps
As there is no test file in this pull request nor any test function or class in the file machine_learning/Multi-Armed Bandits .py, please provide doctest for the function run_experiment
|
|
||
|
|
||
| # Example usage and comparison | ||
| def compare_algorithms(): |
There was a problem hiding this comment.
Please provide return type hint for the function: compare_algorithms. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/Multi-Armed Bandits .py, please provide doctest for the function compare_algorithms
Describe your change:
Checklist: