- If you already have a version of GCC > 7.2, you can skip this step. Otherwise you have to install it:
brew install gcc
; - make sure the symbolic links are created, i.e.
/usr/local/bin/gcc -> gcc-7
,/usr/local/bin/g++ -> g++-7
- I used the version 7 of GCC, but probably a newer version will work too.
- tell PIP to compile the package, avoiding the pre-compiled binaries:
pip install --force-reinstall --ignore-installed --no-binary :all: pyrfr
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 | |
from theano import shared | |
import pymc3 as pm | |
x = np.arange(len(df)) | |
# we set a shared tensor useful for inference | |
x_shared = shared(x) | |
y = df['totale_casi'].values |
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 seaborn as sns | |
import pandas as pd | |
import numpy as np | |
imps_ctrl,convs_ctrl=16500, 30 | |
imps_test, convs_test=17000, 50 | |
#here we create the Beta functions for the two sets | |
a_C, b_C = convs_ctrl+1, imps_ctrl-convs_ctrl+1 | |
a_T, b_T = convs_test+1, imps_test-convs_test+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
from mpmath import betainc | |
p=betainc(a_T, b_T, 0.003,1, regularized=True) #result: 0.48112566853812544 |
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 math import lgamma | |
from numba import jit | |
#defining the functions used | |
@jit | |
def h(a, b, c, d): | |
num = lgamma(a + c) + lgamma(b + d) + lgamma(a + b) + lgamma(c + d) | |
den = lgamma(a) + lgamma(b) + lgamma(c) + lgamma(d) + lgamma(a + b + c + d) | |
return np.exp(num - den) |
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 scipy.stats import beta | |
import numpy as np | |
from calc_prob import calc_prob_between | |
#This is the known data: imporessions and conversions for the Control and Test set | |
imps_ctrl,convs_ctrl=16500, 30 | |
imps_test, convs_test=17000, 50 | |
#here we create the Beta functions for the two sets | |
a_C, b_C = convs_ctrl+1, imps_ctrl-convs_ctrl+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
from math import lgamma | |
from numba import jit | |
@jit | |
def h(a, b, c, d): | |
num = lgamma(a + c) + lgamma(b + d) + lgamma(a + b) + lgamma(c + d) | |
den = lgamma(a) + lgamma(b) + lgamma(c) + lgamma(d) + lgamma(a + b + c + d) | |
return np.exp(num - den) |
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 matplotlib.pyplot as plt | |
def calc_beta_mode(a, b): | |
'''this function calculate the mode (peak) of the Beta distribution''' | |
return (a-1)/(a+b-2) | |
def plot(betas, names, linf=0, lsup=0.01): | |
'''this function plots the Beta distribution''' | |
x=np.linspace(linf,lsup, 100) | |
for f, name in zip(betas,names) : |
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
@jit(nopython=True, nogil=True) | |
def dist_batch(points, n_begin, n_end): | |
#expd=np.expand_dims(points,2) | |
#tiled=np.tile(expd, n_end-n_begin) #we tile up only (n_end-n_begin) times | |
tiled = np.zeros((points.shape[0], points.shape[1], n_end-n_begin)) | |
for dim in range(n_end-n_begin): | |
tiled[:,:,dim]=points | |
selected=points[n_begin:n_end] # we select only part (a batch) of the whole dataset | |
trans=np.transpose(selected) |
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 numba import jit | |
@jit | |
def example_function(arguments): | |
#this function will be compiled by Numba | |
... | |
... | |
... |
NewerOlder