From 55e82439302ee81656f796c4a64af6e6d51bccc8 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 18 Nov 2012 17:58:18 +0100 Subject: Test with euclidian distance. --- source/clusters.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/clusters.py') diff --git a/source/clusters.py b/source/clusters.py index 02766bdf..e53fac9b 100755 --- a/source/clusters.py +++ b/source/clusters.py @@ -1,6 +1,7 @@ #! /usr/bin/env python #-*- coding: utf-8 -*- +import math import random from math import sqrt @@ -51,6 +52,12 @@ def tanimoto(v1, v2): shr += 1 # in both return 1.0 - (float(shr) / (c1 + c2 - shr)) +def euclidian(v1, v2): + d = 0.0 + for i in range(len(v1)): + d += (v1[i] - v2[i])**2 + return math.sqrt(d) + def kcluster(rows,distance=pearson,k=4): # Determine the minimum and maximum values for each point ranges=[(min([row[i] for row in rows]),max([row[i] for row in rows])) -- cgit