Skip to content

Instantly share code, notes, and snippets.

JAVA_OPTIONS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n -Dweblogic.security.SSL.trustedCAKeyStore="/app/Oracle/Middleware/wlserver_10.3/server/lib/cacerts" ${JAVA_OPTIONS}"
export JAVA_OPTIONS
@kdubovikov
kdubovikov / pytorch.py
Last active November 8, 2019 14:41
PyTorch Example 1
import torch
from torch.autograd import Variable
import numpy as np
def rmse(y, y_hat):
"""Compute root mean squared error"""
return torch.sqrt(torch.mean((y - y_hat).pow(2).sum()))
def forward(x, e):
"""Forward pass for our fuction"""
@kdubovikov
kdubovikov / pytorch_optim.py
Last active June 15, 2017 21:56
PyTorch example 2
import torch
from torch.autograd import Variable
import numpy as np
def rmse(y, y_hat):
"""Compute root mean squared error"""
return torch.sqrt(torch.mean((y - y_hat).pow(2)))
def forward(x, e):
"""Forward pass for our fuction"""
@kdubovikov
kdubovikov / tf_example_1.py
Created June 18, 2017 06:16
TensorFlow example 1
import tensorflow as tf
def rmse(y, y_hat):
"""Compute root mean squared error"""
return tf.sqrt(tf.reduce_mean(tf.square((y - y_hat))))
def forward(x, e):
"""Forward pass for our fuction"""
# tensorflow has automatic broadcasting
# so we do not need to reshape e manually
@kdubovikov
kdubovikov / tensorboard.py
Created June 18, 2017 06:46
Tensorboard Example
import tensorflow as tf
import numpy as np
def rmse(y, y_hat):
"""Compute root mean squared error"""
return tf.sqrt(tf.reduce_mean(tf.square((y - y_hat))))
def forward(x, e):
"""Forward pass for our fuction"""
# tensorflow has automatic broadcasting
@kdubovikov
kdubovikov / pytorch_mnist.py
Created June 18, 2017 07:26
PyTorch MNIST example
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
from torch.autograd import Variable
# download and transform train dataset
train_loader = torch.utils.data.DataLoader(datasets.MNIST('../mnist_data',
download=True,
@kdubovikov
kdubovikov / tensorflow_mnist.py
Created June 18, 2017 07:29
TensorFlow MNIST example
import numpy as np
import tensorflow as tf
from tensorflow.contrib import learn
from tensorflow.contrib.learn.python.learn.estimators import model_fn as model_fn_lib
tf.logging.set_verbosity(tf.logging.INFO)
def cnn_model_fn(features, labels, mode):
@kdubovikov
kdubovikov / naive_sampling.py
Last active October 7, 2017 04:11
Naive random sampling with numpy
import timeit
import numpy as np
from collections import Counter
def get_sample(arr, n_iter=None, sample_size=10,
fast=True):
"""Get random sample from arr.
Parameters
----------
@kdubovikov
kdubovikov / fast_sampling.py
Last active October 8, 2017 11:56
Fast random subset sampling from large arrays
import timeit
import numpy as np
from collections import Counter
from tqdm import tqdm
def get_sample(arr, n_iter=None, sample_size=10,
fast=True):
"""Get random sample from arr.
Parameters
@kdubovikov
kdubovikov / fast_sampling_cython.pyx
Created October 8, 2017 10:22
Fast random subset sampling with Cython
%%cython
import numpy as np
cimport numpy as np
cimport cython # so we can use cython decorators
from cpython cimport bool # type annotation for boolean
# disable index bounds checking and negative indexing for speedups
@cython.wraparound(False)
@cython.boundscheck(False)
cdef cython_get_sample(np.ndarray arr, arr_len, n_iter, int sample_size,