Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -127,25 +127,32 @@ def compute_high_y_curve(betas, z_a, y):
|
|
127 |
numerator = -4*a*(a-1)*y*betas - 2*a*y - 2*a*(2*a-1)
|
128 |
return numerator/denominator
|
129 |
|
130 |
-
|
131 |
def compute_custom_expression(betas, z_a, y, num_expr_str, denom_expr_str):
|
132 |
"""
|
133 |
Compute a custom curve given numerator and denominator expressions
|
134 |
as strings that can depend on z_a, beta, and y.
|
|
|
135 |
"""
|
136 |
-
|
|
|
|
|
|
|
137 |
try:
|
138 |
-
num_expr = sp.sympify(num_expr_str)
|
139 |
-
denom_expr = sp.sympify(denom_expr_str)
|
140 |
-
except sp.SympifyError:
|
|
|
141 |
return np.full_like(betas, np.nan)
|
142 |
|
143 |
-
num_func = sp.lambdify((beta_sym, z_a_sym, y_sym), num_expr, "numpy")
|
144 |
-
denom_func = sp.lambdify((beta_sym, z_a_sym, y_sym), denom_expr, "numpy")
|
|
|
145 |
with np.errstate(divide='ignore', invalid='ignore'):
|
146 |
result = num_func(betas, z_a, y) / denom_func(betas, z_a, y)
|
147 |
return result
|
148 |
|
|
|
149 |
def generate_z_vs_beta_plot(z_a, y, z_min, z_max, beta_steps, z_steps,
|
150 |
custom_num_expr=None, custom_denom_expr=None):
|
151 |
if z_a <= 0 or y <= 0 or z_min >= z_max:
|
|
|
127 |
numerator = -4*a*(a-1)*y*betas - 2*a*y - 2*a*(2*a-1)
|
128 |
return numerator/denominator
|
129 |
|
130 |
+
|
131 |
def compute_custom_expression(betas, z_a, y, num_expr_str, denom_expr_str):
|
132 |
"""
|
133 |
Compute a custom curve given numerator and denominator expressions
|
134 |
as strings that can depend on z_a, beta, and y.
|
135 |
+
Allows 'a' as an alias for z_a.
|
136 |
"""
|
137 |
+
# Define allowed symbols. Also allow 'a' as an alias for z_a.
|
138 |
+
beta_sym, z_a_sym, y_sym, a_sym = sp.symbols("beta z_a y a", positive=True)
|
139 |
+
local_dict = {"beta": beta_sym, "z_a": z_a_sym, "y": y_sym, "a": z_a_sym}
|
140 |
+
|
141 |
try:
|
142 |
+
num_expr = sp.sympify(num_expr_str, locals=local_dict)
|
143 |
+
denom_expr = sp.sympify(denom_expr_str, locals=local_dict)
|
144 |
+
except sp.SympifyError as e:
|
145 |
+
st.error(f"Error parsing expressions: {e}")
|
146 |
return np.full_like(betas, np.nan)
|
147 |
|
148 |
+
num_func = sp.lambdify((beta_sym, z_a_sym, y_sym), num_expr, modules=["numpy"])
|
149 |
+
denom_func = sp.lambdify((beta_sym, z_a_sym, y_sym), denom_expr, modules=["numpy"])
|
150 |
+
|
151 |
with np.errstate(divide='ignore', invalid='ignore'):
|
152 |
result = num_func(betas, z_a, y) / denom_func(betas, z_a, y)
|
153 |
return result
|
154 |
|
155 |
+
|
156 |
def generate_z_vs_beta_plot(z_a, y, z_min, z_max, beta_steps, z_steps,
|
157 |
custom_num_expr=None, custom_denom_expr=None):
|
158 |
if z_a <= 0 or y <= 0 or z_min >= z_max:
|