bug fix
Browse files- slider values in inputs arguments when calling change methods
- use of partial to call the main function
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
| 3 |
from scipy import linalg
|
| 4 |
from sklearn.datasets import make_sparse_spd_matrix
|
| 5 |
from sklearn.covariance import GraphicalLassoCV, ledoit_wolf
|
|
@@ -125,15 +127,15 @@ title = "Sparse inverse covariance estimation"
|
|
| 125 |
with gr.Blocks(title=title) as demo:
|
| 126 |
gr.Markdown(f"## {title}")
|
| 127 |
gr.Markdown("Estimating covariance and sparse precision from a small number of samples using GraphicalLasso and Ledoit-Wolf algorithms.")
|
| 128 |
-
n_samples = gr.Slider(minimum=20, maximum=100, step=5,
|
| 129 |
label = "Number of Samples")
|
| 130 |
-
n_features = gr.Slider(minimum=10, maximum=100, step=5,
|
| 131 |
label = "Number of features")
|
| 132 |
-
alpha = gr.Slider(minimum=0, maximum=1, step=0.1,
|
| 133 |
label = "sparsity coefficient (alpha)")
|
| 134 |
-
smallest_coef = gr.Slider(minimum=0, maximum=1, step=0.1,
|
| 135 |
label = "minimum correlation value")
|
| 136 |
-
largest_coef = gr.Slider(minimum=0, maximum=1, step=0.1,
|
| 137 |
label = "maximum correlation value")
|
| 138 |
|
| 139 |
models = ['empirical', 'lasso', 'leidot-wolf']
|
|
@@ -142,11 +144,12 @@ with gr.Blocks(title=title) as demo:
|
|
| 142 |
|
| 143 |
model = models[model_counter]
|
| 144 |
plot = gr.Plot(label=model)
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
| 150 |
|
| 151 |
|
| 152 |
demo.launch()
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
+
|
| 4 |
+
from functools import partial
|
| 5 |
from scipy import linalg
|
| 6 |
from sklearn.datasets import make_sparse_spd_matrix
|
| 7 |
from sklearn.covariance import GraphicalLassoCV, ledoit_wolf
|
|
|
|
| 127 |
with gr.Blocks(title=title) as demo:
|
| 128 |
gr.Markdown(f"## {title}")
|
| 129 |
gr.Markdown("Estimating covariance and sparse precision from a small number of samples using GraphicalLasso and Ledoit-Wolf algorithms.")
|
| 130 |
+
n_samples = gr.Slider(minimum=20, maximum=100, step=5, value=60,
|
| 131 |
label = "Number of Samples")
|
| 132 |
+
n_features = gr.Slider(minimum=10, maximum=100, step=5, value=20,
|
| 133 |
label = "Number of features")
|
| 134 |
+
alpha = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.98,
|
| 135 |
label = "sparsity coefficient (alpha)")
|
| 136 |
+
smallest_coef = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.4,
|
| 137 |
label = "minimum correlation value")
|
| 138 |
+
largest_coef = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.7,
|
| 139 |
label = "maximum correlation value")
|
| 140 |
|
| 141 |
models = ['empirical', 'lasso', 'leidot-wolf']
|
|
|
|
| 144 |
|
| 145 |
model = models[model_counter]
|
| 146 |
plot = gr.Plot(label=model)
|
| 147 |
+
fn = partial(compute_and_plot, model=input_model, measure='covariance')
|
| 148 |
+
n_samples.change(fn=fn, inputs=[alpha, smallest_coef, largest_coef, n_features, n_samples], outputs=plot)
|
| 149 |
+
n_features.change(fn=fn, inputs=[alpha, smallest_coef, largest_coef, n_features, n_samples], outputs=plot)
|
| 150 |
+
alpha.change(fn=fn, inputs=[alpha, smallest_coef, largest_coef, n_features, n_samples], outputs=plot)
|
| 151 |
+
smallest_coef.change(fn=fn, inputs=[alpha, smallest_coef, largest_coef, n_features, n_samples], outputs=plot)
|
| 152 |
+
largest_coef.change(fn=fn, inputs=[alpha, smallest_coef, largest_coef, n_features, n_samples], outputs=plot)
|
| 153 |
|
| 154 |
|
| 155 |
demo.launch()
|