Skip to content

Instantly share code, notes, and snippets.

View zsunberg's full-sized avatar

Zachary Sunberg zsunberg

View GitHub Profile
@zsunberg
zsunberg / transmat.jl
Created October 29, 2018 18:14
Procedure to generate a transition matrix from an MDP
using POMDPs
using POMDPModelTools
function transition_matrix_a_s_sp(mdp::MDP)
na = n_actions(mdp)
ns = n_states(mdp)
mat = zeros(na, ns, ns) # this should be sparse
for a in actions(mdp)
ai = actionindex(mdp, a)
@zsunberg
zsunberg / gw_bench.jl
Created August 31, 2018 23:58
Grid world benchmark showing that the current julia compiler cannot handle multiple state types. Output for julia 1.0 at bottom.
using POMDPs
using POMDPModelTools
using POMDPSimulators
using POMDPPolicies
using StaticArrays
using Parameters
using Random
using BenchmarkTools
using POMDPModels
using Test
@zsunberg
zsunberg / simple_grid_world.jl
Last active August 30, 2018 22:19
A simpler verion of a grid world problem for POMDPs.jl
const Vec2 = SVector{2,Int}
const StateTypes = Union{Vec2, TerminalState}
@with_kw struct SimpleGridWorld <: MDP{StateTypes, Symbol}
size::Tuple{Int, Int} = (10,10)
rewards::Dict{Vec2, Float64} = Dict(Vec2(4,3)=>-10.0, Vec2(4,6)=>-5.0, Vec2(9,3)=>10.0, Vec2(8,8)=>3.0)
terminate_in::Set{Vec2} = Set((Vec2(4,3), Vec2(4,6), Vec2(9,3), Vec2(8,8)))
tprob::Float64 = 0.7
discount::Float64 = 0.95
end

AutoViz.jl

A package for rendering simple scenes primarily consisting of cars on roadways using Cairo.

Usage

The main function is

render(scene)
@zsunberg
zsunberg / create_points.py
Created November 28, 2017 18:38
PyJulia Example Use Case
import numpy as np
r = np.arange(1.0, 11.0, 0.1)
n = len(r)**3
pts = np.empty((n, 3))
i = 0
for x in r:
for y in r:
for z in r:
@zsunberg
zsunberg / pomdps_alloc_test.jl
Last active December 2, 2016 07:41
A script to test the effects of preallocating memory in POMDPs.jl
using POMDPs
import POMDPs: create_state, discount, reward
using POMDPToolbox
type ImageMDP <: MDP{Matrix{Int},Int}
size::Tuple{Int, Int}
end
create_state(mdp::ImageMDP) = Array(Int, mdp.size[1], mdp.size[2])
discount(::ImageMDP) = 0.9