Skip to content

Instantly share code, notes, and snippets.

View kweimann's full-sized avatar

Kuba Weimann kweimann

  • Berlin, Germany
View GitHub Profile
@kweimann
kweimann / selfie-cifar10.ipynb
Last active December 1, 2019 18:40
"Selfie" - pretraining by solving jigsaw puzzles on CIFAR10 data set
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kweimann
kweimann / decision_tree.py
Last active December 3, 2018 20:47
Simple decision tree in Python for spam classification on spambase dataset
import numpy as np
import pandas as pd
import logging
class DTNode:
def __init__(self, feature, threshold):
self.feature = feature
self.threshold = threshold
self.left = None
@kweimann
kweimann / Implicits.scala
Created May 17, 2018 16:12
K smallest / largest elements in O(N * log(K)) complexity (N - size of the collection)
object implicits {
implicit class RichTraversable[A](traversable: Traversable[A]) {
// collect k smallest elements in O(n*log(k)) time (n - length of the list, k - size of the window)
def minK(k: Int)(implicit cmp: Ordering[A]): List[A] = {
if (k < 1) return List.empty
traversable
.foldLeft(mutable.PriorityQueue.empty) {
// window not filled yet so append current element
case (window, x) if window.size < k =>
window.enqueue(x)
@kweimann
kweimann / mastermind.py
Last active March 22, 2021 17:36
Mastermind board game (with guessing algorithm)
import random
class CodeMaker(object):
def make_code(self):
"""
code maker invents a secret code
"""
raise NotImplemented()
@kweimann
kweimann / em.py
Last active July 26, 2023 21:23
Expectation Maximization using Python and Numpy
import numpy as np
def em(x, n_clusters, eps):
n_examples, n_features = x.shape
last_log_estimate = None
mean = np.random.uniform(np.min(x, axis=0), np.max(x, axis=0), size=(n_clusters, n_features))
cov = [np.identity(n_features) for _ in range(n_clusters)]
p = np.full((n_clusters,), 1.0 / n_clusters)
@kweimann
kweimann / summarizingGraph.scala
Created February 21, 2016 17:47
Akka Streams exercise: custom streams & graph DSL
class Delayed[A](delay: FiniteDuration) extends GraphStage[FlowShape[A, A]] {
val in = Inlet[A]("Delayed.in")
val out = Outlet[A]("Delayed.out")
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new TimerGraphStageLogic(shape) {
var open = true
setHandler(in, new InHandler {
override def onPush(): Unit = {
push(out, grab(in))