Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 979:cc89267b5ff9 | 980:23f98ebb113f |
|---|---|
| 1 >>> from math import fabs | |
| 2 >>> from numpy import ones | |
| 3 >>> from ml import prototypeCluster | |
| 4 | |
| 5 >>> nTrajectories = 7 | |
| 6 >>> similarityFunc = lambda x, y: 1.-fabs(x-y)/(nTrajectories-1) | |
| 7 >>> similarities = -ones((nTrajectories, nTrajectories)) | |
| 8 >>> prototypeIndices = prototypeCluster(range(nTrajectories), similarities, 1., similarityFunc, optimizeCentroid = True) # too large to be similar | |
| 9 >>> len(prototypeIndices) == nTrajectories | |
| 10 True | |
| 11 >>> # could use lists to have a length |
