Skip to content

Instantly share code, notes, and snippets.

@soumyasd
soumyasd / multi-ts-lstm.py
Created July 31, 2017 11:48 — forked from lukovkin/multi-ts-lstm.py
Time series prediction with multiple sequences input - LSTM - 1
# Time Series Testing
import keras.callbacks
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dense, Dropout
from keras.layers.recurrent import LSTM
# Call back to capture losses
class LossHistory(keras.callbacks.Callback):
def on_train_begin(self, logs={}):
self.losses = []
@soumyasd
soumyasd / resnet_all_conv.py
Created April 21, 2017 14:25 — forked from EderSantana/resnet_all_conv.py
Resnet + all conv implementation example
"""
Possibly correct implementation of an all conv neural network using a single residual module
This code was written for instruction purposes and no attempt to get the best results were made.
References:
Deep Residual Learning for Image Recognition: http://arxiv.org/pdf/1512.03385v1.pdf
STRIVING FOR SIMPLICITY, THE ALL CONVOLUTIONAL NET: http://arxiv.org/pdf/1412.6806v3.pdf
A video walking through the code and main ideas: https://youtu.be/-N_zlfKo4Ec
import math
import random
def get_random_neighbour(state):
neighbour = [house[:] for house in state] # Deep copy
i = random.randint(0, 4)
j = random.choice(range(0, i) + range(i+1, 4))
attr_idx = random.randint(0, 4)
@soumyasd
soumyasd / springer-free-maths-books.md
Created December 29, 2015 01:44 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links
@soumyasd
soumyasd / S3UploadStream.scala
Created December 21, 2015 01:02 — forked from th0br0/S3UploadStream.scala
play-s3 streaming upload
package lib
import fly.play.s3._
import java.io.OutputStream
import scala.concurrent.Future
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import play.api.http.ContentTypeOf
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.concurrent.Akka
@soumyasd
soumyasd / Db.scala
Created November 4, 2015 02:15 — forked from rodolfo42/Db.scala
How to use transactions with finagle-mysql
package transactions
import com.twitter.finagle.exp.mysql.{Client, OK, Result}
class Db(mysqlClient: Client) {
val insertOrder = "INSERT INTO orders (ref) VALUES(?)"
val insertOrderItem = "INSERT INTO order_items (order_id, item_id) VALUES(?, ?)"
def persistOrderWithItems[T](order: Order)(whenDone: (OK, Seq[Result]) => T): Future[T] = {
import java.net.{SocketOptions, Inet4Address, InetAddress, Socket}
import java.util.concurrent.TimeoutException
import akka.actor.{ActorRef, Props, ActorSystem}
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.ws._
import akka.io.Inet
import akka.routing.BroadcastGroup
class HttpClient {
def get(uri: URI): Future[String]
}
// return Future of next URI to get
def getUri(): Future[URI]
// return's available HttpClient from a pool
def getHttpClient(): Future[HttpClient]
#!/usr/bin/env scalas
/***
scalaVersion := "2.11.7"
libraryDependencies += "com.typesafe.play" %% "play-netty-server" % "2.4.1"
*/
import play.core.server._
import play.api.routing.sird._
import play.api.mvc._
/** Find the minimum amount of smoke (second) and resulting color (first)
by splitting the sequence at every possible position,
given `lookup` contains the best mix for subsequence. */
def minSmokeMixtureSingle(s: Seq[Int], lookup: Map[Seq[Int],(Int,Int)]): (Int,Int) =
if(s.size == 1)
(s(0),0)
else if(s.size == 2)
mix(s(0),s(1))
else {
val splits = (1 to (s.size - 1)).map(s.splitAt)