# Path: concept_formation/utils.py
# def mean(values):
#     """
#     Computes the mean of a list of values.
# 
#     This is primarily included to reduce dependency on external math libraries
#     like numpy in the core algorithm.
# 
#     :param values: a list of numbers
#     :type values: list
#     :return: the mean of the list of values
#     :rtype: float
# 
#     >>> mean([600, 470, 170, 430, 300])
#     394.0
#     """
#     if len(values) <= 0:
#         raise ValueError("Length of list must be greater than 0.")
# 
#     return float(sum(values))/len(values)


from math import sqrt
from scipy.stats import sem
from scipy.stats import t
from scipy import linalg
from concept_formation.utils import mean
import numpy as np

    smoother curve. The number of robustifying iterations is given by iter. The
    function will run faster with a smaller number of iterations.

    .. todo:: double check that the confidence bounds are correct
    """
    n = len(x)
    r = int(np.ceil(f*n))
    h = [np.sort(np.abs(x - x[i]))[r] for i in range(n)]
    w = np.clip(np.abs((x[:, None] - x[None, :]) / h), 0.0, 1.0)
    w = (1 - w**3)**3
    yest = np.zeros(n)
    delta = np.ones(n)
    for iteration in range(iter):
        for i in range(n):
            weights = delta * w[:, i]
            b = np.array([np.sum(weights*y), np.sum(weights*y*x)])
            A = np.array([[np.sum(weights), np.sum(weights*x)],
                          [np.sum(weights*x), np.sum(weights*x*x)]])
            beta = linalg.solve(A, b)
            yest[i] = beta[0] + beta[1]*x[i]

        residuals = y - yest
        s = np.median(np.abs(residuals))
        delta = np.clip(residuals / (6.0 * s), -1, 1)
        delta = (1 - delta**2)**2

    h = np.zeros(n)
    for x_idx, x_val in enumerate(x):
        r2 = np.array([v*v for i, v in enumerate(residuals) if x[i] == x_val])
        n = len(r2)

# Path: concept_formation/utils.py
# def mean(values):
#     """
#     Computes the mean of a list of values.
# 
#     This is primarily included to reduce dependency on external math libraries
#     like numpy in the core algorithm.
# 
#     :param values: a list of numbers
#     :type values: list
#     :return: the mean of the list of values
#     :rtype: float
# 
#     >>> mean([600, 470, 170, 430, 300])
#     394.0
#     """
#     if len(values) <= 0:
#         raise ValueError("Length of list must be greater than 0.")
# 
#     return float(sum(values))/len(values)


# Path: concept_formation/examples/examples_utils.py
from math import sqrt
from scipy.stats import sem
from scipy.stats import t
from scipy import linalg
from concept_formation.utils import mean
import numpy as np

    smoother curve. The number of robustifying iterations is given by iter. The
    function will run faster with a smaller number of iterations.

    .. todo:: double check that the confidence bounds are correct
    """
    n = len(x)
    r = int(np.ceil(f*n))
    h = [np.sort(np.abs(x - x[i]))[r] for i in range(n)]
    w = np.clip(np.abs((x[:, None] - x[None, :]) / h), 0.0, 1.0)
    w = (1 - w**3)**3
    yest = np.zeros(n)
    delta = np.ones(n)
    for iteration in range(iter):
        for i in range(n):
            weights = delta * w[:, i]
            b = np.array([np.sum(weights*y), np.sum(weights*y*x)])
            A = np.array([[np.sum(weights), np.sum(weights*x)],
                          [np.sum(weights*x), np.sum(weights*x*x)]])
            beta = linalg.solve(A, b)
            yest[i] = beta[0] + beta[1]*x[i]

        residuals = y - yest
        s = np.median(np.abs(residuals))
        delta = np.clip(residuals / (6.0 * s), -1, 1)
        delta = (1 - delta**2)**2

    h = np.zeros(n)
    for x_idx, x_val in enumerate(x):
        r2 = np.array([v*v for i, v in enumerate(residuals) if x[i] == x_val])
        n = len(r2)

        se = sqrt(mean(r2)) / sqrt(len(r2))
