Skip to content

Instantly share code, notes, and snippets.

View karlnapf's full-sized avatar

Heiko Strathmann karlnapf

View GitHub Profile
import glob
from optparse import OptionParser
import os
import sys
from modshogun import SerializableAsciiFile, WrappedObjectArray
if __name__ == "__main__":
op = OptionParser()
/*
* -*- coding: utf-8 -*-
* vim: set fileencoding=utf-8
*
* Copyright (c) 2016, Shogun-Toolbox e.V. <shogun-team@shogun-toolbox.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@karlnapf
karlnapf / gamma_median_heuristic.py
Created January 22, 2016 11:00
Heuristc for choosing the bandwidth of a Gaussian kernel
def gamma_median_heuristic(Z, num_subsample=1000):
"""
Computes the median pairwise distance in a random sub-sample of Z.
Returns a \gamma for k(x,y)=\exp(-\gamma ||x-y||^2), according to the median heuristc,
i.e. it corresponds to \sigma in k(x,y)=\exp(-0.5*||x-y||^2 / \sigma^2) where
\sigma is the median distance. \gamma = 0.5/(\sigma^2)
"""
inds = np.random.permutation(len(Z))[:np.max([num_subsample, len(Z)])]
dists = squareform(pdist(Z[inds], 'sqeuclidean'))
median_dist = np.median(dists[dists > 0])
@karlnapf
karlnapf / MNST_kernel_exp_family.ipynb
Last active March 4, 2016 10:30
MNIST and kernel exponential family
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Welcome to Shogun-manual's documentation!

Contents:

<!DOCTYPE html>
<html>
<head>
<title>Shogun 4.0</title>
</head>
<body>
<p>
The Shogun team just released <a href="http://www.shogun-toolbox.org/new/41" target="_blank">version 4.0</a> of their community driven Machine Learning toolbox.
# A single Shogun program
This documents classififier_libsvm_probabilities.cpp.
Cool thing is we can use standard markdown to write the documentation while the source code can be executed. Another advantage is that not all source code is pasted at once. Rather, we can write little paragraphs in between, even including math.
## Include and initialisation
First, let's include the needed header files and initialise Shogun.
However, if this is not documented in this doxypage (one might not want to do that as it is standard), the code still is in the source file and thus can be executed and tested.
### Header includes
@karlnapf
karlnapf / gist:8ed7de163eed39e733da
Created August 19, 2014 03:12
custom random densities with PyMC3
{
"metadata": {
"name": "",
"signature": "sha256:5480489225e5331c5fb14f21f5cb3e8312909e64210905685b98b1b36a07e6f3"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"metadata": {
"name": "Gastby ML assignment 6"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{