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
""" | |
Marginalize a 2-dimensional distribution evaluated over a numpy meshgrid. | |
-The Distribution class holds the distribution, the marginalization method, | |
and the grid parameters to be used for the integration. | |
-The Marginalize() method allows specification of the axis you would like to marginalize. | |
The marginalization is done via simple grid integration, using rectangular Riemann | |
sum approximation of integral. | |
There is similar code in scipy's scipy/stats/tests/test_multivariate.py::test_marginalization() |
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 chi-square test for the difference between two data sets. | |
_count() method is from SciPy's https://github.com/scipy/scipy/blob/v0.14.0/scipy/stats/stats.py#L3467 | |
A version of this function is in NRC, and related functions are in SciPy: | |
NRC: chstwo(bins1, bins2, nbins, knstrn, df, chsq, prob) | |
SciPy: power_divergence(f_obs, f_exp=None, ddof=0, axis=0, lambda_=None) | |
""" | |
import numpy as np |
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
""" | |
Plotting a matplotlib.pyplot.barh from the left or right of axes | |
Ref: | |
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.barh.html | |
https://matplotlib.org/examples/lines_bars_and_markers/barh_demo.html | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt |
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
/* | |
Code to change the strings used for TAxis bin labels in ROOT. | |
Ref: | |
https://root.cern.ch/doc/master/classTAxis.html | |
*/ | |
#include <map> | |
#include <string> | |
#include <iostream> |
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
""" | |
Create a custom list of colors for use in data visualization | |
""" | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# create n data points | |
n = 20 | |
xData = np.linspace(0,n,n) |
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 |
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
""" | |
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
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
""" | |
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: |
OlderNewer