Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mraveri committed May 21, 2020
0 parents commit 8d1e1e1
Show file tree
Hide file tree
Showing 76 changed files with 166,941 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[run]
branch = True

omit =
*/.local/*
/usr/*
tensiometer/test*

[report]
show_missing = True

# Regexes for lines to exclude from consideration
exclude_lines =

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

ignore_errors = True
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
*.DS_Store
__pycache__/
*.py[cod]
*$py.class
*.ipynb_checkpoints

# Distribution / packaging
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/
77 changes: 77 additions & 0 deletions .material.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
This is random material, do not read it :)
"""

def _temp_vec_kde_pdf(x, samples, weights):
"""
Utility function to compute the KDE
"""
X = np.subtract(x[np.newaxis, :, :], samples[:, np.newaxis, :])
_temp = np.dot(weights, np.exp(-0.5*(X*X).sum(axis=2)))
return np.log(_temp)



C_p1, C_p12 = chain_2.cov(pars=param_names), chain_12.cov(pars=param_names)
C_Pi = chain_prior.cov(pars=param_names)
theta_1 = chain_2.getMeans(pars=[chain_1.index[name]
for name in param_names])
theta_12 = chain_12.getMeans(pars=[chain_12.index[name]
for name in param_names])

KL_eig, KL_eigv = utils.KL_decomposition(C_p1, C_p12)

KL_eig

prior_factor = 1000.0
temp_C_p1 = utils.QR_inverse(utils.QR_inverse(C_p1) +prior_factor*utils.QR_inverse(C_Pi))
temp_C_p12 = utils.QR_inverse(utils.QR_inverse(C_p12) +prior_factor*utils.QR_inverse(C_Pi))

temp_theta_12 = np.dot(temp_C_p12,np.dot(theta_12,utils.QR_inverse(C_p12))+np.dot(theta_1,prior_factor*utils.QR_inverse(C_Pi)))


KL_eig_2, KL_eigv_2 = utils.KL_decomposition(temp_C_p1, temp_C_p12)
KL_eig_2

plt.plot(KL_eig)
plt.plot(KL_eig_2)

helper_stat(theta_1-theta_12, KL_eig,KL_eigv, 1.05)
helperplot(KL_eig,KL_eigv)

helper_stat(theta_1-temp_theta_12, KL_eig_2,KL_eigv_2, 1.05)
helperplot(KL_eig_2,KL_eigv_2)




def helper_stat(shift, eig, eigv, lower_cutoff):
upper_cutoff = 100.
_filter = np.logical_and(eig > lower_cutoff, eig < upper_cutoff)
Q_UDM = np.sum(np.dot(eigv.T, shift)[_filter]**2./(eig[_filter]-1.))
dofs = np.sum(_filter)
P = scipy.stats.chi2.cdf(Q_UDM, dofs)
return utils.from_confidence_to_sigma(P)

def helperplot(eig, eigv):
fish = np.sum(eigv*eigv/eig, axis=1)
fish = ((eigv*eigv/eig).T/fish).T
im1 = plt.imshow(fish, cmap='viridis')
num_params = len(fish)
for i in range(num_params):
for j in range(num_params):
if fish[j,i]>0.5:
col = 'k'
else:
col = 'w'
plt.text(i, j, np.round(fish[j,i],2), va='center', ha='center', color=col)
# label on the axis:
plt.xlabel('KL mode ($\\lambda^a-1$)');
plt.ylabel('Parameters');
# x axis:
ticks = np.arange(num_params)
labels = [ str(t+1)+'\n ('+str(l)+')' for t,l in zip(ticks,np.round(eig-1.,2))]
plt.xticks(ticks, labels, horizontalalignment='center')
labels = [ '$'+chain_12.getParamNames().parWithName(name).label+'$' for name in param_names ]
plt.yticks(ticks, labels, horizontalalignment='right')
plt.show()
42 changes: 42 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
os: linux
language: python
dist: bionic
git:
depth: false


jobs:
include:
- env:
- CHANNEL="defaults"
- PYDIST="ANACONDA"
python: "3.6"
- env:
- CHANNEL="conda-forge"
- PYDIST="ANACONDA"
python: "3.8"
- name: "3.7 with bionic"
python: "3.7"

install:
# Setup anaconda following http://conda.pydata.org/docs/travis.html
- if [[ "$PYDIST" == "ANACONDA" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda;
export PATH="$HOME/miniconda/bin:$PATH";
hash -r;
conda config --set always_yes yes --set changeps1 no;
conda info -a;
conda create -q -n test-environment -c $CHANNEL python=$TRAVIS_PYTHON_VERSION scipy matplotlib;
source activate test-environment;
fi
- python --version
- pip install .
- pip install PyYAML
- pip install coveralls

script:
- make test_with_coverage

after_success:
- coveralls

0 comments on commit 8d1e1e1

Please sign in to comment.