
# one-dimensional data set is just a collection of numbers. 

# first step is to compute a few summary statistics. 
# You’d like to know how many data points you have, the smallest, the largest, 
# the mean, and the standard deviation.

# But even these don’t necessarily give you a great understanding. 
# A good next step is to create a histogram,

from typing import List, Dict
from collections import Counter
import math

import matplotlib.pyplot as plt

def bucketize(point: float, bucket_size: float) -> float:
    """Floor the point to the next lower multiple of bucket_size
       53 --> 50, -53 --> -60
    """
    return bucket_size * math.floor(point / bucket_size)

def make_histogram(points: List[float], bucket_size: float) -> Dict[float, int]:
    """Buckets the points and counts how many in each bucket
    Counter([50, 40, 50]) ==> [50:2, 40:1]
    """
    return Counter(bucketize(point, bucket_size) for point in points)

def plot_histogram(points: List[float], bucket_size: float, title: str = ""):
    histogram = make_histogram(points, bucket_size)
    # histogram = [50:2, 40:1, ....]
    plt.bar(histogram.keys(), histogram.values(), width=bucket_size)
    plt.title(title)

import random
from scratch.probability import inverse_normal_cdf


random.seed(0)

# uniform between -100 and 100
uniform = [200 * random.random() - 100 for _ in range(10000)]

# normal distribution with mean 0, standard deviation 57
normal = [57 * inverse_normal_cdf(random.random())
          for _ in range(10000)]

# h = make_histogram(uniform, 10)
h = make_histogram(normal, 10)
print(h)

#plot_histogram(uniform, 10, "Uniform Histogram")
plot_histogram(normal, 10, "Normal Histogram")
plt.show()
