Skip to content

Instantly share code, notes, and snippets.

View NMZivkovic's full-sized avatar

Nikola Živković NMZivkovic

View GitHub Profile
def act(self, frame):
if np.random.rand() <= self.epsilon:
return self.enviroment.action_space.sample()
frame = np.expand_dims(np.asarray(frame).astype(np.float64), axis=0)
q_values = self.q_network.predict(frame)
return np.argmax(q_values[0])
def _build_compile_model(self):
model = Sequential()
model.add(Conv2D(32, 8, strides=(4, 4), padding="valid",activation="relu",
input_shape = self._image_shape))
model.add(Conv2D(64, 4, strides=(2, 2), padding="valid", activation="relu",
input_shape = self._image_shape))
model.add(Conv2D(64, 3, strides=(1, 1), padding="valid",activation="relu",
input_shape = self._image_shape))
model.add(Flatten())
model.add(Dense(512, activation="relu"))
def __init__(self, enviroment, optimizer, image_shape):
# Initialize atributes
self._action_size = enviroment.action_space.n
self._optimizer = optimizer
self._image_shape = image_shape
self.enviroment = enviroment
self.expirience_replay = deque(maxlen=100000)
class Agent(object):
def __init__(self, enviroment, optimizer, image_shape):
# Initialize atributes
self._action_size = enviroment.action_space.n
self._optimizer = optimizer
self._image_shape = image_shape
self.enviroment = enviroment
self.expirience_replay = deque(maxlen=100000)
enviroment.reset()
frames = []
for _ in range(NUMBER_OF_FRAMES):
enviroment.step(enviroment.action_space.sample())
frames.append(enviroment.ale.getScreenRGB())
img_processor.plot_frames(frames)
GAME_NAME = "BreakoutDeterministic-v4"
NUMBER_OF_FRAMES = 5
enviroment = gym.make(GAME_NAME).env
import numpy as np
import random
from collections import deque
import matplotlib.pyplot as plt
from PIL import Image
import imageio
import os
import gym
// Set the training algorithm
var trainer = mlContext.Regression.Trainers.FastTree(
new FastTreeRegressionTrainer.Options() {
NumberOfLeaves = 98,
MinimumExampleCountPerLeaf = 10,
NumberOfTrees = 500,
LearningRate = 0.07655732f,
Shrinkage = 0.2687001f,
LabelColumnName = "season",
FeatureColumnName = "Features"
static void Main(string[] args)
{
var regressors = new List<IEstimator<ITransformer>>()
{
_mlContext.Regression.Trainers.Sdca(labelColumnName: "Count", featureColumnName: "Features"),
_mlContext.Regression.Trainers.LbfgsPoissonRegression(labelColumnName: "Count", featureColumnName: "Features"),
_mlContext.Regression.Trainers.FastForest(labelColumnName: "Count", featureColumnName: "Features"),
_mlContext.Regression.Trainers.FastTree(labelColumnName: "Count", featureColumnName: "Features"),
_mlContext.Regression.Trainers.FastTreeTweedie(labelColumnName: "Count", featureColumnName: "Features"),
using BikeSharingDemand.Helpers;
using BikeSharingDemand.ModelNamespace;
using Microsoft.ML;
using System;
using System.Collections.Generic;
using System.Linq;
namespace BikeSharingDemand
{
class Program