Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zonotope_distance_point returns values larger than distance to centroid #1

Closed
wualbert opened this issue Mar 16, 2019 · 2 comments
Closed
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@wualbert
Copy link
Collaborator

When given a query point q and zonotope z=zonotope(x,G), zonotope_distance_point(z,x) may return something larger than distance(x,q). Example code:

import numpy as np
from pypolycontain.lib.zonotope import zonotope,zonotope_distance_point

iterations = 100
for i in range(iterations):
    centroid_range = iterations
    generator_range = 3
    dimension = 2
    m = np.random.random_integers(dimension, 10)
    G = (np.random.rand(dimension, m) - 0.5) * generator_range
    x = (np.random.rand(dimension, 1) - 0.5) * centroid_range
    z1=zonotope(x,G,color="red")
    query_point = (np.random.rand(1, dimension) - 0.5) * centroid_range
    query_point = query_point.reshape(-1, 1)
    d_centroid_query_point = np.subtract(np.ndarray.flatten(x), \
                              np.ndarray.flatten(query_point))
    d_zonotope_query_point = zonotope_distance_point(z1,query_point)
    print('x: ',x, 'query_point: ', query_point)
    print('dist(x,q): %d, dist(zonotope, q): %d' %(np.linalg.norm(d_centroid_query_point),d_zonotope_query_point))
    assert(d_zonotope_query_point <= np.linalg.norm(d_centroid_query_point))

Example output:

...
('x: ', array([[-11.8958544 ],
       [-15.76381685]]), 'query_point: ', array([[-27.91779239],
       [ 37.10888876]]))
dist(x,q): 55, dist(zonotope, q): 72
Traceback (most recent call last):
  File ".../bounding_box_closest_polytope/pypolycontain/tests/test_zonotope_distance_2.py", line 27, in <module>
    assert(d_zonotope_query_point <= np.linalg.norm(d_centroid_query_point))
AssertionError
@wualbert wualbert added the bug Something isn't working label Mar 16, 2019
@sadraddini
Copy link
Owner

Thanks for pointing this out. It's not really a bug. The underlying metric is not L2 or L_infinity. It is based on G and it is explained in Section 4.2 in this paper. Nevertheless, it is a good idea to have L1,L2 and L_Infinity norms as well. Will work on it and push it.

@sadraddini sadraddini added the enhancement New feature or request label Mar 16, 2019
@sadraddini
Copy link
Owner

Added a distance (P,x) function to pypolycontain.lib.AH_polytope It works for H-polytopes, zonotopes, and AH-polytopes. The norms can be L1, L2 or L infinity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants