This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for-each for tuples | |
namespace std { | |
template<int I, class Tuple, typename F> struct for_each_impl { | |
static void for_each(const Tuple& t, F f) { | |
for_each_impl<I - 1, Tuple, F>::for_each(t, f); | |
f(get<I>(t)); | |
} | |
}; | |
template<class Tuple, typename F> struct for_each_impl<0, Tuple, F> { | |
static void for_each(const Tuple& t, F f) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3 ~/bin/matlab2013a/sys/os/glnxa64/libgfortran.so.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults write com.apple.dashboard mcx-disabled -boolean YES && killall Dock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double randn(double mean, double sigma) | |
{ | |
gsl_rng *gnr = gsl_rng_alloc(gsl_rng_default); | |
return mean + gsl_ran_gaussian(gnr, sigma); | |
gsl_rng_free(gnr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cfloat> | |
#include <armadillo> | |
using namespace arma; | |
/** | |
* K-means algorithm | |
* @param K the number of clusters | |
* @param means cluster centers | |
* @param counts sizes of clusters | |
* @param resps assignments to clusters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec generate_gmm(size_t N, const vec &mean, const vec &stddev, const vec &weights) | |
{ | |
vec result(N); | |
const size_t K = weights.size(); | |
size_t filled = 0; | |
for (size_t k = 0; k < K; ++k) | |
{ | |
size_t size_k = weights(k) * N; | |
result.subvec(filled, filled + size_k - 1) = mean(k) + randn(size_k) * stddev(k); | |
filled += size_k; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename Iterator> | |
typename std::iterator_traits<Iterator>::value_type | |
median(Iterator _start, Iterator _end) | |
{ | |
typedef typename std::iterator_traits<Iterator>::value_type value_t; | |
std::vector<value_t> low; | |
std::vector<value_t> high; | |
high.push_back(*_start); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// convert an OpenCV multi-channel matrix to Armadillo cube. A copy is made | |
template <typename T, int NC> | |
Cube<T> to_arma(const cv::Mat_<cv::Vec<T, NC>> &src) | |
{ | |
vector<cv::Mat_<T>> channels; | |
Cube<T> dst(src.cols, src.rows, NC); | |
for (int c = 0; c < NC; ++c) | |
channels.push_back({src.rows, src.cols, dst.slice(c).memptr()}); | |
cv::split(src, channels); | |
return dst; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dirent.h> | |
vector<string> list_dir(const string &path) | |
{ | |
vector<string> result; | |
dirent *pdir; | |
DIR *dir = opendir(path.c_str()); // open current directory | |
while (pdir = readdir(dir)) | |
result.push_back(pdir->d_name); | |
closedir(dir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctime> | |
using namespace std; | |
inline std::string date_string() | |
{ | |
time_t rawtime; | |
std::time(&rawtime); | |
struct tm *tinfo = std::localtime(&rawtime); | |
char buffer[12]; |