Skip to content

Instantly share code, notes, and snippets.

@darkseed
darkseed / pearson.scala
Last active September 18, 2015 09:42 — forked from tbertelsen/pearson.scala
Calculating pearson for Breeze vectors
import breeze.linalg._
import breeze.stats._
import scala.math.sqrt
/**
* Effecient for sparse vectors. Scales in O(activeSize)
*/
// Must take SparseVector, for implicits to be linked correctly
def pearson(a: SparseVector[Double], b: SparseVector[Double]): Double = {
@darkseed
darkseed / combinations.scala
Last active September 18, 2015 09:36 — forked from kaja47/combinations.scala
Fast array combinations
// genrate all combinations of integers in range from 0 to `len`-1
// fast as fuck
def combIdxs(len: Int, k: Int): Iterator[Array[Int]] = {
val arr = Array.range(0, k)
arr(k-1) -= 1
val end = k-1
Iterator.continually {
arr(end) += 1
if (arr(end) >= len) {
@darkseed
darkseed / gist:e9e77731b9750e1416c8
Last active September 18, 2015 09:36 — forked from kaja47/gist:554f62c61f21b0420720
minhash vs. HyperLogLog
// min-hash
val fs: Vector[Int => Int] // hash funkce
items map { it => fs map { f => f(it) } } fold (vectorPairwise(min), initialValue = Vector.fill(infinity))
// HyperLogLog
@darkseed
darkseed / svd-img.scala
Last active September 18, 2015 09:35 — forked from kaja47/svd-img.scala
Visualization of truncated SVD
import breeze._
import breeze.linalg._
import breeze.numerics._
import java.awt.image.BufferedImage
import javax.imageio.ImageIO
val f = ???
val img = javax.imageio.ImageIO.read(new File(f))
val gray = new BufferedImage(img.getWidth, img.getHeight, BufferedImage.TYPE_BYTE_GRAY)
val g = gray.createGraphics()
@darkseed
darkseed / csfdsim.scala
Last active September 18, 2015 09:30 — forked from kaja47/csfdsim.scala
How to compute similar movies from CSFD data in 10 minutes and find love of your life
import breeze.linalg._
import breeze.stats
import breeze.numerics._
val dataFile = new File(???)
val userItems: Array[SparseVector[Double]] = loaderUserItemsWithRatings(dataFile, """[ ,:]""".r)
val itemUsers: Array[SparseVector[Double]] = transpose(userItems) map { vec => normalize(vec, 2) }
// weights
val N = DenseVector.fill[Double](itemIndex.size)(userIndex.size) // vector where total numbers of users is repeated
@darkseed
darkseed / gist:612194e0e9e74745fc79
Last active September 18, 2015 09:20 — forked from yu-iskw/gist:4e0d3a2f999effbcf640
A weighted Euclidean distance function implementation
package breeze.linalg.functions
import breeze.generic.UFunc
import breeze.linalg.{SparseVector, DenseVector}
import breeze.numerics.sqrt
/**
* A weighted Euclidean distance function implementation
*/
object weightedEuclideanDistance extends UFunc {
@darkseed
darkseed / gatlingClusterRun.sh
Last active September 7, 2015 10:41 — forked from Nimrod007/gatlingClusterRun.sh
Gatling - running on multiple machines and aggregating the results
#!/bin/bash
##################################################################################################################
#Gatling scale out/cluster run script:
#Before running this script some assumptions are made:
#1) Public keys were exchange inorder to ssh with no password promot (ssh-copy-id on all remotes)
#2) Check read/write permissions on all folders declared in this script.
#3) Gatling installation (GATLING_HOME variable) is the same on all hosts
#4) Assuming all hosts has the same user name (if not change in script)
##################################################################################################################
@darkseed
darkseed / deepdream-install.md
Last active September 1, 2015 19:29 — forked from robertsdionne/deepdream-install.md
Deepdream installation
#!/usr/bin/env bash

# Assuming OS X Yosemite 10.10.4

# Install XCode and command line tools
# See https://itunes.apple.com/us/app/xcode/id497799835?mt=12#
# See https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html
xcode-select --install
@darkseed
darkseed / CorsSupport.scala
Last active August 29, 2015 14:28 — forked from joseraya/CorsSupport.scala
CORS directive for Spray
package com.agilogy.spray.cors
import spray.http.{HttpMethods, HttpMethod, HttpResponse, AllOrigins}
import spray.http.HttpHeaders._
import spray.http.HttpMethods._
import spray.routing._
// see also https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
trait CORSSupport {
this: HttpService =>
@darkseed
darkseed / nnet_plot_update.r
Last active August 29, 2015 14:26 — forked from fawda123/nnet_plot_update.r
nnet_plot_update
plot.nnet<-function(mod.in,nid=T,all.out=T,all.in=T,bias=T,wts.only=F,rel.rsc=5,
circle.cex=5,node.labs=T,var.labs=T,x.lab=NULL,y.lab=NULL,
line.stag=NULL,struct=NULL,cex.val=1,alpha.val=1,
circle.col='lightblue',pos.col='black',neg.col='grey',
bord.col='lightblue', max.sp = F,...){
require(scales)
#sanity checks
if('mlp' %in% class(mod.in)) warning('Bias layer not applicable for rsnns object')