everydaytok commited on
Commit
f50e1c3
·
verified ·
1 Parent(s): 192a7aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -516,7 +516,6 @@ class VerifyLayer:
516
  elif inv.mode=="geq": passed=val>=-inv.tolerance
517
  elif inv.mode=="leq": passed=val<=inv.tolerance
518
  else: passed=err<inv.tolerance
519
- # UI Adjustment: if it's an inequality, return the raw value, not absolute error.
520
  g2[inv.name]=(round(val if inv.mode in ("geq","leq") else err,6),passed)
521
  except: g2[inv.name]=(999.0,False)
522
  g2_pass=all(v[1] for v in g2.values()) if g2 else True
@@ -1230,18 +1229,22 @@ def _hyp_composite(problem,baton,all_batons,model):
1230
  except: pass
1231
  return hyps
1232
 
 
 
 
 
 
 
 
 
 
1233
  def _hyp_parsimony(problem,baton,all_batons,model):
1234
- """
1235
- 15.6 FIX: Explicit L0-norm sparsity for SignalRecovery/Compressed Sensing.
1236
- Zeros out variables that are significantly smaller than the max magnitude.
1237
- """
1238
  b = dict(baton.binding)
1239
  nb = {}
1240
  max_val = max((abs(v) for v in b.values()), default=1.0)
1241
  for v in problem.variables:
1242
  val = b[v]
1243
  lo, hi = problem.bounds[v]
1244
- # Sparsity enforcement: if it's < 10% of the max signal, try snapping to exactly 0.0
1245
  if abs(val) < 0.1 * max_val and lo <= 0.0 <= hi:
1246
  nb[v] = 0.0
1247
  else:
@@ -1252,6 +1255,24 @@ def _hyp_parsimony(problem,baton,all_batons,model):
1252
  nb[v] = min(candidates, key=lambda c: abs(c - val)) if candidates else val
1253
  return [_make_hyp(f"par_{hash(str(nb))%9999}", nb, "parsimony", "OccamSparsity", ["parsimony"], {}, list(problem.variables), 0.58)]
1254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1255
  AXIOM_CONSTRUCTORS:Dict[str,Callable]={
1256
  Axiom.CONTINUOUS:_hyp_continuous, Axiom.DISCRETE:_hyp_discrete,
1257
  Axiom.QUADRATIC:_hyp_quadratic, Axiom.BILINEAR:_hyp_bilinear,
@@ -1295,10 +1316,6 @@ class SequenceHypothesisGenerator:
1295
 
1296
  best_ce=current.ce; best_b=current.binding
1297
 
1298
- # 15.6 FIX: Removed ThreadPoolExecutor.
1299
- # Sequential evaluation is vastly faster here because Python's GIL
1300
- # prevents true parallelism for SymPy CPU math anyway, and context
1301
- # switching was causing timeouts/dropped hypotheses.
1302
  valid_hyps = [h for h in sorted(new_hyps, key=lambda h: -h.confidence)[:MAX_HYPS_PER_AXIOM]
1303
  if h.hid not in model.failure_patterns]
1304
 
@@ -1427,11 +1444,10 @@ class SequenceRayTracer:
1427
  scout_rays = CREATIVE_SEEDER.random_scouts(n=500)
1428
  for r in scout_rays: r.ce_prior = init_ce
1429
 
1430
- # 15.6 FIX: Round-Robin Queue setup
1431
  queues = {
1432
- "core": [], # Seeds, Branches
1433
- "explore": [], # Scouts, Tensions
1434
- "genetic": [] # Recombine, Invert
1435
  }
1436
 
1437
  for r in seed_rays: queues["core"].append(r)
@@ -1453,14 +1469,13 @@ class SequenceRayTracer:
1453
  q_idx = 0
1454
 
1455
  while total_fired < self.MAX_TOTAL_RAYS:
1456
- # Round-Robin Pop
1457
  start_idx = q_idx
1458
  while not queues[queue_order[q_idx]]:
1459
  q_idx = (q_idx + 1) % 3
1460
  if q_idx == start_idx: break
1461
 
1462
  if not queues[queue_order[q_idx]]:
1463
- break # All queues empty
1464
 
1465
  ray = queues[queue_order[q_idx]].pop(0)
1466
  q_idx = (q_idx + 1) % 3
@@ -1531,13 +1546,11 @@ class SequenceRayTracer:
1531
  CREATIVE_SEEDER.resonance_extensions(
1532
  ray, output_baton.ce, shared_model.resonant_pairs))
1533
 
1534
- # Push children into appropriate buckets
1535
  for child in new_children:
1536
  if child.ray_type in (RAY_SEED, RAY_BRANCH): queues["core"].append(child)
1537
  elif child.ray_type in (RAY_SCOUT, RAY_TENSION): queues["explore"].append(child)
1538
  elif child.ray_type in (RAY_RECOMBINE, RAY_INVERT): queues["genetic"].append(child)
1539
 
1540
- # Keep A* priority within buckets (optional, keeps best stuff at front of its bucket)
1541
  queues["core"].sort(key=lambda r: r.ce_prior + (r.depth * 0.0001))
1542
  queues["genetic"].sort(key=lambda r: r.ce_prior + (r.depth * 0.0001))
1543
 
@@ -2182,4 +2195,4 @@ async def dashboard():
2182
  </body></html>"""
2183
 
2184
  if __name__=="__main__":
2185
- uvicorn.run(app,host="0.0.0.0",port=7860,log_level="warning")
 
516
  elif inv.mode=="geq": passed=val>=-inv.tolerance
517
  elif inv.mode=="leq": passed=val<=inv.tolerance
518
  else: passed=err<inv.tolerance
 
519
  g2[inv.name]=(round(val if inv.mode in ("geq","leq") else err,6),passed)
520
  except: g2[inv.name]=(999.0,False)
521
  g2_pass=all(v[1] for v in g2.values()) if g2 else True
 
1229
  except: pass
1230
  return hyps
1231
 
1232
+ def _hyp_holism(problem,baton,all_batons,model):
1233
+ b=dict(baton.binding); grad=problem.evaluate_gradient(b)
1234
+ gms=sum(g**2 for g in grad.values())
1235
+ if gms<1e-12: return []
1236
+ lr=min(0.5,baton.ce/(gms+1e-8))
1237
+ nb={v:max(problem.bounds[v][0],min(problem.bounds[v][1],b[v]-lr*grad[v])) for v in problem.variables}
1238
+ return [_make_hyp(f"hol_{hash(str(nb))%9999}",nb,"holism",
1239
+ f"Global(lr={lr:.4f})",["holism"],{},list(problem.variables),0.73)]
1240
+
1241
  def _hyp_parsimony(problem,baton,all_batons,model):
 
 
 
 
1242
  b = dict(baton.binding)
1243
  nb = {}
1244
  max_val = max((abs(v) for v in b.values()), default=1.0)
1245
  for v in problem.variables:
1246
  val = b[v]
1247
  lo, hi = problem.bounds[v]
 
1248
  if abs(val) < 0.1 * max_val and lo <= 0.0 <= hi:
1249
  nb[v] = 0.0
1250
  else:
 
1255
  nb[v] = min(candidates, key=lambda c: abs(c - val)) if candidates else val
1256
  return [_make_hyp(f"par_{hash(str(nb))%9999}", nb, "parsimony", "OccamSparsity", ["parsimony"], {}, list(problem.variables), 0.58)]
1257
 
1258
+ def _hyp_duality(problem,baton,all_batons,model):
1259
+ hyps=[]; b=dict(baton.binding)
1260
+ for mc in problem.compiled_constraints:
1261
+ if mc.kind!="inequality" or not mc.projections: continue
1262
+ for v,projs in mc.projections.items():
1263
+ lo,hi=problem.bounds.get(v,(-1e18,1e18))
1264
+ for proj in projs:
1265
+ try:
1266
+ val=float(proj["func"](*[b.get(s,0.0) for s in proj["syms"]]))
1267
+ if not(lo<=val<=hi) or not math.isfinite(val): continue
1268
+ nb=dict(b); nb[v]=val
1269
+ hyps.append(_make_hyp(f"dua_{hash(mc.expr_str)%9999}_{v}",nb,"duality",
1270
+ f"Tight({v})",["duality",mc.expr_str],{v:val},
1271
+ [u for u in problem.variables if u!=v],0.68))
1272
+ break
1273
+ except: pass
1274
+ return hyps
1275
+
1276
  AXIOM_CONSTRUCTORS:Dict[str,Callable]={
1277
  Axiom.CONTINUOUS:_hyp_continuous, Axiom.DISCRETE:_hyp_discrete,
1278
  Axiom.QUADRATIC:_hyp_quadratic, Axiom.BILINEAR:_hyp_bilinear,
 
1316
 
1317
  best_ce=current.ce; best_b=current.binding
1318
 
 
 
 
 
1319
  valid_hyps = [h for h in sorted(new_hyps, key=lambda h: -h.confidence)[:MAX_HYPS_PER_AXIOM]
1320
  if h.hid not in model.failure_patterns]
1321
 
 
1444
  scout_rays = CREATIVE_SEEDER.random_scouts(n=500)
1445
  for r in scout_rays: r.ce_prior = init_ce
1446
 
 
1447
  queues = {
1448
+ "core": [],
1449
+ "explore": [],
1450
+ "genetic": []
1451
  }
1452
 
1453
  for r in seed_rays: queues["core"].append(r)
 
1469
  q_idx = 0
1470
 
1471
  while total_fired < self.MAX_TOTAL_RAYS:
 
1472
  start_idx = q_idx
1473
  while not queues[queue_order[q_idx]]:
1474
  q_idx = (q_idx + 1) % 3
1475
  if q_idx == start_idx: break
1476
 
1477
  if not queues[queue_order[q_idx]]:
1478
+ break
1479
 
1480
  ray = queues[queue_order[q_idx]].pop(0)
1481
  q_idx = (q_idx + 1) % 3
 
1546
  CREATIVE_SEEDER.resonance_extensions(
1547
  ray, output_baton.ce, shared_model.resonant_pairs))
1548
 
 
1549
  for child in new_children:
1550
  if child.ray_type in (RAY_SEED, RAY_BRANCH): queues["core"].append(child)
1551
  elif child.ray_type in (RAY_SCOUT, RAY_TENSION): queues["explore"].append(child)
1552
  elif child.ray_type in (RAY_RECOMBINE, RAY_INVERT): queues["genetic"].append(child)
1553
 
 
1554
  queues["core"].sort(key=lambda r: r.ce_prior + (r.depth * 0.0001))
1555
  queues["genetic"].sort(key=lambda r: r.ce_prior + (r.depth * 0.0001))
1556
 
 
2195
  </body></html>"""
2196
 
2197
  if __name__=="__main__":
2198
+ uvicorn.run(app,host="0.0.0.0",port=7860,log_level="warning")