Skip to content

Instantly share code, notes, and snippets.

@danoneata
danoneata / aggregate_tree.py
Last active August 29, 2015 14:08
Generates any segmentation from the base SLICs
"""Usage:
python aggregate_tree.py 500000
python aggregate_tree.py -3000
"""
from matplotlib import pyplot as plt
import numpy as np
import pdb
@danoneata
danoneata / fvecs_read.m
Created October 27, 2014 11:25
Reading fvecs format in MATLAB
% Read a set of vectors stored in the fvec format (int + n * float)
% The function returns a set of output vector (one vector per column)
%
% Syntax:
% v = fvecs_read (filename) -> read all vectors
% v = fvecs_read (filename, n) -> read n vectors
% v = fvecs_read (filename, [a b]) -> read the vectors from a to b (indices starts from 1)
function v = fvecs_read (filename, bounds)
% open the file and count the number of descriptors
@danoneata
danoneata / visitor_binary_operation.py
Last active November 20, 2015 12:53
Binary methods using the visitor pattern
class Expr(object):
def accept(self, visitor):
method_name = 'visit_{}'.format(self.__class__.__name__.lower())
visit = getattr(visitor, method_name)
return visit(self)
class Int(Expr):
def __init__(self, value):
@danoneata
danoneata / descs_to_sstats.py
Created April 12, 2016 21:45
Computing sufficient statistics for Fisher vectors
def descriptors_to_sufficient_statistics(xx, gmm, **kwargs):
# yael assumes that the data is in C-contiguous format.
xx = np.ascontiguousarray(np.atleast_2d(xx))
N = xx.shape[0]
K = gmm.k
D = gmm.d
# Compute posterior probabilities using yael.
Q = gmm_predict_proba(xx, gmm) # NxK
@danoneata
danoneata / Components.scala
Created March 3, 2017 09:57
Digital circuit simulator
/**
* Created by eurus on 28/02/2017.
*/
package components
import collection.immutable.Queue
import ActionType._
sealed trait SignalValue
object `0` extends SignalValue {
@danoneata
danoneata / sudoku.py
Created June 14, 2017 09:20
Skeleton code for Sudoku solver in Python
from typing import (
List,
TypeVar,
)
# Type aliases
A = TypeVar('A')
Digit = int
Matrix = List[List[A]]
Grid = Matrix[Digit]
@danoneata
danoneata / online_doc2vec.py
Created November 15, 2016 08:54
Online learning for Doc2Vec
import logging
from gensim.models.doc2vec import (
Doc2Vec,
TaggedDocument,
)
logging.basicConfig(
format='%(asctime)s : %(threadName)s : %(levelname)s : %(message)s',
level=logging.DEBUG,
@danoneata
danoneata / deep-learning-ai.md
Last active November 28, 2017 13:28
Deep Learning AI #1
@danoneata
danoneata / hodgp.py
Last active April 2, 2018 10:43
Python implemetation of Origami patterns
from functools import singledispatch
class Document:
pass
class Paragraph(Document):
def __init__(self, text):
self.text = text
@danoneata
danoneata / fisher_normalize.py
Created March 27, 2014 16:47
Fisher vector normalization
import numpy as np
def power_normalize(xx, alpha=0.5):
"""Computes a alpha-power normalization for the matrix xx."""
return np.sign(xx) * np.abs(xx) ** alpha
def L2_normalize(xx):
"""L2-normalizes each row of the data xx."""