This file contains hidden or 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
""" | |
Exploring parameterization of scipy.stats.truncnorm | |
Ref: | |
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.truncnorm.html | |
https://github.com/scipy/scipy/blob/v1.2.1/scipy/stats/_continuous_distns.py | |
truncnorm_gen | |
""" | |
import numpy as np | |
import scipy.stats as stats |
This file contains hidden or 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
# Pull in image to stack on top of | |
# ... https://hub.docker.com/r/wisecg/rootmj | |
# ... Installs CLHEP-2.3.2.2, ROOT-6.12.04, and a few Python packages, bash entry | |
# ... atop python:3.6.4-jessie (Debian 8 "jessie" OS) | |
FROM wisecg/rootmj:v2 | |
# Install Anaconda | |
# ... '-b' accepts license | |
RUN wget https://repo.continuum.io/archive/Anaconda3-5.3.1-Linux-x86_64.sh | |
RUN bash Anaconda3-5.3.1-Linux-x86_64.sh -b |
This file contains hidden or 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
""" | |
Profile several 'FindBin' methods | |
The "(np.abs(binCenters - val)).argmin()" method is the best, so far | |
""" | |
import sys | |
import numpy as np | |
from datetime import datetime |
This file contains hidden or 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
""" | |
Calculate expectation values for quantities of a distribution | |
via parallelized Monte Carlo approximation. | |
Approximate with t samples distributed across k CPU cores. | |
Let t = m * k, such that each core handles m samples. | |
Let P(x) be some distribution as a function of x. | |
E[x] ~= (1/t) * Sum_{i=0}^{t}[ x_i ] | |
= (1/t) * Sum_{j=0}^{k}[ Sum_{i=0}^{m}[ x_i ] ] |
This file contains hidden or 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
""" | |
Save NumPy arrays in a dictionary structure into a HDF5 file. | |
Ref: | |
http://docs.h5py.org | |
""" | |
import numpy as np | |
import h5py | |
import os |
This file contains hidden or 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
""" | |
A simple example using argparse to sum or find max of a list of numbers, | |
and optionally multiply result by some factor. | |
Examples: | |
$ python basic_argparse.py 1 2 3 4 | |
$ python basic_argparse.py --mult 10 --max 1 2 3 4 | |
$ python basic_argparse.py --max --mult 10 1 2 3 4 | |
Ref: |
This file contains hidden or 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 isSectionValid(s): | |
""" | |
Inputs: | |
s = string of chars with 1<=len(s)<=3 | |
Output: | |
True or False for valid or invalid | |
Description: | |
Leading digit of section must not be 0 if length of section > 1. Value | |
of section must be within [0,255]. If section fails either of these | |
requirements, section is invalid. |
This file contains hidden or 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
""" | |
Write, read, and print using the json module. | |
""" | |
import json | |
import os | |
# Create dictionary | |
d = {'first': 1, 'second': 2, 'third': 3} | |
file_path = './tmp_file.json' |
This file contains hidden or 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
""" | |
Use scipy.optimize.fmin (simplex algorithm) to find optimal weights for components of a simple mixture model. | |
""" | |
import numpy as np | |
import scipy.stats as stats | |
from scipy.optimize import fmin | |
############# | |
# Generate data |
This file contains hidden or 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
""" | |
Save and access numpy arrays, as single arrays in .npy files, and as multiple arrays in .npz files | |
Ref: | |
https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.save.html | |
https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.savez.html | |
""" | |
import numpy as np | |
import glob | |
import os |
NewerOlder