view python/tests/ml.txt @ 980:23f98ebb113f

first tests for clustering algo
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 19 Feb 2018 16:32:59 -0500
parents
children
line wrap: on
line source

>>> from math import fabs
>>> from numpy import ones
>>> from ml import prototypeCluster

>>> nTrajectories = 7
>>> similarityFunc = lambda x, y: 1.-fabs(x-y)/(nTrajectories-1)
>>> similarities = -ones((nTrajectories, nTrajectories))
>>> prototypeIndices = prototypeCluster(range(nTrajectories), similarities, 1., similarityFunc, optimizeCentroid = True) # too large to be similar
>>> len(prototypeIndices) == nTrajectories
True
>>> # could use lists to have a length