Skip to content

Instantly share code, notes, and snippets.

View yhaddad's full-sized avatar
🎯
Focusing

Yacine Haddad yhaddad

🎯
Focusing
View GitHub Profile
@yhaddad
yhaddad / mle_tf.py
Created February 7, 2018 11:17 — forked from ibab/mle_tf.py
TensorFlow simple MLE example
import numpy as np
import tensorflow as tf
sess = tf.Session()
TYPE=np.float64
N = 1000000
data = np.random.normal(0, 1, N).astype(TYPE)
@yhaddad
yhaddad / simple_fit.py
Created July 17, 2017 23:03 — forked from ibab/simple_fit.py
Simple fit with tensorflow
import numpy as np
import tensorflow as tf
from scipy.optimize import minimize
import matplotlib
matplotlib.use('PDF')
import matplotlib.pyplot as plt
# Generate dataset
data = np.random.normal(0, 1, 1000)
@yhaddad
yhaddad / gist:c6973c78ede2ba872572f1578310f0f6
Created July 3, 2017 23:37 — forked from DavidWalz/gist:8538435
python: clopper pearson binomial confidence belt
import scipy.stats
def clopper_pearson(k,n,alpha=0.32):
"""
http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval
alpha confidence intervals for a binomial distribution of k expected successes on n trials
Clopper Pearson intervals are a conservative estimate.
"""
lo = scipy.stats.beta.ppf(alpha/2, k, n-k+1)
hi = scipy.stats.beta.ppf(1 - alpha/2, k+1, n-k)
return lo, hi
@yhaddad
yhaddad / wunderground_current.py
Created March 5, 2017 17:44 — forked from philshem/wunderground_current.py
Wunderground API: Streamlined python 2.7 code using the requests package. Must register at http://www.wunderground.com/weather/api/ and insert your personal key.
import requests
data = requests.get('http://api.wunderground.com/api/INSERT_KEY_HERE/geolookup/conditions/q/Switzerland/Zurich.json').json()
location = data['location']['city']
temp_c = data['current_observation']['temp_c']
print "Current temperature in %s is: %s C" % (location, temp_c)
@yhaddad
yhaddad / genetic.py
Created May 28, 2016 14:51 — forked from bellbind/genetic.py
[python]Genetic Algorithm example
"""Genetic Algorithmn Implementation
see:
http://www.obitko.com/tutorials/genetic-algorithms/ga-basic-description.php
"""
import random
class GeneticAlgorithm(object):
def __init__(self, genetics):
self.genetics = genetics
pass
"""
Helper module for displaying ROOT canvases in ipython notebooks
Usage example:
# Save this file as rootnotes.py to your working directory.
import rootnotes
c1 = rootnotes.default_canvas()
fun1 = TF1( 'fun1', 'abs(sin(x)/x)', 0, 10)
c1.SetGridx()