
from typing import List
import math
import random
import matplotlib.pyplot as plt


from scratch.linear_algebra import Matrix, Vector, make_matrix
from scratch.probability import inverse_normal_cdf
from scratch.statistics import correlation


def correlation_matrix(data: List[Vector]) -> Matrix:
    """
    Returns the len(data) x len(data) matrix whose (i, j)-th entry
    is the correlation between data[i] and data[j]
    """
    def correlation_ij(i: int, j: int) -> float:
        return correlation(data[i], data[j])

    return make_matrix(len(data), len(data), correlation_ij)


def random_normal() -> float:
    """Returns a random draw from a standard normal distribution"""
    return inverse_normal_cdf(random.random())

xs = [random_normal() for _ in range(1000)]
ys1 = [ x + random_normal() / 2 for x in xs]
ys2 = [-x + random_normal() / 2 for x in xs]

vectors = [xs, ys1, ys2]

A = correlation_matrix(vectors)
print(A)


