Skip to content

Instantly share code, notes, and snippets.

@bklebel
bklebel / OxfordAdapters.py
Last active September 16, 2021 07:24
pymeasure VISA-Adapter for OxfordInstruments PS 120-10
from pymeasure.adapters import VISAAdapter
from pyvisa.errors import VisaIOError
import re
import logging
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
@bklebel
bklebel / processors.py
Last active August 15, 2018 08:39
MultiInputProcessor for keras-rl without window_length
import numpy as np
from rl.core import Processor
from rl.util import WhiteningNormalizer
class MultiInputProcessor(Processor):
"""Converts observations from an environment with multiple observations for use in a neural network
policy.
In some cases, you have environments that return multiple different observations per timestep
(in a robotics context, for example, a camera may be used to view the scene and a joint encoder may
@bklebel
bklebel / cartpole_multidict.py
Last active October 14, 2019 15:59
Cartpole Example for dictionary observation spaces, using keras-rl
import math
import gym
from gym import spaces, logger
from gym.utils import seeding
import numpy as np
class CartPoleMultidictEnv(gym.Env):
metadata = {
@bklebel
bklebel / MultiInputProcessor.py
Last active September 6, 2019 09:29
Keras model using multiple separate inputs to separate networks - working with keras-rl
class MultiInputProcessor(Processor):
"""Converts observations from an environment with multiple observations for use in a neural network
policy.
In some cases, you have environments that return multiple different observations per timestep
(in a robotics context, for example, a camera may be used to view the scene and a joint encoder may
be used to report the angles for each joint). Usually, this can be handled by a policy that has
multiple inputs, one for each modality. However, observations are returned by the environment
in the form of a tuple `[(modality1_t, modality2_t, ..., modalityn_t) for t in T]` but the neural network
expects them in per-modality batches like so: `[[modality1_1, ..., modality1_T], ..., [[modalityn_1, ..., modalityn_T]]`.