Skip to content

Instantly share code, notes, and snippets.

@krzentner
krzentner / normal_gamma_estimator.py
Last active July 3, 2021 07:12
Estimate the mean and variance of a Normal distribution
from dataclasses import dataclass
import numpy as np
def bayesian_update(x: np.ndarray,
k: int, mu: float, alpha: float, beta: float):
"""
Graphical model is like this:
tau ~ IGa(alpha, beta)
x_i ~ N(mu, tau)
{
"$type": "garage.experiment.local_runner.LocalRunner",
"_algo": {
"$type": "garage.torch.algos.pearl.PEARL",
"_batch_size": 256,
"_context_replay_buffers": {
"0": {
"$type": "garage.replay_buffer.path_buffer.PathBuffer",
"_buffer": {},
"_capacity": 1000000,
@krzentner
krzentner / pickled_call.py
Created November 15, 2018 19:13
A picklable type that calls a function when unpickled.
class PickledCall:
def __new__(cls, to_call, args=(), kwargs=None, __pickle_target=None):
if __pickle_target is None:
result = super(cls, PickledCall).__new__(cls)
result.to_call = to_call
result.args = args
result.kwargs = kwargs or {}
return result
else:
return __pickle_target(*args, **kwargs)
@krzentner
krzentner / configure_with.py
Last active October 27, 2018 17:11
Decorator to avoid writing out field names twice.
#!/usr/bin/env python3
import copy
import types
def configure_with(config_type):
'''
Attach a configuration type to the provided type.
This will allow calling instances of the configuration type to construct
instances of the provided type, by copying fields from the configuration
object.