Skip to content

Instantly share code, notes, and snippets.

View lorenzoriano's full-sized avatar

Lorenzo Riano lorenzoriano

  • Industrial Next
  • San Francisco
View GitHub Profile
@lorenzoriano
lorenzoriano / test_ambiguous_lr.py
Created November 15, 2017 01:18
Tests an ambiguous problem with Linear Regression
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
import numpy as np
NSAMPLE=5000
x_data = np.float32(np.random.uniform(-10.5, 10.5, (1, NSAMPLE))).T
r_data = np.float32(np.random.normal(size=(NSAMPLE,1)))
y_data = np.float32(np.sin(0.75*x_data)*7.0+x_data*0.5+r_data*1.0)
x_data, y_data = y_data, x_data #swap x and y
@lorenzoriano
lorenzoriano / test_linear_regression.py
Last active November 14, 2017 23:14
Test Linear Regression in Python
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
import numpy as np
intercept = -2.0
beta = 5.0
n_samples = 1000
regularization = 1e30
X = np.random.normal(size=(n_samples,1))
@lorenzoriano
lorenzoriano / find_system_python_dylibs.sh
Created January 7, 2016 16:57
This script prints the filenames of any dylibs that depend on the System Python, and changes them
#!/bin/bash
#echo "This script prints the filenames of any dylibs in your /opt/ros/indigo/lib that depend on the System Python"
echo "This script prints the filenames of any dylibs in your /usr/local/ that depend on the System Python"
#for f in `find /usr/local/lib`; do
for f in `find /opt/ros/indigo/lib`; do
otool -L "$f" 2> /dev/null| grep Python | grep System &> /dev/null
status=$?
if [ $status -eq 0 ]; then
echo "$status: $f"
@lorenzoriano
lorenzoriano / config
Last active January 4, 2016 09:39
Terminator Config ~/.config/terminator/config
[global_config]
focus = mouse
[keybindings]
toggle_zoom = F12
next_tab = <Shift>Right
split_vert = <Ctrl><Shift>l
split_horiz = <Ctrl><Shift>b
prev_tab = <Shift>Left
[profiles]
[[default]]
import numpy as np
from scipy import optimize
from matplotlib import pyplot as plt, cm, colors
def calc_R(x,y, xc, yc):
""" calculate the distance of each 2D points from the center (xc, yc) """
return np.sqrt((x-xc)**2 + (y-yc)**2)
def f(c, x, y):
""" calculate the algebraic distance between the data points and the mean circle centered at c=(xc, yc) """
@lorenzoriano
lorenzoriano / trapez_profile.py
Last active February 11, 2018 21:09
Trapezoidal velocity profile function, handles special cases too
def trapez_profile(t, accel, vel_max, v_start, v_end, t_total):
"""Trapezoidal velocity profile function, handles special cases too
Parameters:
t: current time
accel: the maximum acceleration (and deceleration) of the system
vel_max: the maximum velocity
v_start: the starting velocity
v_end: the desired ending velocity
t_toal: how long should the motion be
import numpy as np
from math import pi, log
import pylab
from scipy import fft, ifft
from scipy.optimize import curve_fit
i = 10000
x = np.linspace(0, 3.5 * pi, i)
y = (0.3*np.sin(x) + np.sin(1.3 * x) + 0.9 * np.sin(4.2 * x) + 0.06 *
np.random.randn(i))
@lorenzoriano
lorenzoriano / change_transforms.py
Last active December 19, 2015 21:48
Creates ROS frame transformations on the fly, adapted from John Schulman code
#!/usr/bin/python
from numpy import *
from traitsui.key_bindings import KeyBinding,KeyBindings
from traitsui.api import *
from traits.api import *
import numpy as np
import roslib
roslib.load_manifest("sensor_msgs")
roslib.load_manifest("rospy")
roslib.load_manifest("tf")
static const double _PI= 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348;
static const double _TWO_PI= 6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696;
// Floating-point modulo
// The result (the remainder) has same sign as the divisor.
// Similar to matlab's mod(); Not similar to fmod() - Mod(-3,4)= 1 fmod(-3,4)= -3
template<typename T>
T Mod(T x, T y)
{
static_assert(!std::numeric_limits<T>::is_exact , "Mod: floating-point type expected");
@lorenzoriano
lorenzoriano / linspace.cpp
Last active December 12, 2022 02:28 — forked from jmbr/linspace.cpp
C++ Analogous of Python linspace, returns a std::vector
template <typename T>
std::vector<T> linspace(T a, T b, size_t N) {
T h = (b - a) / static_cast<T>(N-1);
std::vector<T> xs(N);
typename std::vector<T>::iterator x;
T val;
for (x = xs.begin(), val = a; x != xs.end(); ++x, val += h)
*x = val;
return xs;
}