Skip to content

Instantly share code, notes, and snippets.

View rmsander's full-sized avatar

Ryan Sander rmsander

View GitHub Profile
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import WhiteKernel, DotProduct, RBF
import matplotlib.pyplot as plt
import numpy as np
# Random seeds
np.random.seed(seed=0) # Set seed for NumPy
random_state = 0
# Generate features, and take norm for use with target
@rmsander
rmsander / data_fusion_constructor_sampler_only.py
Last active September 6, 2021 14:18
Module for implementing an Audi Autonomous Driving Dataset (A2D2) DataLoader designed for performing data fusion betweeen 2D RGB images and 3D Lidar point clouds.
"""Module for implementing an Audi Autonomous Driving Dataset (A2D2) DataLoader
designed for performing data fusion betweeen 2D RGB images and 3D Lidar point clouds."""
import numpy as np
from torch.utils.data import Dataset
class A2D2DataLoader(Dataset):
def __init__(self, dataset, rotation=None, \
normalize_xyz=True, normalize_rgb=True, \
take_subset=False, convert_to_tensor=True, \
target_ids=[]):
@rmsander
rmsander / data_fusion_full.py
Last active September 6, 2021 14:20
Module for implementing an Audi Autonomous Driving Dataset (A2D2) DataLoader designed for performing data fusion betweeen 2D RGB images and 3D Lidar point clouds. This is the FULL class.
"""Module for implementing an Audi Autonomous Driving Dataset (A2D2) DataLoader
designed for performing data fusion betweeen 2D RGB images and 3D Lidar point clouds.
This is the FULL class."""
import torch
import torch.nn as nn
from torch.utils.data import Dataset, DataLoader
import numpy as np
import os
import matplotlib.pyplot as plt
import cv2 as cv
@rmsander
rmsander / gen_reward_surface.py
Last active September 6, 2021 18:58
Functions and script to generate a reward surface with state and action inputs. Configured for the Pendulum-v0 Gym environment.
"""Functions and script to generate a reward surface with state and
action inputs. Configured for the Pendulum-v0 Gym environment."""
import gym
import matplotlib.pyplot as plt
import numpy as np
# Parameters
SAMPLES = 50
SEED = 42
import matplotlib.pyplot as plt
import numpy as np
p_values = [1, 1.5, 2]
labels = ["Lasso (L=1)", "ElasticNet (L=1.5)", "Ridge (L=2)"]
xx, yy = np.meshgrid(np.linspace(-3, 3, num=101), np.linspace(-3, 3, num=101))
fig, axes = plt.subplots(ncols=3, figsize=(28, 7))
for p, ax, l in zip(p_values, axes.flat, labels):
if p == 0:
zz = (xx != 0).astype(int) + (yy != 0).astype(int)
"""Tester script for GPyTorch using analytic sine functions."""
import torch
import numpy as np
import matplotlib.pyplot as plt
import time
from sklearn.metrics import mean_squared_error as mse
def main():
""" Class object and functions for creating, training, and evaluating PPO agents
using the TensorFlow Agents API. """
# Native Python imports
import os
import argparse
from datetime import datetime
import pickle
# TensorFlow and tf-agents
import gym
import gym_multi_car_racingenv = gym.make("MultiCarRacing-v0", num_agents=2, direction='CCW',
use_random_direction=True, backwards_flag=True,
h_ratio=0.25, use_ego_color=False)
obs = env.reset()
done = False
total_reward = 0
while not done:
# The actions have to be of the format (num_agents,3)
# The action format for each car is as in the CarRacing env.
"""Wrapper placed around Gym Environments enabling easier multi-agent
reinforcement learning. Compatible with single-agent RL environments as well."""
import tensorflow as tf
import numpy as np
class ObservationWrapper:
""" Class for stacking and processing frame observations.
"""
def train_gp_batched_scalar(Zs, Ys, use_cuda=False, epochs=10,
lr=0.1, thr=0, use_ard=False, composite_kernel=False,
ds=None, global_hyperparams=False,
model_hyperparams=None):
"""Computes a Gaussian Process object using GPyTorch. Each outcome is
modeled as a single scalar outcome.
Parameters:
Zs (np.array): Array of inputs of expanded shape (B, N, XD), where B is
the size of the minibatch, N is the number of data points in each