Yields an infinite sequence, for example: sequence() => 0, 1, 2, 3, ... sequence(1.0, lambda i: i/2) => 1, 0.5, 0.25, 0.125, ...
(i=0, f=lambda i: i+1)
| 1597 | return "Cluster(%s)" % list.__repr__(self)[1:-1] |
| 1598 | |
| 1599 | def sequence(i=0, f=lambda i: i+1): |
| 1600 | """ Yields an infinite sequence, for example: |
| 1601 | sequence() => 0, 1, 2, 3, ... |
| 1602 | sequence(1.0, lambda i: i/2) => 1, 0.5, 0.25, 0.125, ... |
| 1603 | """ |
| 1604 | # Used to generate unique vector id's in hierarchical(). |
| 1605 | # We cannot use Vector.id, since the given vectors might be plain dicts. |
| 1606 | # We cannot use id(vector), since id() is only unique for the lifespan of the object. |
| 1607 | while True: |
| 1608 | yield i; i=f(i) |
| 1609 | |
| 1610 | def hierarchical(vectors, k=1, iterations=1000, distance=COSINE, **kwargs): |
| 1611 | """ Returns a Cluster containing k items (vectors or clusters with nested items). |
no test coverage detected
searching dependent graphs…