<commit_before>#!/usr/bin/env python

# Utility functions.
# <NAME>, 5/21/2012

import numpy as np

def logit(x):
    return np.log(x / (1.0 - x))

def inv_logit(x):
    return 1.0 / (np.exp(-x) + 1.0)

# Convenience functions for plotting ellipses, e.g., 2-d confidence regions
#
# Finding the right settings for Ellipse is surprisingly tricky so I follow:
#   http://scikit-learn.org/stable/auto_examples/plot_lda_qda.html
try:
    from matplotlib.patches import Ellipse
except:
    print 'Failed import of matplotlib.patches.Ellipse.'
def draw_ellipse(a, m, S):
    v, w = np.linalg.eigh(S)
    u = w[0] / np.linalg.norm(w[0])
    angle = (180.0 / np.pi) * np.arctan(u[1] / u[0])
    e = Ellipse(m, 2.0 * np.sqrt(v[0]), 2.0 * np.sqrt(v[1]),
                180.0 + angle, color = 'k')
    a.add_artist(e)
    e.set_clip_box(ax.bbox)
    e.set_alpha(0.5)<commit_msg>Allowed for displaying multiple confidence contours.<commit_after>#!/usr/bin/env python

# Utility functions.
# <NAME>, 5/21/2012

import numpy as np
from scipy.stats import norm

def logit(x):
    return np.log(x / (1.0 - x))

def inv_logit(x):
    return 1.0 / (np.exp(-x) + 1.0)

# Convenience functions for plotting ellipses, e.g., 2-d confidence regions
#
# Finding the right settings for Ellipse is surprisingly tricky so I follow:
#   http://scikit-learn.org/stable/auto_examples/plot_lda_qda.html
try:
    from matplotlib.patches import Ellipse
except:
    print 'Failed import of matplotlib.patches.Ellipse.'
def draw_confidence(a, m, S, levels = [0.5, 0.95]):
    # Convert levels into ellipse scale multipliers
    d = norm()
    multipliers = [d.ppf(l / 2.0 + 0.5) for l in levels]
    multipliers.sort()
    multipliers.reverse()
    alphas = np.linspace(1.0, 0.0, len(multipliers) + 2)[1:-1]
    print multipliers

    v, w = np.linalg.eigh(S)
    u = w[0] / np.linalg.norm(w[0])
    angle = (180.0 / np.pi) * np.arctan(u[1] / u[0])
    for alpha, multiplier in zip(alphas, multipliers):
        e = Ellipse(m, multiplier * np.sqrt(v[0]), multiplier * np.sqrt(v[1]),
                    180.0 + angle, color = 'k')
        a.add_artist(e)
        e.set_clip_box(a.bbox)
        e.set_alpha(alpha)
{'fraction_non_alphanumeric': 0.14967860422405876, 'fraction_numerical': 0.03581267217630854, 'mean_word_length': 2.9050179211469533, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5768675', 'n_tokens_mistral': 907, 'n_tokens_neox': 855, 'n_words': 208}