Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |
This file contains hidden or 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
import random | |
class CodeMaker(object): | |
def make_code(self): | |
""" | |
code maker invents a secret code | |
""" | |
raise NotImplemented() |
This file contains hidden or 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
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) |
This file contains hidden or 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
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)) |