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 _get_required_decimals(x: np.ndarray) -> int: | |
"""Determine the number of decimals needed to nicely show the data.""" | |
req_decimals = np.floor(np.log10(x)) | |
dec = np.percentile(req_decimals, [5]) | |
return abs(int(dec)) | |
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
from collections import OrderedDict | |
from typing import Iterable | |
import numpy as np | |
import scipy.sparse as sp | |
import scipy.stats as stats | |
import pandas as pd | |
def FDR(p_values: Iterable, dependent=False, m=None, ordered=False) -> Iterable: |
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
from sklearn.base import BaseEstimator | |
from sklearn.neighbors import NearestNeighbors | |
import numpy as np | |
import networkx as nx | |
from community import best_partition | |
def jaccard(x: set, y: set) -> float: | |
return len(x & y) / len(x | y) |
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 scipy.sparse as sp | |
import numpy as np | |
def plot_marker( | |
marker, | |
dataset, | |
embedding: np.ndarray, | |
binary=True, | |
s=1, |
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 confidence_histogram(y_true, y_probs, n_bins=10, ax=None): | |
if ax is None: | |
fig, ax = plt.subplots(figsize=(4, 4)) | |
confidences = np.max(y_probs, axis=1) | |
predictions = np.argmax(y_probs, axis=1) | |
accuracies = predictions == y_true | |
bins = np.linspace(0, 1 - 1 / n_bins, n_bins) | |
bin_indices = np.digitize(confidences, bins=bins[1:]) |
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
"""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 |
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
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 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 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 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], |
NewerOlder