annotate trafficintelligence/tests/ml.txt @ 1130:18e2c8cb9b09

Merged in etienne_beauchamp/trafficintelligence/Etienne-Beauchamp/added-d-optional-argument-1581358671588 (pull request #19) Etienne Beauchamp/added d optional argument 1581358671588 Approved-by: Nicolas Saunier <[email protected]>
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 11 Feb 2020 03:47:05 +0000
parents aafbc0bab925
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
980
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1 >>> from math import fabs
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2 >>> from numpy import ones
1030
aafbc0bab925 moved method around to avoid cross-dependencies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
3 >>> from trafficintelligence.ml import prototypeCluster
980
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5 >>> nTrajectories = 7
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
6 >>> similarityFunc = lambda x, y: 1.-fabs(x-y)/(nTrajectories-1)
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
7 >>> similarities = -ones((nTrajectories, nTrajectories))
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8 >>> prototypeIndices = prototypeCluster(range(nTrajectories), similarities, 1., similarityFunc, optimizeCentroid = True) # too large to be similar
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 >>> len(prototypeIndices) == nTrajectories
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10 True
23f98ebb113f first tests for clustering algo
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 >>> # could use lists to have a length