NathanBiliToponi commited on
Commit
cf4786b
·
verified ·
1 Parent(s): e778887

Upload index.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +33 -422
index.html CHANGED
@@ -2,53 +2,48 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>FoldCheck</title>
 
7
  <style>
8
- body {
9
- font-family: system-ui, sans-serif;
10
- max-width: 1000px;
11
- margin: 40px auto;
12
- padding: 0 20px;
13
- background: #0b1020;
14
- color: #e8ecf3;
15
  }
16
- .card {
17
- background: #151c30;
18
- border: 1px solid #2a3552;
19
- border-radius: 14px;
20
- padding: 24px;
21
- margin-bottom: 20px;
22
  }
23
- h1 { margin-bottom: 4px; }
24
- label { display:block; margin-top:14px; font-weight:600; }
25
- input, button {
26
  width:100%;
27
  box-sizing:border-box;
28
  padding:12px;
29
- margin-top:6px;
30
  border-radius:8px;
31
- border:1px solid #44506d;
32
- background:#0f1628;
33
- color:white;
34
  }
35
- button {
36
  background:#ff7a18;
 
37
  border:0;
38
  font-weight:700;
39
  cursor:pointer;
40
- margin-top:20px;
41
  }
42
- pre {
 
43
  white-space:pre-wrap;
44
  background:#090e1a;
45
  padding:18px;
46
  border-radius:10px;
47
- overflow:auto;
48
  }
