Skip to content

Instantly share code, notes, and snippets.

View vlavorini's full-sized avatar

Vincenzo Lavorini vlavorini

View GitHub Profile
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
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
from mpmath import betainc
p=betainc(a_T, b_T, 0.003,1, regularized=True) #result: 0.48112566853812544
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)
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
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)
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) :

Solving PyRFR issue (SMAC or auto-sklearn)

TL:DR

  • 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

The source of the issue

@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)
from numba import jit
@jit
def example_function(arguments):
#this function will be compiled by Numba
...
...
...