11import marimo
22
3- __generated_with = "0.17.6 "
3+ __generated_with = "0.17.7 "
44app = marimo .App (width = "medium" )
55
66
@@ -21,7 +21,7 @@ def _():
2121 import marimo as mo
2222 import numpy as np
2323 import cvxpy as cp
24- from dbcp import BiconvexProblem
24+ from dbcp import BiconvexProblem , convolve
2525
2626 import matplotlib as mpl
2727 import matplotlib .pyplot as plt
@@ -35,7 +35,7 @@ def _():
3535 os .makedirs ('./figures' )
3636
3737 np .random .seed (10015 )
38- return BiconvexProblem , cp , mo , np , plt
38+ return BiconvexProblem , convolve , cp , mo , np , plt
3939
4040
4141@app .cell (hide_code = True )
@@ -109,16 +109,19 @@ def _(mo):
109109
110110
111111@app .cell
112- def _ (BiconvexProblem , conv , cp , d , m , n ):
112+ def _ (BiconvexProblem , convolve , cp , d , m , n ):
113113 alpha_sp = 0.1
114114 alpha_sm = 0.2
115115 beta = 1
116116
117117 x = cp .Variable (n , nonneg = True )
118118 y = cp .Variable (m , nonneg = True )
119- obj = cp .sum_squares (conv (x , y ) - d ) + alpha_sp * cp .norm1 (x ) + alpha_sm * cp .sum_squares (cp .diff (y ))
119+ obj = cp .Minimize (
120+ cp .sum_squares (convolve (x , y ) - d )
121+ + alpha_sp * cp .norm1 (x )
122+ + alpha_sm * cp .sum_squares (cp .diff (y )))
120123 constr = [cp .norm (y , "inf" ) <= beta ]
121- prob = BiconvexProblem (cp . Minimize ( obj ) , [[x ], [y ]], constr )
124+ prob = BiconvexProblem (obj , [[x ], [y ]], constr )
122125 prob .solve (cp .CLARABEL , gap_tolerance = 1e-5 , max_iter = 200 )
123126 return x , y
124127
@@ -157,16 +160,5 @@ def _(d, np, plt, x, x0, y, y0):
157160 return
158161
159162
160- @app .cell (hide_code = True )
161- def _ (cp ):
162- def conv (x , y ):
163- c = [0 ] * (x .shape [0 ] + y .shape [0 ] - 1 )
164- for _i , _a in enumerate (y ):
165- for _j , _b in enumerate (x ):
166- c [_i + _j ] += _a * _b
167- return cp .hstack (c )
168- return (conv ,)
169-
170-
171163if __name__ == "__main__" :
172164 app .run ()
0 commit comments