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 |
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
fortune = 500_000_000 | |
total_americans = 327_000_000 | |
americans_lives_changed = 0 | |
for american in range(total_americans): | |
if fortune - 1_000_000 >= 0: | |
fortune -= 1_000_000 | |
americans_lives_changed += 1 | |
else: | |
raise ValueError(f"Uh oh! He ran out of money! Lives changed: {americans_lives_changed}") |
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 random | |
number_of_hens = 100 | |
repeats = 1000 # repeat many times so that we get some decent statistics | |
sums = [] | |
for _ in range(repeats): | |
hens = np.zeros(number_of_hens, dtype=bool) # reset an array of 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
x_ = np.linspace(0, 12, 1000) | |
die_y = die_fit_func(x_, *guess) | |
fig, ax = plt.subplots() | |
ax.plot(x_, die_y.real) | |
ax2 = ax.twinx() | |
ax2.plot(x_, die_y.imag, color='red') | |
ax.set(xlabel='Energy', ylabel='Real') |