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 index_of_which_bin(bin_sizes, absolute_index, verbose=False): | |
""" | |
Given the absolute index, returns which bin it falls in and which element of that bin it corresponds to. | |
""" | |
# Which class/bin does i fall into? | |
accum = np.add.accumulate(bin_sizes) | |
if verbose: | |
print("accum =", accum) | |
bin_index = len(np.argwhere(accum <= absolute_index)) | |
if verbose: |
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 torchvision | |
import torchvision.transforms as transforms | |
from torchvision.datasets import CIFAR10 | |
from torch.utils.data import Dataset, DataLoader | |
import numpy as np | |
# Transformations | |
RC = transforms.RandomCrop(32, padding=4) | |
RHF = transforms.RandomHorizontalFlip() | |
RVF = transforms.RandomVerticalFlip() |
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
# Author: Miladiouss (Milad Pourrahmani) | |
# Author's Website: Miladiouss.com | |
# Date: Sep 26, 2018 | |
# Title: Simple Particle Simulator | |
# Description: | |
""" | |
I am hoping to assemble a series of brief educational computer programs that will capture the simplicity and elegance of laws of physics, both in nature and in apprehension. | |
This particular educational project (Simple Particle Simulator) is the first of this series. In less than 25 lines, plotting and comments aside, we can obtain the trajectory of a particle in ANY force field. The generated plot displays the simulated and exaggerated perihelion precision of Mercury. |
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 matplotlib import pyplot as plt | |
import torch | |
class HistogramTransform(object): | |
""" | |
Transforms the distribution of the input tensor to match that | |
of the list of template histograms corresponding to each channel. | |
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 pathlib import Path | |
# AstroPy | |
import astropy | |
from astropy.coordinates import SkyCoord, GCRS, ICRS, GeocentricTrueEcliptic, Galactic | |
import astropy.units as u | |
from astropy.io import fits | |
from astropy.wcs import WCS |
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
# Library import for plotting | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
# Define Logistic Map | |
def f(x, r): | |
return r * x * (1 - x) | |
# Define history and parameters | |
history = [0.5] |
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
# GPU Detection Tests | |
from torch.cuda import device_count | |
import gpustat | |
print(""" | |
If pytorch raises "RuntimeError: cuda runtime error (30)" after suspension, | |
run the following commands in linux terminal: | |
sudo rmmod nvidia_uvm | |
sudo rmmod nvidia |
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 datetime import datetime | |
timeFormat = '%a %b %d %Y at %H:%M:%S' | |
import socket | |
deviceName = socket.gethostname() | |
import getpass | |
userName = getpass.getuser() | |
t1 = datetime.now() | |
print(t1.strftime(timeFormat) + ' on ' + deviceName + ' by ' + userName) |
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 appendOrdinality(df, columns, ascending, strictlyIncreasing=False): | |
""" | |
Appends absolute and relative ordinality to a dataframe. | |
Oridinality is the normalized position of a row in a sorted dataframe. | |
df: | |
Pandas DataFrame | |
columns: | |
List of column names for to be used for sorting (e.g. ['prob_1']) | |
ascending: |
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
-- An HSC-PDR2 SQL query to extract RA, Dec, tract, patch of clean galaxies with a magnitude cut. | |
-- Useful Links: | |
-- /https://hsc-release.mtk.nao.ac.jp/hscMap-pdr2/app/#/?_=%7B%22view%22%3A%7B%22a%22%3A5.770914805732617,%22d%22%3A-0.019535944017082533,%22fovy%22%3A0.0002503311005562077,%22roll%22%3A0%7D,%22sspParams%22%3A%7B%22type%22%3A%22SDSS_TRUE_COLOR%22,%22filter%22%3A%5B%22HSC-I%22,%22HSC-R%22,%22HSC-G%22%5D,%22simpleRgb%22%3A%7B%22beta%22%3A22026.465794806718,%22a%22%3A1,%22bias%22%3A0.05,%22b0%22%3A0%7D,%22sdssTrueColor%22%3A%7B%22beta%22%3A26003.369421497522,%22a%22%3A1,%22bias%22%3A0.14439999999999995,%22b0%22%3A0%7D%7D%7D | |
-- https://hsc-release.mtk.nao.ac.jp/schema/#pdr2.pdr2_wide.forced | |
SELECT | |
object_id | |
, tract |
OlderNewer