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
--------------------------------------------------------------------------- | |
ValueError Traceback (most recent call last) | |
/var/folders/yt/z22_f0896l74f8gs3_20vc_00000gn/T/ipykernel_88946/1449311839.py in <module> | |
7 return np.linalg.inv(x) | |
8 | |
----> 9 y = gufoo(b) | |
~/mambaforge/envs/py/lib/python3.9/site-packages/dask/array/gufunc.py in __call__(self, *args, **kwargs) | |
659 | |
660 def __call__(self, *args, **kwargs): |
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 bilinear_interpolate(img, points, clipped_nan=True): | |
"""Bilinearly interpolate points from an image using NumPy or CuPy | |
Args: | |
img: Image of shape (Y, X) to interpolate from. | |
points: array of shape (2, N) of (y, x) coordinates | |
clipped_nan: If True, the value of coordinates outside the image shape | |
are set to nan. Otherwise they are clipped to the image edge. | |
Returns: |
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 bilinear_binning(points, intensities, subpixel=1, gaussian_blur=False): | |
"""Bilinear weighting of points onto a grid. | |
Extent of grid given by min and max of points in each dimension | |
points should be an array of shape (N, 2) | |
intensity should be an array of shape (N,) | |
subpixel will increase the gridsize by its factor | |
gaussian_blur: blur the binned intensity and weighting images before they are divided, avoiding divide-by-zero warnings | |
TODO: Give a known grid as input | |
""" |
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 bilinear_bincount_cupy(points, intensities, subpixel=1): | |
"""Bilinear weighting of points onto a grid. | |
Extent of grid given by min and max of points in each dimension | |
points should be a cupy array of shape (N, 2) | |
intensity should be a cupy array of shape (N,) | |
""" | |
points = subpixel * points | |
floor = cp.floor(points) | |
ceil = floor + 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 bilinear_bincount_numpy(points, intensities): | |
"""Bilinear weighting of points onto a grid. | |
Extent of grid given by min and max of points in each dimension | |
points should have shape (N, 2) | |
intensity should have shape (N,) | |
""" | |
floor = np.floor(points) | |
ceil = floor + 1 | |
floored_indices = np.array(floor, dtype=int) | |
low0, low1 = floored_indices.min(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
(gpus) [thomasaar@ml2 KDEpy]$ pip install -e . | |
Obtaining file:///itf-fi-ml/home/thomasaar/github/KDEpy | |
Requirement already satisfied: numpy>=1.14.2 in /itf-fi-ml/home/thomasaar/.conda/envs/gpus/lib/python3.9/site-packages (from KDEpy==1.1.0) (1.21.0) | |
Requirement already satisfied: scipy>=1.0.1 in /itf-fi-ml/home/thomasaar/.conda/envs/gpus/lib/python3.9/site-packages (from KDEpy==1.1.0) (1.6.3) | |
Requirement already satisfied: matplotlib>=2.2.0 in /itf-fi-ml/home/thomasaar/.conda/envs/gpus/lib/python3.9/site-packages (from KDEpy==1.1.0) (3.4.2) | |
Requirement already satisfied: pillow>=6.2.0 in /itf-fi-ml/home/thomasaar/.conda/envs/gpus/lib/python3.9/site-packages (from matplotlib>=2.2.0->KDEpy==1.1.0) (8.2.0) | |
Requirement already satisfied: cycler>=0.10 in /itf-fi-ml/home/thomasaar/.conda/envs/gpus/lib/python3.9/site-packages (from matplotlib>=2.2.0->KDEpy==1.1.0) (0.10.0) | |
Requirement already satisfied: python-dateutil>=2.7 in /itf-fi-ml/home/thomasaar/.conda/envs/gpus/lib/python3.9/site-packages (from matplotlib>= |
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 sympy as sp | |
import numpy as np | |
def levenberg(sympy_func, xi, target, sympy_param, guess, weight=None, module='numpy'): | |
''' | |
Computes the minimum `guess` so that `sympy_func(guess) - target` is minimized | |
Arguments: | |
sympy_func : Should be a sympy function to be minimized | |
xi : numpy array, the x-axis of `target` |
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
(base) ~: mamba create --name torchtest pytorch torchvision torchaudio cpuonly -c pytorch | |
__ __ __ __ | |
/ \ / \ / \ / \ | |
/ \/ \/ \/ \ | |
███████████████/ /██/ /██/ /██/ /████████████████████████ | |
/ / \ / \ / \ / \ \____ | |
/ / \_/ \_/ \_/ \ o \__, | |
/ _/ \_____/ ` | |
|/ |
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
(base) ~: conda create --name torch pytorch torchvision torchaudio cpuonly -c pytorch | |
Collecting package metadata (current_repodata.json): done | |
Solving environment: done | |
## Package Plan ## | |
environment location: /home/thomasaar/mambaforge/envs/torch | |
added / updated specs: | |
- cpuonly |
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
# Let's minimize the function f(x,y) = (x-50)**2 + (y-100)**2 | |
# We can tell from looking at the equation that the minimum should be at (50, 100). | |
def func(params): | |
x, y = params | |
return (x-50)**2 + (y-100)**2 | |
# Optionally, view what it looks like |