49
- .small { color:#aeb8cc; font-size:14px; }
50
- .pass { color:#55d98b; }
51
- .fail { color:#ff7b7b; }
52
  </style>
53
  </head>
54
 
@@ -56,9 +51,11 @@ pre {
56
 
57
  <div class="card">
58
  <h1>📐 FoldCheck</h1>
 
59
  <p>Blind numerical screening for fold / saddle-node candidates.</p>
 
60
  <p class="small">
61
- Your CSV is processed locally in your browser. It is not uploaded to a server.
62
  </p>
63
 
64
  <label>CSV file</label>
@@ -76,406 +73,20 @@ Your CSV is processed locally in your browser. It is not uploaded to a server.
76
  <label>Required consecutive steps per branch</label>
77
  <input id="steps" type="number" value="10">
78
 
79
- <button onclick="run()">Analyze</button>
 
 
80
  </div>
81
 
82
  <div class="card">
83
  <h2>Result</h2>
84
- <pre id="result">Waiting for data.</pre>
85
- <button onclick="downloadJSON()">Download JSON report</button>
86
- </div>
87
-
88
- <script>
89
- let lastReport = null;
90
-
91
- function parseCSV(text) {
92
- const lines = text.trim().split(/\r?\n/);
93
- const headers = lines[0].split(",").map(x => x.trim());
94
-
95
- return lines.slice(1).map(line => {
96
- const vals = line.split(",");
97
- const row = {};
98
- headers.forEach((h,i) => row[h] = vals[i] === undefined ? "" : vals[i].trim());
99
- return row;
100
- });
101
- }
102
-
103
- function mean(a) {
104
- return a.reduce((s,x)=>s+x,0)/a.length;
105
- }
106
-
107
- function solve3(A,b) {
108
- const M = A.map((r,i)=>[...r,b[i]]);
109
-
110
- for(let i=0;i<3;i++){
111
- let pivot=i;
112
-
113
- for(let j=i+1;j<3;j++)
114
- if(Math.abs(M[j][i]) > Math.abs(M[pivot][i]))
115
- pivot=j;
116
-
117
- [M[i],M[pivot]]=[M[pivot],M[i]];
118
-
119
- if(Math.abs(M[i][i]) < 1e-15) return null;
120
-
121
- const d=M[i][i];
122
- for(let k=i;k<4;k++) M[i][k]/=d;
123
-
124
- for(let j=0;j<3;j++){
125
- if(j===i) continue;
126
- const f=M[j][i];
127
- for(let k=i;k<4;k++)
128
- M[j][k]-=f*M[i][k];
129
- }
130
- }
131
-
132
- return [M[0][3],M[1][3],M[2][3]];
133
- }
134
-
135
- function quadFit(x,y) {
136
- let s0=x.length, s1=0,s2=0,s3=0,s4=0;
137
- let t0=0,t1=0,t2=0;
138
-
139
- for(let i=0;i<x.length;i++){
140
- const X=x[i], Y=y[i];
141
- const X2=X*X;
142
-
143
- s1+=X;
144
- s2+=X2;
145
- s3+=X2*X;
146
- s4+=X2*X2;
147
-
148
- t0+=Y;
149
- t1+=X*Y;
150
- t2+=X2*Y;
151
- }
152
-
153
- return solve3(
154
- [[s4,s3,s2],[s3,s2,s1],[s2,s1,s0]],
155
- [t2,t1,t0]
156
- );
157
- }
158
-
159
- function linearRegression(x,y) {
160
- const mx=mean(x), my=mean(y);
161
-
162
- let sxx=0,sxy=0,syy=0;
163
-
164
- for(let i=0;i<x.length;i++){
165
- const dx=x[i]-mx;
166
- const dy=y[i]-my;
167
- sxx+=dx*dx;
168
- sxy+=dx*dy;
169
- syy+=dy*dy;
170
- }
171
-
172
- if(sxx===0) return null;
173
-
174
- const slope=sxy/sxx;
175
- const intercept=my-slope*mx;
176
-
177
- let rss=0;
178
-
179
- for(let i=0;i<x.length;i++){
180
- const e=y[i]-(intercept+slope*x[i]);
181
- rss+=e*e;
182
- }
183
-
184
- const r2=syy===0 ? NaN : 1-rss/syy;
185
-
186
- let stderr=null;
187
-
188
- if(x.length>2){
189
- const sigma2=rss/(x.length-2);
190
- stderr=Math.sqrt(sigma2/sxx);
191
- }
192
-
193
- return {slope,intercept,r2,rss,stderr};
194
- }
195
-
196
- function r2(y,yhat){
197
- const m=mean(y);
198
-
199
- let rss=0,tss=0;
200
-
201
- for(let i=0;i<y.length;i++){
202
- rss+=(y[i]-yhat[i])**2;
203
- tss+=(y[i]-m)**2;
204
- }
205
-
206
- return tss===0 ? NaN : 1-rss/tss;
207
- }
208
-
209
- function aic(y,yhat,k){
210
- let rss=0;
211
-
212
- for(let i=0;i<y.length;i++)
213
- rss+=(y[i]-yhat[i])**2;
214
-
215
- rss=Math.max(rss,Number.MIN_VALUE);
216
-
217
- return y.length*Math.log(rss/y.length)+2*k;
218
- }
219
-
220
- function consecutiveSteps(points, pc, xc, left, threshold){
221
- let branch=points.filter(q => left ? q.x<xc : q.x>xc);
222
-
223
- branch.sort(
224
- (a,b)=>Math.abs(a.x-xc)-Math.abs(b.x-xc)
225
- );
226
-
227
- let count=0;
228
-
229
- for(let i=0;i<branch.length-1;i++){
230
- const rel=
231
- Math.abs(branch[i+1].p-branch[i].p) /
232
- Math.max(Math.abs(pc),Number.EPSILON);
233
-
234
- if(rel<threshold)
235
- count++;
236
- else
237
- break;
238
- }
239
-
240
- return count;
241
- }
242
-
243
- async function run(){
244
-
245
- const file=document.getElementById("file").files[0];
246
-
247
- if(!file){
248
- alert("Choose a CSV file.");
249
- return;
250
- }
251
-
252
- const pcol=document.getElementById("pcol").value.trim();
253
- const xcol=document.getElementById("xcol").value.trim();
254
-
255
- const resolution=
256
- Number(document.getElementById("resolution").value);
257
 
258
- const required=
259
- Number(document.getElementById("steps").value);
260
-
261
- const rows=parseCSV(await file.text());
262
-
263
- let pts=rows
264
- .map(r=>({p:Number(r[pcol]),x:Number(r[xcol])}))
265
- .filter(q=>Number.isFinite(q.p)&&Number.isFinite(q.x));
266
-
267
- if(pts.length<9){
268
- document.getElementById("result").textContent=
269
- "Not enough valid numeric points.";
270
- return;
271
- }
272
-
273
- pts.sort((a,b)=>a.x-b.x);
274
-
275
- let best=null;
276
-
277
- const minWindow=9;
278
- const maxWindow=Math.min(
279
- 31,
280
- pts.length%2 ? pts.length : pts.length-1
281
- );
282
-
283
- for(let win=minWindow;win<=maxWindow;win+=2){
284
-
285
- const half=Math.floor(win/2);
286
-
287
- for(let center=half;center<pts.length-half;center++){
288
-
289
- const slice=pts.slice(center-half,center+half+1);
290
-
291
- const xs=slice.map(q=>q.x);
292
- const ps=slice.map(q=>q.p);
293
-
294
- const x0=mean(xs);
295
- const u=xs.map(v=>v-x0);
296
-
297
- const q=quadFit(u,ps);
298
-
299
- if(!q) continue;
300
-
301
- const [a,b,c]=q;
302
-
303
- if(Math.abs(a)<1e-15) continue;
304
-
305
- const uv=-b/(2*a);
306
- const xc=x0+uv;
307
-
308
- if(xc<Math.min(...xs)||xc>Math.max(...xs))
309
- continue;
310
-
311
- const pc=a*uv*uv+b*uv+c;
312
-
313
- const qhat=u.map(v=>a*v*v+b*v+c);
314
-
315
- const lin=linearRegression(u,ps);
316
-
317
- if(!lin) continue;
318
-
319
- const lhat=u.map(v=>lin.intercept+lin.slope*v);
320
-
321
- const qr2=r2(ps,qhat);
322
-
323
- const deltaAIC=
324
- aic(ps,lhat,2)-aic(ps,qhat,3);
325
-
326
- const candidate={
327
- pc,xc,
328
- window:win,
329
- quadratic_r2:qr2,
330
- delta_aic_linear_minus_quadratic:deltaAIC
331
- };
332
-
333
- if(
334
- !best ||
335
- candidate.delta_aic_linear_minus_quadratic >
336
- best.delta_aic_linear_minus_quadratic
337
- )
338
- best=candidate;
339
- }
340
- }
341
-
342
- if(!best){
343
-
344
- lastReport={
345
- verdict:"NO_TURNING_POINT_CANDIDATE",
346
- n_points:pts.length
347
- };
348
-
349
- document.getElementById("result").textContent=
350
- JSON.stringify(lastReport,null,2);
351
-
352
- return;
353
- }
354
-
355
- const pc=best.pc;
356
- const xc=best.xc;
357
-
358
- let scale=[];
359
-
360
- for(const side of [-1,1]){
361
-
362
- let branch=pts.filter(q=>
363
- side<0 ? q.x<xc : q.x>xc
364
- );
365
-
366
- branch.sort(
367
- (a,b)=>Math.abs(a.x-xc)-Math.abs(b.x-xc)
368
- );
369
-
370
- branch=branch.slice(0,12);
371
-
372
- for(const q of branch){
373
-
374
- const dp=Math.abs(q.p-pc);
375
- const dx=Math.abs(q.x-xc);
376
-
377
- if(dp>0&&dx>0)
378
- scale.push({
379
- lp:Math.log(dp),
380
- lx:Math.log(dx)
381
- });
382
- }
383
- }
384
-
385
- let beta=null, betaCI=[null,null], scalingR2=null;
386
-
387
- if(scale.length>=4){
388
-
389
- const reg=linearRegression(
390
- scale.map(q=>q.lp),
391
- scale.map(q=>q.lx)
392
- );
393
-
394
- beta=reg.slope;
395
- scalingR2=reg.r2;
396
-
397
- if(reg.stderr!==null){
398
- betaCI=[
399
- beta-1.96*reg.stderr,
400
- beta+1.96*reg.stderr
401
- ];
402
- }
403
- }
404
-
405
- const leftSteps=
406
- consecutiveSteps(pts,pc,xc,true,resolution);
407
-
408
- const rightSteps=
409
- consecutiveSteps(pts,pc,xc,false,resolution);
410
-
411
- const gate=
412
- leftSteps>=required &&
413
- rightSteps>=required;
414
-
415
- let verdict;
416
-
417
- if(
418
- best.delta_aic_linear_minus_quadratic<=0 ||
419
- best.quadratic_r2<0.9
420
- )
421
- verdict="WEAK_OR_NO_FOLD_EVIDENCE";
422
-
423
- else if(beta===null)
424
- verdict="FOLD_CANDIDATE_SCALING_INCONCLUSIVE";
425
-
426
- else if(gate)
427
- verdict="FOLD_CANDIDATE_PRIMARY_RESOLUTION_PASS";
428
-
429
- else
430
- verdict="FOLD_CANDIDATE_RESOLUTION_FAIL";
431
-
432
- lastReport={
433
- n_points:pts.length,
434
- pc,
435
- xc,
436
- quadratic_window:best.window,
437
- quadratic_r2:best.quadratic_r2,
438
- delta_aic_linear_minus_quadratic:
439
- best.delta_aic_linear_minus_quadratic,
440
- beta,
441
- beta_ci95:betaCI,
442
- scaling_r2:scalingR2,
443
- consecutive_steps_left:leftSteps,
444
- consecutive_steps_right:rightSteps,
445
- resolution_threshold:resolution,
446
- required_consecutive_steps_per_branch:required,
447
- resolution_gate_pass:gate,
448
- verdict,
449
- warning:
450
- "Numerical screening only. beta≈0.5 is not evidence of universality."
451
- };
452
-
453
- document.getElementById("result").textContent=
454
- JSON.stringify(lastReport,null,2);
455
- }
456
-
457
- function downloadJSON(){
458
-
459
- if(!lastReport){
460
- alert("Run an analysis first.");
461
- return;
462
- }
463
-
464
- const blob=new Blob(
465
- [JSON.stringify(lastReport,null,2)],
466
- {type:"application/json"}
467
- );
468
-
469
- const url=URL.createObjectURL(blob);
470
 
471
- const a=document.createElement("a");
472
- a.href=url;
473
- a.download="foldcheck_result.json";
474
- a.click();
475
 
476
- URL.revokeObjectURL(url);
477
- }
478
- </script>
479
 
480
  </body>
481
  </html>
 
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
  <title>FoldCheck</title>
7
+
8
  <style>
9
+ body{
10
+ font-family:system-ui,sans-serif;
11
+ max-width:1000px;
12
+ margin:40px auto;
13
+ padding:0 20px;
14
+ background:#0b1020;
15
+ color:#e8ecf3;
16
  }
17
+ .card{
18
+ background:#151c30;
19
+ border:1px solid #2a3552;
20
+ border-radius:14px;
21
+ padding:24px;
22
+ margin-bottom:20px;
23
  }
24
+ input,button{
 
 
25
  width:100%;
26
  box-sizing:border-box;
27
  padding:12px;
28
+ margin:6px 0 14px;
29
  border-radius:8px;
 
 
 
30
  }
31
+ button{
32
  background:#ff7a18;
33
+ color:white;
34
  border:0;
35
  font-weight:700;
36
  cursor:pointer;
 
37
  }
38
+ button:disabled{opacity:.5}
39
+ pre{
40
  white-space:pre-wrap;
41
  background:#090e1a;
42
  padding:18px;
43
  border-radius:10px;
 
44
  }
45
+ label{font-weight:600}
46
+ .small{color:#aeb8cc}
 
47
  </style>
48
  </head>
49
 
 
51
 
52
  <div class="card">
53
  <h1>📐 FoldCheck</h1>
54
+
55
  <p>Blind numerical screening for fold / saddle-node candidates.</p>
56
+
57
  <p class="small">
58
+ CSV processing happens locally in your browser.
59
  </p>
60
 
61
  <label>CSV file</label>
 
73
  <label>Required consecutive steps per branch</label>
74
  <input id="steps" type="number" value="10">
75
 
76
+ <button id="analyze">Analyze</button>
77
+
78
+ <p id="status" class="small">Ready.</p>
79
  </div>
80
 
81
  <div class="card">
82
  <h2>Result</h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ <pre id="result">Waiting for data.</pre>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
+ <button id="download">Download JSON report</button>
87
+ </div>
 
 
88
 
89
+ <script src="app.js" defer></script>
 
 
90
 
91
  </body>
92
  </html>