Source code for similarityPy.algorithms.sum_formula

# coding=utf-8
"""
Created on 18 January 2014
@author: Cenk Bircanoglu
"""
import math


[docs]class SumFormula: def __init__(self): self._data = []
[docs] def exponential(self, x, power): return math.pow(x, power)
[docs] def calculate(self, data, is_tuple=False, index=None, power=1): if is_tuple: self._data = [obj[index] for obj in data] else: self._data = data self.power = power return self.__algorithm()
def __algorithm(self): total = 0.0 for num in self._data: total += self.exponential(float(num), self.power) return total