Skip to content

Instantly share code, notes, and snippets.

@tklein23
tklein23 / gist:7188804
Created October 27, 2013 22:43
StreamingSparseFeatures.ipynb
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@tklein23
tklein23 / memleaking-apply_binary.py
Created November 5, 2013 18:23
Memory leak in python modular interface
#!/usr/bin/env python
import modshogun
import scipy
import scipy.sparse
import numpy
import time
import resource
@tklein23
tklein23 / memleaking-apply_binary.py
Last active December 27, 2015 13:29
Output of `valgrind --leak-check=full python ./memleaking-apply_binary.py`
==14757== 200,000 bytes in 50,000 blocks are definitely lost in loss record 2,435 of 2,455
==14757== at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14757== by 0x9255CD6: operator new(unsigned long) (memory.cpp:103)
==14757== by 0x9275583: shogun::SGReferencedData::SGReferencedData(bool) (SGReferencedData.cpp:15)
==14757== by 0x9346BCD: shogun::SGSparseVector<double>::SGSparseVector() (SGSparseVector.cpp:9)
==14757== by 0x925B5F0: shogun::SGSparseVector<double>* shogun::sg_generic_malloc<shogun::SGSparseVector<double> >(unsigned long) (memory.cpp:422)
==14757== by 0x748DDC7: bool spmatrix_from_numpy<double>(shogun::SGSparseMatrix<double>&, _object*, int) (modshogunPYTHON_wrap.cxx:6769)
==14757== by 0x70C0D6F: _wrap_new_SparseRealFeatures__SWIG_2 (modshogunPYTHON_wrap.cxx:426582)
==14757== by 0x70C186B: _wrap_new_SparseRealFeatures (modshogunPYTHON_wrap.cxx:426782)
==14757== by 0x4AE24D: ??? (in /home/tklein/ipython-notebooks/ipy/bin/python)
@tklein23
tklein23 / DualLibQPBMSOSVMNCBM_unittest.cc
Created January 28, 2014 22:41
Example for numerical problems in libncbm.cpp (not terminating)
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2014 Thoralf Klein
*/
#include <shogun/lib/config.h>
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2014 Thoralf Klein
*/
#include <shogun/lib/config.h>
@tklein23
tklein23 / MultilabelLabelsIO.cpp
Created March 13, 2014 21:43
SHOGUN: MultilabelLabels::save() and MultilabelLabels::load()
// The following includes are only needed for save() and load()
#include <string>
#include <iostream>
#include <fstream>
#include <limits>
void
CMultilabelLabels::save(const char * fname)
{
FILE * fh = fopen(fname, "wb");
@tklein23
tklein23 / build-before-pr.sh
Last active August 29, 2015 13:57
Small shell script that can be used to compile SHOGUN Machine Learning Toolbox http://www.shogun-toolbox.org/ before sending a pull request
#!/bin/bash
# Taken from: https://gist.github.com/tklein23/9730737
set -ex
NUM_CORES=$(grep '^processor\s*:\s*' /proc/cpuinfo |wc -l)
NUM_JOBS=$((NUM_CORES+3))
BUILDDIR="$(pwd)/build-before-pr"
// your model should provide a method how to create an "own" structured labels object.
CStructuredLabels* MultilabelSOModel::structured_labels_factory(int32_t num_labels)
{
return new MultilabelSOModel(num_labels);
}
@tklein23
tklein23 / file_input.cpp
Last active August 29, 2015 14:02
Loading SVMlight file using streaming API
/*
* Written (W) 2013 Thoralf Klein <thoralf.klein@zib.de>
* Copyright (C) 2013 Zuse-Institute-Berlin (ZIB)
* Copyright (C) 2013 Thoralf Klein
*/
#include <shogun/io/streaming/StreamingAsciiFile.h>
#include <shogun/features/streaming/StreamingSparseFeatures.h>
#include <shogun/lib/SGVector.h>
/*
* Written (W) 2013 Thoralf Klein <thoralf.klein@zib.de>
* Copyright (C) 2013 Zuse-Institute-Berlin (ZIB)
* Copyright (C) 2013 Thoralf Klein
*/
#include <shogun/lib/Hash.h>
#include <shogun/lib/SGSparseVector.h>
#include <shogun/lib/SGSparseMatrix.h>