This file contains 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
#http://www.svcl.ucsd.edu/courses/ece161c/handouts/DCT.pdf | |
import numpy as np | |
import matplotlib.pyplot as plt | |
pi = np.pi | |
N = 50 # timesteps | |
k = 10 # n basis functions |
This file contains 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 keras.backend as K | |
import numpy as np | |
def gaussian_nll(ytrue, ypreds): | |
"""Keras implmementation of multivariate Gaussian negative loglikelihood loss function. | |
This implementation implies diagonal covariance matrix. | |
Parameters | |
---------- |
This file contains 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 count_conv_params_flops(conv_layer, verbose=1): | |
# out shape is n_cells_dim1 * (n_cells_dim2 * n_cells_dim3) | |
out_shape = conv_layer.output.shape.as_list() | |
n_cells_total = np.prod(out_shape[1:-1]) | |
n_conv_params_total = conv_layer.count_params() |
This file contains 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 os | |
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | |
PROJECT_DIR = os.path.dirname(SCRIPT_DIR) | |
LOG_DIR = os.path.join(PROJECT_DIR, 'logs') |
This file contains 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
def random_number_generator(arg1, arg2): | |
""" | |
Summary line. | |
Extended description of function. | |
Parameters | |
---------- | |
arg1 : int | |
Description of arg1 |
This file contains 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
def sample_dball_uniform(n_points=1000, n_dims=3): | |
"""Sample uniformly from d-dimensional ball | |
The code is inspired by this small note: | |
https://blogs.sas.com/content/iml/2016/04/06/generate-points-uniformly-in-ball.html | |
https://www.sciencedirect.com/science/article/pii/S0047259X10001211 | |
Parameters | |
---------- | |
n_points : int |
This file contains 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 hist_pdf(x, data, n_bins=10, minv=None, maxv=None): | |
"""Histogram density estimator | |
[minv, minv+delta, , minv+delta*2, ..., 1] | |
for any x in B_l=[minv+delta*j, minv+delta*(j+1)] density is estimated in the following way | |
p(x) = p(x | x \in B_l) * p(x \in B_l) = (1/delta) * (\sum_{x_j}{I(x_j \in B_l)} / N) |
This file contains 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
#!/usr/bin/env python | |
# coding: utf-8 | |
# In[32]: | |
import numpy as np | |
def hist_pdf(x, data, n_bins=10, minv=None, maxv=None): | |
"""Histogram density estimator |
This file contains 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
def is_permuted_palindrome(s): | |
"""Checks if the string is a permuted version of a palindrome | |
Upper case do not matter, spaces can be ignored. | |
Example: | |
"cat cat" -> Yes (palindrome: "cat tac") | |
"cat do" -> No | |
This file contains 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
def set_bit(x, i): | |
bi = 0b1 << i | |
return x | bi | |
def xor_bit(x, i): | |
bi = 0b1 << i | |
return x ^ bi | |
def clear_bit(x, i): | |
bi = ~(0b1 << i) |
OlderNewer