Skip to content

Instantly share code, notes, and snippets.

@serser
serser / gpu_availability_test.py
Created December 12, 2018 08:12
Use gpu for tf computation when available
import unittest
import tensorflow as tf
import sys
import os
class TestGPU(unittest.TestCase):
def setUp(self):
os.environ["CUDA_VISIBLE_DEVICES"]='0'
def test_gpu(self):
@serser
serser / singleton_property_setter.py
Created December 12, 2018 08:08
change multiple properties on setter with singleton
import functools
def singleton(cls, *args, **kw):
instances = dict()
@functools.wraps(cls)
def _fun():
if cls not in instances:
instances[cls] = cls(*args, **kw)
return instances[cls]
return _fun
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# ------------
# https://classroom.udacity.com/courses/cs373/lessons/48736210/concepts/486838410923
# ------------
# User Instructions
#
# In this problem you will implement a more manageable
# version of graph SLAM in 2 dimensions.
#
# Define a function, online_slam, that takes 5 inputs:
# data, N, num_landmarks, motion_noise, and
# ------------
# User Instructions
#
# In this problem you will implement SLAM in a 2 dimensional
# world. Please define a function, slam, which takes five
# parameters as input and returns the vector mu. This vector
# should have x, y coordinates interlaced, so for example,
# if there were 2 poses and 2 landmarks, mu would look like:
#
# mu = matrix([[Px0],
# Landmark constraints are set in the same way as the robot positions.
# i.e.,
# x0 - l0 = -z0
# -x0 + l0 = z0
# https://classroom.udacity.com/courses/cs373/lessons/48696626/concepts/486966250923
# -----------
# User Instructions
#
# Modify your doit function to incorporate 3
# distance measurements to a landmark(Z0, Z1, Z2).
# The program incrementally apply constraints into matrix omega and vector xi.
# The final estimation of robot position is thus given by
# mu = omega.inverse() * xi
# notice the steps
#
# [1, 0, 0] -> [init]
#
# [1, -1, 0] -> [-move1]
# [-1, 1, 0] -> [move1]
# so on and so forth.
# In this example, localization (particle filter), planning (A*, smooth), control (PID)
# are put all altogether to make a real robot run from init to goal.
#
# https://classroom.udacity.com/courses/cs373/lessons/48696626/concepts/484039410923
# -----------
# User Instructions
#
# Familiarize yourself with the code below. Most of it
# reproduces results that you have obtained at some
# point in this class. Once you understand the code,
# -------------
# User Instructions
#
# Now you will be incorporating fixed points into
# your smoother.
#
# You will need to use the equations from gradient
# descent AND the new equations presented in the
# previous lecture to implement smoothing with
# fixed points.
# https://classroom.udacity.com/courses/cs373/lessons/48721468/concepts/487421890923
# -------------
# User Instructions
#
# Here you will be implementing a cyclic smoothing
# algorithm. This algorithm should not fix the end
# points (as you did in the unit quizzes). You
# should use the gradient descent equations that
# you used previously.
#