This file contains hidden or 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
Moodle prepend lang tags where any translations are needed. | |
Long syntax: | |
Find: | |
(<span lang="es") | |
Replace: | |
<span lang="en" class="multilang"> English version<\/span><span lang="sl" class="multilang"> Slovenska verzija<\/span>$1 | |
Short syntax: | |
Find: |
This file contains hidden or 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
# 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() |
This file contains hidden or 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 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 |
This file contains hidden or 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
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__ |
This file contains hidden or 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
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): |
This file contains hidden or 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 | |
# 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], |
This file contains hidden or 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
from typing import Callable | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def lagrangian_interpolation(xs: np.ndarray, ys: np.ndarray) -> Callable: | |
"""Make a Lagrangian interpolating polynomial function.""" | |
def _interpolate(x: float) -> float: | |
result = 0 |
This file contains hidden or 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
class MaxHeap: | |
def __init__(self, collection=None): | |
self._heap = [] | |
if collection is not None: | |
for el in collection: | |
self.push(el) | |
def push(self, value): | |
self._heap.append(value) |
This file contains hidden or 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
read.h5ad = function (fname) { | |
#' Read an H5AD file | |
#' | |
#' @param fname str: The path to the H5AD file | |
library(reticulate) | |
library(Matrix) | |
ad = import("anndata", convert = FALSE) | |
sp = import("scipy.sparse", convert = FALSE) | |
This file contains hidden or 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
"""Adapted from Orange 2""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def compute_critical_difference(avg_ranks, N, alpha="0.05", type="nemenyi"): | |
""" Returns critical difference for Nemenyi or Bonferroni-Dunn test | |
according to given alpha (either alpha="0.05" or alpha="0.1") for average | |
ranks and number of tested data sets N. Type can be either "nemenyi" for |
OlderNewer