Skip to content

Instantly share code, notes, and snippets.

View pavlin-policar's full-sized avatar

Pavlin Poličar pavlin-policar

View GitHub Profile
@pavlin-policar
pavlin-policar / ridge_circulant.py
Created April 30, 2018 18:45
Ridge regression on circulant matrices
import numpy as np
# Initialize the generating vector
x = np.array([1, 2, 3, 4, 5])
y = np.array([5, 4, 3, 2, 1])
# Initialize the permutation matrix
P = np.array([
[0, 0, 0, 0, 1],
[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
from functools import reduce
from typing import Iterable, Dict, List, Union, Optional
from collections import Counter
import numpy as np
from data_provider import get_talks
class TokenizedDocument(Counter):
class SomeClass:
class single_execution:
"""Compute property only once and cache the result for further access.
When the property is first accessed, the result is computed, and the
attribute on the instance is replaced with the result. This is
essentially a single execution lazy property.
"""
def __init__(self, method):
self.__method = method
self.__attribute_name = method.__name__
import numpy as np
def entropy(p):
"""Compute the Shannon entropy of a distribution.
The Shannon entropy is defined as follows
:math:`\sum_x p(x_i) * \log p(x_i)`.
Parameters
@pavlin-policar
pavlin-policar / keras_load_model_error.py
Last active February 23, 2017 17:26
Can't load_model with error “Optimizer weight shape (...) not compatible with provided weight shape (...)”
# Solution found here: https://github.com/fchollet/keras/issues/4044
import h5py
f = h5py.File('model_file.h5', 'r+')
del f['optimizer_weights']
f.close()
Moodle prepend lang tags where any translations are needed.
Long syntax:
Find:
(<span lang="es")
Replace:
<span lang="en" class="multilang">&nbsp;English version<\/span><span lang="sl" class="multilang">&nbsp;Slovenska verzija<\/span>$1
Short syntax:
Find: