Skip to content

Instantly share code, notes, and snippets.

View robotsorcerer's full-sized avatar
🙂

Lekan robotsorcerer

🙂
View GitHub Profile
@robotsorcerer
robotsorcerer / exp_replay.py
Created July 24, 2023 15:48
Experience replay
from collections import namedtuple
import random
# tree policy is the prior probability of the node that won
Transition = namedtuple('Transition',
('state', 'tree_policy', 'winner'))
class AgentMemory(object):
def __init__(self, max_cap):
"""
@robotsorcerer
robotsorcerer / msg_filters
Created July 19, 2023 20:34
Msg Filters Subscribers in ros 2
#!/usr/bin/env python3
__all__ = ["SubscribeRegress"]
import os
import sys
import time
import rospy
import logging
import pickle
@robotsorcerer
robotsorcerer / matlab_utils.py
Last active March 18, 2023 12:13
General Matlab Functions Defined in Python, Numpy, Scipy and Slycot
__all__ = [
"Bundle", "ZEROS_TYPE", "ONES_TYPE", "rad2deg", "deg2rad",
"realmin", "DEFAULT_ORDER", "mat_like_array", "index_array",
"quickarray", "ismember", "omin", "omax", "strcmp", "isbundle",
"isfield", "cputime","error", "realmax", "eps", "info","warn",
"debug", "length","size", "to_column_mat", "numel", "numDims",
"ndims", "expand", "ones", "zeros", "isvector", "isColumnLength",
"cell", "iscell", "isnumeric", "isfloat", "isscalar", "is_symmetric",
"precc", "succ", "psdpart", "kron", "check_shape", "sys_integrator",
"is_pos_def", "sympart", "place_varga", "place", "acker", "is_observable",
@robotsorcerer
robotsorcerer / class-kappa.m
Created June 10, 2021 13:05
A visualization of class-kappa functions
%% Class Kappa functions
% alpha = arctan(r) is a class kappa function
clc; close all
r = linspace(1, 1000);
alpha = atan(r);
subplot(221)
plot(alpha, 'LineWidth',3); hold on;
grid on;
xlabel('r'); ylabel('\alpha=tan^{-1}(r)')
title('Class \kappa function')
@robotsorcerer
robotsorcerer / KalmanFilter.py
Last active October 12, 2020 01:07
Simple Kalman filter implementation for a single state linear system.
from __future__ import print_function
'An easy implementation of the Kalman-Bucy Filter'
'Ref: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.361.6851&rep=rep1&type=pdf'
import rospy. # you don't have to use rospy
import numpy as np
# handle_soro_pose is a function wrapper around a ros service that retrieves sensor observations in real time.
from scripts.service_clinet import handle_soro_pose
<?xml version="1.0"?>
<Node name="DomeRingNode" gravity="0 -9.81 0" dt=".02">
<EulerImplicitSolver name="domeRing_cg_odesolver" printLog="false" />
<CGLinearSolver iterations="25" name="linear solver_dome_ring" tolerance="1.0e-9" threshold="1.0e-9" />
<!-- <MeshObjLoader name="dome_ring_loader" filename="../../../../ros/srs_traj_opt/patient_description/meshes/dome/dome_ring.obj" scale="1"/> -->
<MeshVTKLoader name="vtkDomeRingLoader" filename="../../../../ros/srs_traj_opt/patient_description/meshes/dome/dome_ring.vtu" />
<TetrahedronSetTopologyContainer name="TetraTopologyContainer_dome_ring" src="@vtkDomeRingLoader" />
<MechanicalObject name="dofs" src="@vtkDomeRingLoader" template="Vec3d" showIndices='false' showIndicesScale='4e-5' rx='0' dz='0'/>
<TetrahedronSetGeometryAlgorithms template="Vec3d" name="domeRing_TetraGeomAlgo" drawTetrahedra="1"/>
<TetrahedronSetTopologyAlgorithms template="Vec3d" name="domeRing_TetraTopologyAlgo" />
import numpy as np
"""
For details, see
[1] https://people.eecs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF
[2] https://docs.scipy.org/doc/numpy/reference/generated/numpy.around.html?highlight=round#numpy.around
Thanks to fesetround from ctypes. We can manually set the rounding mode
"""
import ctypes, sys
import os
import cupy as cp
import numpy as np
class chambollepock(object):
def __init__(self):
self.proxops = proxops()
self.variables = cpk_variables()
self.applyK = cpk_applyK()
self.optimizer = cpk_optimizer(self)
@robotsorcerer
robotsorcerer / mac_dev_setup.sh
Created August 15, 2018 03:45 — forked from captainsafia/mac_dev_setup.sh
A set of commands I use to configure my Mac for development
# Create a global gitignore for macOS
curl https://raw.githubusercontent.com/github/gitignore/master/Global/macOS.gitignore >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
# Send screenshots to a directory that isn't the desktop
mkdir -p ~/Screenshots
defaults write com.apple.screencapture location ~/Screenshots
# Show all hidden files (like dotfiles)
defaults write com.apple.finder AppleShowAllFiles YES; killall Finder;
import os
import copy
import time
import random
import h5py
import h5sparse
import logging
import numpy as np
from scipy.sparse import vstack