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
""" | |
Ensures a consistent ordering of corners returned by cv2.findChessboardCornersSB | |
for asymmetrical chessboards. | |
For patterns with dims i, j where i > j and i is odd the script ensures the corner | |
order to start at a black square running along the positive i axis. | |
The detected corners are used to create a canonical chessboard view. This | |
view is analysed by looking at the 2x2 blocks associated with each corner. | |
A characteristic value is computed from each 2x2 block and if the series |
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
# Estimate the population size using capture-recapture method | |
# Assumes: experiment twice, closed population | |
import numpy as np | |
import matplotlib.pyplot as plt | |
T = 1000 # true pop size | |
N1 = 50 # size of sample 1 | |
N2 = 30 # size of sample 2 |
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 cv_to_ndc(fx, fy, cx, cy, near, far, w, h): | |
"""Returns the 4x4 projection matrix that converts from OpenCV camera | |
coordinates to OpenGL NDC coordinates. | |
This takes into account that cameras in | |
- OpenCV has +z into scene, +y down the image | |
- OpenGL has -z into scene, +y up the image |
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 | |
import matplotlib.pyplot as plt | |
def sierpinski_triangle(): | |
"""Generates a Sierpinski triangle. | |
Given 3 anchor points and a trace point, the | |
next trace point is half-way between its current | |
location and a randomly chosen anchor. |
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 argparse | |
import platform | |
import sys | |
import subprocess | |
from pathlib import Path | |
def describe() -> dict: | |
meta = { | |
"python": "py" + ".".join(platform.python_version_tuple()[:2]), |
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 | |
import matplotlib.pyplot as plt | |
import dataclasses | |
@dataclasses.dataclass | |
class MotionEstimate: | |
coeffs: np.ndarray # 3x1 | |
t0: float | |
degree: int = dataclasses.field(init=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
import torch | |
def sample_entropy( | |
x: torch.Tensor, m: int = 2, r: float = None, stride: int = 1, subsample: int = 1 | |
): | |
"""Returns the (batched) sample entropy of the given time series. | |
Sample entropy is a measure of complexity of sequences that can be related | |
to predictability. Sample entropy (SE) is defined as the negative logarithm of | |
the following ratio: |
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 scipy.optimize import linprog | |
import numpy as np | |
import pandas as pd | |
def print_metrics(df): | |
print('Total staff costs', df.to_numpy().sum()) | |
print('Management cost ratio') | |
print(df.MgtStaffCosts / df.to_numpy().sum()) | |
print('Partner cost ratio') |
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 | |
from itertools import count | |
def perm_matrix(perm_indices): | |
'''Returns the permutation matrix corresponding to given permutation indices | |
Here `perm_indices` defines the permutation order in the following sense: | |
value `j` at index `i` will move row/column `j` of the original matrix to | |
row/column `i`in the permuated matrix P*M/M*P^T. | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder