Spaces:
Runtime error
Runtime error
Update app/services/inference_engine.py
Browse files
app/services/inference_engine.py
CHANGED
|
@@ -142,4 +142,48 @@ def compute_score_range(edges, nodes):
|
|
| 142 |
return {
|
| 143 |
"edges": [min_edge, max_edge],
|
| 144 |
"nodes": [min_node, max_node]
|
| 145 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
return {
|
| 143 |
"edges": [min_edge, max_edge],
|
| 144 |
"nodes": [min_node, max_node]
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
def generate_edge_scores_v2(edge, dataset_meta):
|
| 148 |
+
scores = {}
|
| 149 |
+
|
| 150 |
+
for algo in ALGORITHMS:
|
| 151 |
+
|
| 152 |
+
compatible = is_algorithm_compatible(algo, dataset_meta)
|
| 153 |
+
|
| 154 |
+
# synthetic override
|
| 155 |
+
if getattr(dataset_meta, "isSynthetic", False):
|
| 156 |
+
compatible = True
|
| 157 |
+
|
| 158 |
+
if not compatible:
|
| 159 |
+
scores[algo.name] = None
|
| 160 |
+
continue
|
| 161 |
+
|
| 162 |
+
if algo.requiresTFList and not edge.get("isTFEdge", False):
|
| 163 |
+
if not getattr(dataset_meta, "isSynthetic", False):
|
| 164 |
+
scores[algo.name] = None
|
| 165 |
+
continue
|
| 166 |
+
|
| 167 |
+
if algo.undirected and edge["source"] > edge["target"]:
|
| 168 |
+
if not getattr(dataset_meta, "isSynthetic", False):
|
| 169 |
+
scores[algo.name] = None
|
| 170 |
+
continue
|
| 171 |
+
|
| 172 |
+
h = simple_hash(f"{edge['source']}-{edge['target']}-{algo.name}")
|
| 173 |
+
probability = (h % 1000) / 1000
|
| 174 |
+
|
| 175 |
+
sparsity = algo.edgeSparsity
|
| 176 |
+
if getattr(dataset_meta, "isSynthetic", False):
|
| 177 |
+
sparsity = min(sparsity + 0.1, 0.99)
|
| 178 |
+
|
| 179 |
+
if probability > sparsity:
|
| 180 |
+
scores[algo.name] = None
|
| 181 |
+
continue
|
| 182 |
+
|
| 183 |
+
gene_penalty = 0.85 if dataset_meta.nGenes > 15000 else 1
|
| 184 |
+
cell_penalty = 0.9 if dataset_meta.nCells < 200 else 1
|
| 185 |
+
|
| 186 |
+
base = 0.45 + ((h % 400) / 1000)
|
| 187 |
+
scores[algo.name] = round(base * gene_penalty * cell_penalty, 3)
|
| 188 |
+
|
| 189 |
+
return scores
|