Skip to content

Instantly share code, notes, and snippets.

@silgon
silgon / gist:e6998ed93592ce476d1a
Created June 12, 2015 14:35
IRL with chainMDP
#! /usr/bin/python
"""
Simple example for IRL based on apprenticeship learning
"""
from __future__ import print_function
import numpy as np
def linearMDP(S=5, goal=3):
"""
@silgon
silgon / gist:615e1afe95129682b908
Created June 14, 2015 15:18
TEXI2DVI tilde error
This is an excellent tool when you're compiling latex files. Nevertheless, there's a bug when you insert a tilde as a nbsp. Something that needs to be modified in ''/usr/bin/texi2dvi'', and that's this part of code ''catcode_special=true'' to''catcode_special=false''. After that, a nice example for your latex file is:
texi2dvi --pdf --clean --verbose --batch file.tex
@silgon
silgon / least_squares.py
Last active November 12, 2017 18:17
Basic Least Squares Implementation with pseudo inverse
"""
Basic Least Squares Implementation with pseudo inverse
"""
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
t = np.linspace(0, 3, 20) # horizontal axis
x = np.array([3, 0, 4]) # a,b,c of f(t)=a+b*t+c*t^2
f = lambda t, x: x[0]+x[1]*t+x[2]*t**2 # f(t)
@silgon
silgon / 2d_curve_fit.py
Last active October 5, 2024 12:56
Python curve_fit function with 2d data
# curvefit with non linear least squares (curve_fit function)
import numpy as np
from scipy.optimize import curve_fit
def func(x, a, b, c):
return a*np.sin(x[0])+b*np.cos(x[1])+c
limits = [0, 2*np.pi, 0, 2*np.pi] # [x1_min, x1_max, x2_min, x2_max]
side_x = np.linspace(limits[0], limits[1], 100)
side_y = np.linspace(limits[2], limits[3], 100)
@silgon
silgon / hmm_sampling_fitting.py
Created October 9, 2015 11:47
hmmlearn extended sampling fitting example
"""
this is an extended version of http://hmmlearn.github.io/hmmlearn/auto_examples/plot_hmm_sampling.html#example-plot-hmm-sampling-py
sampling as in the example, then fitting data to another model (with also 4 variables) and then doing some scoring with
the same model and also with a mixture of gaussians
"""
import numpy as np
import matplotlib.pyplot as plt
from hmmlearn import hmm

Installation of IPOPT on LINUX

NOTE: this page is for a from-source install (useful if you want to contribute to CasADi). If you just want to evaluate CasADi quickly, use a binary install.

  • To get started quickly, start off by grabbing as many dependencies as possible from repositories.
  • Ubuntu: sudo apt-get install gcc g++ gfortran git cmake liblapack-dev pkg-config --install-recommends
  • Fedora: sudo yum install gcc gcc-c++ gcc-gfortran git cmake lapack-devel
  • To compile the Python interface, you also need SWIG and a decent Python installation:
  • Ubuntu: sudo apt-get install swig ipython python-dev python-numpy python-scipy python-matplotlib --install-recommends
  • Fedora: sudo yum install swig ipython python-devel numpy scipy python-matplotlib
@silgon
silgon / boost_log_example.cpp
Created December 10, 2015 23:09
Boost Log example with channel and file generation.
// compile with
// g++ -std=c++11 test_log_default.cpp -DBOOST_LOG_DYN_LINK -lboost_log -lboost_thread -lpthread -lboost_system
#include <iostream>
#include <boost/log/expressions.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/sinks.hpp>
@silgon
silgon / find_peaks.cpp
Created January 26, 2016 16:05
Eigen Find Peaks C++
Eigen::ArrayXXb findPeaks(Eigen::ArrayXXd &M, unsigned int &footprint_size){
Eigen::ArrayXXb result = Eigen::ArrayXXb::Zero(M.rows(), M.cols());
bool tmp_max;
bool quit_for=false;
for(int i = footprint_size; i<M.rows()-footprint_size; ++i){
for(int j = footprint_size; j<M.cols()-footprint_size; ++j){
tmp_max=true;
for(int ii=i-footprint_size; ii<i+footprint_size;++ii){
for(int jj=j-footprint_size; jj<j+footprint_size;++jj){
if(ii==i && jj==j)
@silgon
silgon / distance_angle_pose_to_point.cpp
Last active March 21, 2024 02:59
Get distance and angle of the closest obstacle from pose and map
#include <ros/ros.h>
#include <nav_msgs/OccupancyGrid.h>
#include <geometry_msgs/PoseStamped.h>
#include <tf/tf.h>
#include <tf/transform_listener.h>
#include <iterator>
#include <vector>
// some definitions of functions
#define MAP_INDEX(map, i, j) ((i) + (j) * map.size_x)
@silgon
silgon / write_read_json.jl
Last active April 18, 2024 01:31
How to Read and Write JSON files in julia
import JSON
###################
### Write data ####
###################
# dictionary to write
dict1 = Dict("param1" => 1, "param2" => 2,
"dict" => Dict("d1"=>1.,"d2"=>1.,"d3"=>1.))
# pass data as a json string (how it shall be displayed in a file)
stringdata = JSON.json(dict1)