<jupyter_start><jupyter_text>H-polytope Approximations to AH-polytopes<jupyter_code>import numpy as np
import pypolycontain as pp
import pydrake.solvers.mathematicalprogram as MP
import pydrake.solvers.gurobi as Gurobi_drake
# use Gurobi solver
global gurobi_solver, license
gurobi_solver=Gurobi_drake.GurobiSolver()
license = gurobi_solver.AcquireLicense()
import pydrake.solvers.scs as SCS
scs_solver=SCS.ScsSolver()
prog=MP.MathematicalProgram()
q=4
H_planes=np.random.random((q,2))-0.5
h_y=prog.NewContinuousVariables(2*q,1,"hy")
H_y=np.vstack(( H_planes , -H_planes ))
Y=pp.H_polytope( H_y , h_y)
G=np.random.random((2,11))-0.5
X1=pp.zonotope( x=np.random.random((2,1))*3,G=G ,color='red')
H=np.array([[1,1],[-1,1],[0,-1]])
h=np.array([1,0,0]).reshape(3,1)*5
X2=pp.H_polytope(H,h, color='orange')
X=pp.translate(P=pp.intersection(X1,X2),t=np.array([-12,2]).reshape(2,1))
X.color='black'
pp.subset(prog,X,Y)
prog.AddLinearCost(np.ones(2*q),np.array([0]),h_y)
result=gurobi_solver.Solve(prog,None,None)
if result.is_success():
    h_y_n=result.GetSolution(h_y)
    Y_n=pp.H_polytope(H_y,h_y_n,color='cyan')
    pp.visualize([X1,X2,X],alpha=0.6,a=0.2)
    pp.visualize([Y_n,X],alpha=0.4,a=0.2)
else:
    print("not sucessfull")
prog=MP.MathematicalProgram()
# T_y=prog.NewContinuousVariables(2*q,1,"hy")
# T=prog.NewSymmetricContinuousVariables(2,'T')
T=prog.NewContinuousVariables(2,2,'T')
t=prog.NewContinuousVariables(2,1,'t')
# prog.AddPositiveSemidefiniteConstraint(T)
prog.AddMaximizeLogDeterminantSymmetricMatrixCost(T)
new_X=pp.affine_map(t=t,T=T,P=X)
# new_X=pp.AH_polytope(t=t+X.t,T=np.dot(T,X.T),P=X.P)
pp.subset(prog,new_X,Y_n)
result=scs_solver.Solve(prog,None,None)
if result.is_success():
    T_n=result.GetSolution(T)
    t_n=np.atleast_2d(result.GetSolution(t)).T
    Tinv=np.linalg.inv(T_n)
    X_new=pp.affine_map(T=T_n,t=t_n,P=X)
    Y_new=pp.affine_map(T=Tinv,t=-np.dot(Tinv,t_n),P=Y_n)
#     Y_new_2=pp.affine_map(T=Tinv,P=pp.translate(-t_n,Y_n))
    X_new.color='yellow'
#     X_new_new=pp.affine_map(T=Tinv,t=-np.dot(Tinv,t_n),P=X_new)
    pp.visualize([Y_n,Y_new,X],alpha=0.9,a=0.2)
    pp.visualize([Y_n,X],alpha=0.9,a=0.2)
    pp.visualize([Y_n,X_new],alpha=0.7,a=0.2)
#     pp.visualize([X_new_new,X],alpha=0.2)
#     pp.visualize([Y_new_2,Y_new],alpha=0.3,title='Y transformed')
    print(np.linalg.det(T_n))
    print(T_n)
    print(t_n)
else:
    print("not sucessfull")<jupyter_output>1.1453055159684407
[[ 1.17450419 -0.78908248]
 [ 0.00628894  0.9709144 ]]
[[3.67215593]
 [0.1338156 ]]
{'fraction_non_alphanumeric': 0.1943673145577152, 'fraction_numerical': 0.05632685442284808, 'mean_word_length': 6.8566978193146415, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '198190', 'license': 'AFL-1.1', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1242, 'n_words': 104, 'path': 'doc/source/AH-Polytope Overapproximation.ipynb', 'repo_name': 'Kasraghasemi/pypolycontain', 'size': '2521'}