import%20marimo%0A%0A__generated_with%20%3D%20%220.13.15%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0Awith%20app.setup%3A%0A%20%20%20%20import%20cvxpy%20as%20cp%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20plotly.graph_objects%20as%20go%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%23%20Problem%0A%0A%20%20%20%20We%20compute%20the%20radius%20and%20center%20of%20the%20smallest%20enclosing%20ball%20for%20%24N%24%20points%20in%20%24d%24%20dimensions.%0A%20%20%20%20We%20use%20a%20variety%20of%20tools%20and%20compare%20their%20performance.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20mo.md(%22%22%22%23%23%20Generate%20a%20cloud%20of%20points%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20rng%20%3D%20np.random.default_rng()%0A%20%20%20%20pos%20%3D%20rng.standard_normal((1000%2C%2011))%0A%20%20%20%20return%20(pos%2C)%0A%0A%0A%40app.cell%0Adef%20_(pos)%3A%0A%20%20%20%20%23%20Create%20the%20scatter%20plot%0A%20%20%20%20fig%20%3D%20go.Figure(data%3Dgo.Scatter(x%3Dpos%5B%3A%2C%200%5D%2C%20y%3Dpos%5B%3A%2C%201%5D%2C%20mode%3D%22markers%22%2C%20marker%3D%7B%22symbol%22%3A%20%22x%22%2C%20%22size%22%3A%2010%7D))%0A%0A%20%20%20%20%23%20Update%20layout%20for%20equal%20aspect%20ratio%20and%20axis%20labels%0A%20%20%20%20fig.update_layout(%0A%20%20%20%20%20%20%20%20xaxis_title%3D%22x%22%2C%0A%20%20%20%20%20%20%20%20yaxis_title%3D%22y%22%2C%0A%20%20%20%20%20%20%20%20yaxis%3D%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22scaleanchor%22%3A%20%22x%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22scaleratio%22%3A%201%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Show%20the%20plot%0A%20%20%20%20fig%0A%0A%20%20%20%20%23%20plot%20makes%20really%20only%20sense%20when%20using%20d%3D2%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20mo.md(%22%22%22%23%23%20Compute%20with%20cvxpy%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20min_circle_cvx(points%2C%20**kwargs)%3A%0A%20%20%20%20%22%22%22Compute%20the%20minimum%20enclosing%20circle%20using%20CVXPY.%0A%0A%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20points%3A%20Array%20of%20shape%20(N%2C%20d)%20containing%20N%20points%20in%20d%20dimensions%0A%20%20%20%20%20%20%20%20**kwargs%3A%20Additional%20arguments%20to%20pass%20to%20the%20CVXPY%20solver%0A%0A%20%20%20%20Returns%3A%0A%20%20%20%20%20%20%20%20Dictionary%20containing%20the%20radius%20and%20midpoint%20of%20the%20minimum%20enclosing%20circle%0A%20%20%20%20%22%22%22%0A%20%20%20%20%23%20cvxpy%20variable%20for%20the%20radius%0A%20%20%20%20r%20%3D%20cp.Variable(1%2C%20name%3D%22Radius%22)%0A%20%20%20%20%23%20cvxpy%20variable%20for%20the%20midpoint%0A%20%20%20%20x%20%3D%20cp.Variable(points.shape%5B1%5D%2C%20name%3D%22Midpoint%22)%0A%0A%20%20%20%20objective%20%3D%20cp.Minimize(r)%0A%20%20%20%20constraints%20%3D%20%5B%0A%20%20%20%20%20%20%20%20cp.SOC(%0A%20%20%20%20%20%20%20%20%20%20%20%20r%20*%20np.ones(points.shape%5B0%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20points%20-%20cp.outer(np.ones(points.shape%5B0%5D)%2C%20x)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20axis%3D1%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%5D%0A%0A%20%20%20%20problem%20%3D%20cp.Problem(objective%3Dobjective%2C%20constraints%3Dconstraints)%0A%20%20%20%20problem.solve(**kwargs)%0A%0A%20%20%20%20return%20%7B%22Radius%22%3A%20r.value%2C%20%22Midpoint%22%3A%20x.value%7D%0A%0A%0A%40app.cell%0Adef%20_(pos)%3A%0A%20%20%20%20min_circle_cvx(points%3Dpos%2C%20solver%3D%22CLARABEL%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
1b0be69333424f87cf78fd1d9f53efda5ed1d8ed65d979b781b3c47bb157d743