This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from stable_baselines3.common.env_util import make_atari_env | |
from stable_baselines3.common.vec_env import VecFrameStack | |
from stable_baselines3 import A2C | |
# There already exists an environment generator | |
# that will make and wrap atari environments correctly. | |
# Here we are also multi-worker training (n_envs=4 => 4 environments) | |
env = make_atari_env('BreakoutNoFrameskip-v4', n_envs=16) | |
# Frame-stacking with 4 frames | |
env = VecFrameStack(env, n_stack=4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
from stable_baselines3 import PPO | |
# Parallel environments | |
#env = make_vec_env("LunarLander-v2", n_envs=8) | |
# Create environment | |
env = gym.make('LunarLander-v2') | |
# Instantiate the agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from stable_baselines3 import PPO | |
from stable_baselines3.common.env_util import make_vec_env | |
# Parallel environments | |
env = make_vec_env("CartPole-v1", n_envs=4) | |
model = PPO("MlpPolicy", env, verbose=1) | |
model.learn(total_timesteps=25000) | |
model.save("ppo_cartpole") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from stable_baselines3 import PPO | |
import gym | |
env = gym.make("CartPole-v1") | |
model = PPO(policy = "MlpPolicy",env = env, verbose=1) | |
model.learn(total_timesteps=25000) | |
model.save("ppo_cartpole") # saving the model to ppo_cartpole.zip | |
model = PPO.load("ppo_cartpole") # loading the model from ppo_cartpole.zip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from stable_baselines3 import PPO | |
import gym | |
# Parallel environments | |
env = gym.make("CartPole-v1") | |
model = PPO(policy = "MlpPolicy",env = env, verbose=1) | |
model.learn(total_timesteps=25000) | |
obs = env.reset() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# making an instance of a neuron | |
neuron = Perceptron(input_size = 3, learning_rate = 0.05) | |
#training samples | |
X_train = np.array([[1,0,0,1,1,0,1,0], | |
[0,1,0,1,0,1,1,0], | |
[0,0,1,0,1,1,1,0]] ) | |
#training label | |
y_train = np.array([ 1, 0, 0, 1, 1, 0, 1, 0]) | |
#test sample | |
X_test = np.array([[1], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Neuron: | |
def __init__(self,input_size, learning_rate): | |
self.w = np.random.random((input_size,1))-0.5 # self.w is a 2 dimensional column vector | |
self.b = np.random.random(1)-0.5 | |
self.learning_rate = learning_rate | |
#forward pass | |
def forward(self,x): | |
a = x.T.dot(self.w) + self.b | |
return a | |
def loss(self,x,y): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Neuron: | |
def __init__(self,input_size, learning_rate): | |
self.w = np.random.random((input_size,1))-0.5 # self.w is a 2 dimensional column vector | |
self.b = np.random.random(1)-0.5 | |
self.learning_rate = learning_rate | |
#forward pass | |
def forward(self,x): | |
y_hat = x.T.dot(self.w) + self.b | |
return y_hat | |
def loss(self,x,y): |