Exemplo n.º 1
0
    def _average(self):
        sum_xi = None
        for v in self._xi:
            if not sum_xi:
                sum_xi = [0.0] * len(v)
            sum_xi = add(sum_xi, v)

        average = div(sum_xi, len(self._xi))
        return average
Exemplo n.º 2
0
def _weightedAverage(values, weight):
    sum_values = None
    for v in values:
        if not sum_values:
            sum_values = [0.0] * len(v)
        sum_values = add(sum_values, v)

    weighted_average = div(sum_values, weight)
    return weighted_average
Exemplo n.º 3
0
    def compute(self):
        init_yi = self._average()
        yi = init_yi
        converged = False
        it = 0
        while not converged:

            diffi = [sub(xj, yi) for xj in self._xi]
            normi = [sqrt(dot(di, di)) for di in diffi]
            weight = sum([1 / ni for ni in normi])
            val = [div(self._xi[i], normi[i]) for i in range(len(self._xi))]

            yip1 = _weightedAverage(val, weight)
            diff = sub(yip1, yi)
            yi = yip1
            it += 1
#             print(it)
            if sqrt(dot(diff, diff)) < self._eps:
                converged = True

        return yi