In [14]:
import numpy as np
import pandas as pd
import active
from IPython.display import display
%load_ext autoreload
%autoreload 1
%aimport active
For a polyhedron defined by a set of linear inequality constraints, the Chebyshev center is defined to be the center of the largest Euclidean ball that lies within it. If the polyhedron is a square and the setting of the problem is the plane, then the solution is trivial to calculate. We test our implementation for squares of various sizes.
In [15]:
def get_results(A, test_input, tol=10e-8):
expected = []
actual = []
result = []
for (c1, c2) in test_input:
b = np.array([c1, 0, c2, 0])
ac_expected = np.asarray((c1/2, c2/2))
ac_actual = active.chebyshev_center(A, b)
expected.append(ac_expected)
actual.append(ac_actual)
# if np.array_equal(ac_expected, ac_actual):
if np.linalg.norm(ac_expected - ac_actual) <= tol:
result.append(True)
else:
result.append(False)
results = pd.DataFrame([test_input, expected, actual, result])
results = results.transpose()
results.columns = ['test_input', 'expected', 'actual', 'result']
display(results)
In [16]:
A = np.array([[1, 0],[-1,0],[0,1],[0,-1]])
test_input = [(1, 1), (5, 5), (20, 20), (10e2, 10e2), (10e4, 10e4),
(10e6, 10e6), (10e8, 10e8), (10e10, 10e10),
(0.5, 0.5), (0.1, 0.1), (0.01, 0.01),
(0.005, 0.005), (0.001, 0.001),(0.0005, 0.0005), (0.0001, 0.0001),
(0.00005, 0.00005), (0.00001, 0.00001), (0.00001, 0.00001)]
In [17]:
get_results(A, test_input)