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
// | |
// Created by Vladyslav Yazykov on 28/12/2018. | |
// | |
#ifndef BEZIER_POLYNOMIAL_H | |
#define BEZIER_POLYNOMIAL_H | |
#include <cstdlib> | |
#include <initializer_list> |
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
// | |
// Created by Vladyslav Yazykov on 17/12/2018. | |
// | |
#include <random> | |
#include "float.h" | |
namespace math { | |
template<int power> | |
struct TSign { |
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
using UnityEditor; | |
using UnityEngine; | |
namespace Shared.SingletonBehaviour { | |
/// <summary> | |
/// Singleton is not guaranteed to be initialized at OnValidate and Awake | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
[ExecuteInEditMode] | |
public class SingletonBehaviour<T> : MonoBehaviour where T : SingletonBehaviour<T> { |
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 visualizer import visualize | |
from YOUR_CLASSIFIER import YourClassifier | |
if __name__ == '__main__': | |
# Load data | |
model = G2Model(**data) | |
sample_size = int(2e4) | |
training_set = model.generate_sample(sample_size) | |
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 numpy as np | |
import torch | |
from torch.utils.data import SubsetRandomSampler, DataLoader | |
from time import sleep | |
from IPython.display import clear_output, display | |
import os | |
class Trainer: |
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 collections import namedtuple | |
import gym | |
import torch | |
env = gym.make('CartPole-v0') | |
obs_size = env.observation_space.shape[0] | |
num_actions = env.action_space.n |
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 torch.nn as nn | |
actor_hidden = 32 | |
actor = nn.Sequential(nn.Linear(state_size, actor_hidden), | |
nn.ReLU(), | |
nn.Linear(actor_hidden, num_actions), | |
nn.Softmax(dim=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
from torch.distributions import Categorical | |
def get_action(state): | |
state = torch.tensor(state).float().unsqueeze(0) # Turn state into a batch with a single element | |
dist = Categorical(actor(state)) # Create a distribution from probabilities for actions | |
return dist.sample().item() |
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
# Critic takes a state and returns its values | |
critic_hidden = 32 | |
critic = nn.Sequential(nn.Linear(obs_shape[0], critic_hidden), | |
nn.ReLU(), | |
nn.Linear(critic_hidden, 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
from torch.optim import Adam | |
critic_optimizer = Adam(critic.parameters(), lr=0.005) | |
def update_critic(advantages): | |
loss = .5 * (advantages ** 2).mean() | |
critic_optimizer.zero_grad() | |
loss.backward() |
OlderNewer