yahma commited on
Commit
d1dfb73
·
verified ·
1 Parent(s): d1e7fc0

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +749 -19
index.html CHANGED
@@ -1,19 +1,749 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
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>3D Gradient Descent Visualization</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/build/dat.gui.min.js"></script>
9
+ <style>
10
+ * {
11
+ margin: 0;
12
+ padding: 0;
13
+ box-sizing: border-box;
14
+ }
15
+
16
+ body {
17
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
18
+ background: linear-gradient(135deg, #0c0c0c 0%, #1a1a2e 50%, #16213e 100%);
19
+ color: #e0e0e0;
20
+ overflow-x: hidden;
21
+ min-height: 100vh;
22
+ }
23
+
24
+ .header {
25
+ background: rgba(10, 10, 20, 0.8);
26
+ backdrop-filter: blur(10px);
27
+ padding: 1.5rem 2rem;
28
+ border-bottom: 1px solid rgba(255, 255, 255, 0.1);
29
+ position: relative;
30
+ z-index: 100;
31
+ }
32
+
33
+ .header-content {
34
+ max-width: 1200px;
35
+ margin: 0 auto;
36
+ display: flex;
37
+ justify-content: space-between;
38
+ align-items: center;
39
+ }
40
+
41
+ .logo {
42
+ font-size: 1.8rem;
43
+ font-weight: 700;
44
+ background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
45
+ -webkit-background-clip: text;
46
+ -webkit-text-fill-color: transparent;
47
+ display: flex;
48
+ align-items: center;
49
+ gap: 0.5rem;
50
+ }
51
+
52
+ .anycoder-link {
53
+ color: #4facfe;
54
+ text-decoration: none;
55
+ font-size: 0.9rem;
56
+ font-weight: 500;
57
+ transition: all 0.3s ease;
58
+ padding: 0.5rem 1rem;
59
+ border-radius: 20px;
60
+ background: rgba(79, 172, 254, 0.1);
61
+ }
62
+
63
+ .anycoder-link:hover {
64
+ background: rgba(79, 172, 254, 0.2);
65
+ transform: translateY(-2px);
66
+ }
67
+
68
+ .container {
69
+ max-width: 1200px;
70
+ margin: 0 auto;
71
+ padding: 2rem;
72
+ }
73
+
74
+ .hero {
75
+ text-align: center;
76
+ margin-bottom: 3rem;
77
+ padding: 2rem 0;
78
+ }
79
+
80
+ .hero h1 {
81
+ font-size: 3.5rem;
82
+ background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
83
+ -webkit-background-clip: text;
84
+ -webkit-text-fill-color: transparent;
85
+ margin-bottom: 1rem;
86
+ font-weight: 800;
87
+ }
88
+
89
+ .hero p {
90
+ font-size: 1.2rem;
91
+ max-width: 700px;
92
+ margin: 0 auto 2rem;
93
+ color: #b0b0b0;
94
+ line-height: 1.6;
95
+ }
96
+
97
+ .visualization-container {
98
+ display: grid;
99
+ grid-template-columns: 1fr 350px;
100
+ gap: 2rem;
101
+ margin-bottom: 3rem;
102
+ }
103
+
104
+ .canvas-wrapper {
105
+ position: relative;
106
+ border-radius: 12px;
107
+ overflow: hidden;
108
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
109
+ background: rgba(15, 15, 25, 0.6);
110
+ border: 1px solid rgba(255, 255, 255, 0.1);
111
+ height: 600px;
112
+ }
113
+
114
+ #gradientDescentCanvas {
115
+ width: 100%;
116
+ height: 100%;
117
+ display: block;
118
+ }
119
+
120
+ .controls-panel {
121
+ background: rgba(20, 20, 35, 0.7);
122
+ border-radius: 12px;
123
+ padding: 1.5rem;
124
+ border: 1px solid rgba(255, 255, 255, 0.1);
125
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
126
+ backdrop-filter: blur(10px);
127
+ height: fit-content;
128
+ }
129
+
130
+ .controls-panel h2 {
131
+ font-size: 1.5rem;
132
+ margin-bottom: 1.5rem;
133
+ color: #4facfe;
134
+ display: flex;
135
+ align-items: center;
136
+ gap: 0.5rem;
137
+ }
138
+
139
+ .control-group {
140
+ margin-bottom: 1.5rem;
141
+ }
142
+
143
+ .control-group h3 {
144
+ font-size: 1.1rem;
145
+ margin-bottom: 0.8rem;
146
+ color: #00f2fe;
147
+ }
148
+
149
+ .slider-container {
150
+ margin-bottom: 1rem;
151
+ }
152
+
153
+ .slider-label {
154
+ display: flex;
155
+ justify-content: space-between;
156
+ margin-bottom: 0.3rem;
157
+ font-size: 0.9rem;
158
+ }
159
+
160
+ .slider {
161
+ width: 100%;
162
+ height: 6px;
163
+ background: rgba(255, 255, 255, 0.1);
164
+ border-radius: 3px;
165
+ outline: none;
166
+ -webkit-appearance: none;
167
+ }
168
+
169
+ .slider::-webkit-slider-thumb {
170
+ -webkit-appearance: none;
171
+ width: 18px;
172
+ height: 18px;
173
+ border-radius: 50%;
174
+ background: #4facfe;
175
+ cursor: pointer;
176
+ transition: all 0.2s ease;
177
+ }
178
+
179
+ .slider::-webkit-slider-thumb:hover {
180
+ background: #00f2fe;
181
+ transform: scale(1.2);
182
+ }
183
+
184
+ .button-group {
185
+ display: grid;
186
+ grid-template-columns: 1fr 1fr;
187
+ gap: 0.8rem;
188
+ margin-top: 1rem;
189
+ }
190
+
191
+ .btn {
192
+ padding: 0.8rem 1rem;
193
+ border: none;
194
+ border-radius: 6px;
195
+ font-weight: 600;
196
+ cursor: pointer;
197
+ transition: all 0.3s ease;
198
+ display: flex;
199
+ align-items: center;
200
+ justify-content: center;
201
+ gap: 0.5rem;
202
+ }
203
+
204
+ .btn-primary {
205
+ background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
206
+ color: #0c0c0c;
207
+ }
208
+
209
+ .btn-secondary {
210
+ background: rgba(255, 255, 255, 0.1);
211
+ color: #e0e0e0;
212
+ border: 1px solid rgba(255, 255, 255, 0.2);
213
+ }
214
+
215
+ .btn:hover {
216
+ transform: translateY(-2px);
217
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
218
+ }
219
+
220
+ .btn:active {
221
+ transform: translateY(0);
222
+ }
223
+
224
+ .info-section {
225
+ background: rgba(20, 20, 35, 0.7);
226
+ border-radius: 12px;
227
+ padding: 2rem;
228
+ margin-top: 2rem;
229
+ border: 1px solid rgba(255, 255, 255, 0.1);
230
+ }
231
+
232
+ .info-section h2 {
233
+ font-size: 1.8rem;
234
+ margin-bottom: 1.5rem;
235
+ color: #4facfe;
236
+ }
237
+
238
+ .info-grid {
239
+ display: grid;
240
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
241
+ gap: 1.5rem;
242
+ }
243
+
244
+ .info-card {
245
+ background: rgba(30, 30, 50, 0.5);
246
+ border-radius: 8px;
247
+ padding: 1.5rem;
248
+ border-left: 4px solid #4facfe;
249
+ }
250
+
251
+ .info-card h3 {
252
+ font-size: 1.2rem;
253
+ margin-bottom: 0.8rem;
254
+ color: #00f2fe;
255
+ }
256
+
257
+ .info-card p {
258
+ color: #b0b0b0;
259
+ line-height: 1.6;
260
+ }
261
+
262
+ .footer {
263
+ text-align: center;
264
+ padding: 2rem;
265
+ margin-top: 3rem;
266
+ border-top: 1px solid rgba(255, 255, 255, 0.1);
267
+ color: #888;
268
+ font-size: 0.9rem;
269
+ }
270
+
271
+ @media (max-width: 968px) {
272
+ .visualization-container {
273
+ grid-template-columns: 1fr;
274
+ }
275
+
276
+ .hero h1 {
277
+ font-size: 2.5rem;
278
+ }
279
+
280
+ .canvas-wrapper {
281
+ height: 500px;
282
+ }
283
+ }
284
+
285
+ @media (max-width: 600px) {
286
+ .container {
287
+ padding: 1rem;
288
+ }
289
+
290
+ .hero h1 {
291
+ font-size: 2rem;
292
+ }
293
+
294
+ .canvas-wrapper {
295
+ height: 400px;
296
+ }
297
+
298
+ .button-group {
299
+ grid-template-columns: 1fr;
300
+ }
301
+ }
302
+
303
+ .loading {
304
+ position: absolute;
305
+ top: 0;
306
+ left: 0;
307
+ width: 100%;
308
+ height: 100%;
309
+ background: rgba(10, 10, 20, 0.9);
310
+ display: flex;
311
+ flex-direction: column;
312
+ justify-content: center;
313
+ align-items: center;
314
+ z-index: 10;
315
+ color: #4facfe;
316
+ font-size: 1.2rem;
317
+ }
318
+
319
+ .spinner {
320
+ width: 50px;
321
+ height: 50px;
322
+ border: 5px solid rgba(79, 172, 254, 0.3);
323
+ border-top: 5px solid #4facfe;
324
+ border-radius: 50%;
325
+ animation: spin 1s linear infinite;
326
+ margin-bottom: 1rem;
327
+ }
328
+
329
+ @keyframes spin {
330
+ 0% { transform: rotate(0deg); }
331
+ 100% { transform: rotate(360deg); }
332
+ }
333
+
334
+ .hidden {
335
+ display: none;
336
+ }
337
+ </style>
338
+ </head>
339
+ <body>
340
+ <div class="header">
341
+ <div class="header-content">
342
+ <div class="logo">
343
+ <span>∇ GradientVision</span>
344
+ </div>
345
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" class="anycoder-link">Built with anycoder</a>
346
+ </div>
347
+ </div>
348
+
349
+ <div class="container">
350
+ <div class="hero">
351
+ <h1>3D Gradient Descent Visualization</h1>
352
+ <p>Explore the complex optimization landscape of machine learning algorithms in an immersive 3D environment. Watch as gradient descent navigates through intricate mathematical terrains to find optimal solutions.</p>
353
+ </div>
354
+
355
+ <div class="visualization-container">
356
+ <div class="canvas-wrapper">
357
+ <div id="loading" class="loading">
358
+ <div class="spinner"></div>
359
+ <p>Initializing 3D Visualization...</p>
360
+ </div>
361
+ <canvas id="gradientDescentCanvas"></canvas>
362
+ </div>
363
+
364
+ <div class="controls-panel">
365
+ <h2>⚙️ Control Panel</h2>
366
+
367
+ <div class="control-group">
368
+ <h3>Learning Parameters</h3>
369
+ <div class="slider-container">
370
+ <div class="slider-label">
371
+ <span>Learning Rate</span>
372
+ <span id="learningRateValue">0.1</span>
373
+ </div>
374
+ <input type="range" min="0.001" max="0.5" step="0.001" value="0.1" class="slider" id="learningRate">
375
+ </div>
376
+
377
+ <div class="slider-container">
378
+ <div class="slider-label">
379
+ <span>Iterations</span>
380
+ <span id="iterationsValue">100</span>
381
+ </div>
382
+ <input type="range" min="10" max="500" step="10" value="100" class="slider" id="iterations">
383
+ </div>
384
+ </div>
385
+
386
+ <div class="control-group">
387
+ <h3>Visualization</h3>
388
+ <div class="slider-container">
389
+ <div class="slider-label">
390
+ <span>Animation Speed</span>
391
+ <span id="speedValue">1.0</span>
392
+ </div>
393
+ <input type="range" min="0.1" max="5" step="0.1" value="1.0" class="slider" id="animationSpeed">
394
+ </div>
395
+
396
+ <div class="slider-container">
397
+ <div class="slider-label">
398
+ <span>Surface Complexity</span>
399
+ <span id="complexityValue">3</span>
400
+ </div>
401
+ <input type="range" min="1" max="5" step="1" value="3" class="slider" id="surfaceComplexity">
402
+ </div>
403
+ </div>
404
+
405
+ <div class="button-group">
406
+ <button id="startBtn" class="btn btn-primary">
407
+ <span>▶️ Start</span>
408
+ </button>
409
+ <button id="resetBtn" class="btn btn-secondary">
410
+ <span>🔄 Reset</span>
411
+ </button>
412
+ <button id="pauseBtn" class="btn btn-secondary">
413
+ <span>⏸️ Pause</span>
414
+ </button>
415
+ <button id="randomizeBtn" class="btn btn-secondary">
416
+ <span>🎲 Randomize</span>
417
+ </button>
418
+ </div>
419
+ </div>
420
+ </div>
421
+
422
+ <div class="info-section">
423
+ <h2>Understanding Gradient Descent</h2>
424
+ <div class="info-grid">
425
+ <div class="info-card">
426
+ <h3>What is Gradient Descent?</h3>
427
+ <p>Gradient descent is an optimization algorithm used to minimize functions by iteratively moving in the direction of steepest descent as defined by the negative of the gradient.</p>
428
+ </div>
429
+ <div class="info-card">
430
+ <h3>The Learning Process</h3>
431
+ <p>The algorithm calculates the gradient of the loss function and updates parameters in the opposite direction, scaled by the learning rate.</p>
432
+ </div>
433
+ <div class="info-card">
434
+ <h3>3D Visualization</h3>
435
+ <p>This visualization shows a complex 3D loss surface where gradient descent navigates through valleys and peaks to find the global minimum.</p>
436
+ </div>
437
+ </div>
438
+ </div>
439
+ </div>
440
+
441
+ <div class="footer">
442
+ <p>Interactive 3D Gradient Descent Visualization | Advanced Machine Learning Concepts</p>
443
+ </div>
444
+
445
+ <script>
446
+ // Three.js Gradient Descent Visualization
447
+ let scene, camera, renderer;
448
+ let lossSurface, gradientPath, currentPoint;
449
+ let isAnimating = false;
450
+ let animationId;
451
+ let currentIteration = 0;
452
+ let totalIterations = 100;
453
+ let learningRate = 0.1;
454
+ let animationSpeed = 1.0;
455
+ let surfaceComplexity = 3;
456
+
457
+ // Initialize the application
458
+ function init() {
459
+ // Set up the scene
460
+ scene = new THREE.Scene();
461
+ scene.background = new THREE.Color(0x0c0c0c);
462
+
463
+ // Set up the camera
464
+ camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
465
+ camera.position.z = 5;
466
+ camera.position.y = 3;
467
+ camera.lookAt(0, 0, 0);
468
+
469
+ // Set up the renderer
470
+ const canvas = document.getElementById('gradientDescentCanvas');
471
+ renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
472
+ renderer.setSize(canvas.parentElement.clientWidth, canvas.parentElement.clientHeight);
473
+ renderer.setPixelRatio(window.devicePixelRatio);
474
+
475
+ // Add lighting
476
+ const ambientLight = new THREE.AmbientLight(0x404040, 0.6);
477
+ scene.add(ambientLight);
478
+
479
+ const directionalLight = new THREE.DirectionalLight(0x4facfe, 0.8);
480
+ directionalLight.position.set(5, 5, 5);
481
+ scene.add(directionalLight);
482
+
483
+ const pointLight = new THREE.PointLight(0x00f2fe, 0.5);
484
+ pointLight.position.set(-5, -5, 5);
485
+ scene.add(pointLight);
486
+
487
+ // Create the loss surface
488
+ createLossSurface();
489
+
490
+ // Create gradient descent path
491
+ createGradientPath();
492
+
493
+ // Create current position indicator
494
+ createCurrentPoint();
495
+
496
+ // Start animation loop
497
+ animate();
498
+
499
+ // Hide loading screen
500
+ document.getElementById('loading').classList.add('hidden');
501
+
502
+ // Add window resize handler
503
+ window.addEventListener('resize', onWindowResize);
504
+ }
505
+
506
+ // Create a complex 3D loss surface
507
+ function createLossSurface() {
508
+ if (lossSurface) scene.remove(lossSurface);
509
+
510
+ const geometry = new THREE.PlaneGeometry(8, 8, 100, 100);
511
+ const material = new THREE.MeshPhongMaterial({
512
+ color: 0x1a1a2e,
513
+ wireframe: false,
514
+ transparent: true,
515
+ opacity: 0.8,
516
+ side: THREE.DoubleSide,
517
+ shininess: 100
518
+ });
519
+
520
+ lossSurface = new THREE.Mesh(geometry, material);
521
+ lossSurface.rotation.x = -Math.PI / 2;
522
+
523
+ // Create a complex surface with multiple minima and maxima
524
+ const positions = geometry.attributes.position.array;
525
+ for (let i = 0; i < positions.length; i += 3) {
526
+ const x = positions[i];
527
+ const z = positions[i + 2];
528
+
529
+ // Complex function with multiple local minima
530
+ let y = 0;
531
+ y += Math.sin(x * surfaceComplexity * 0.5) * Math.cos(z * surfaceComplexity * 0.5);
532
+ y += 0.5 * Math.sin(x * surfaceComplexity) * Math.sin(z * surfaceComplexity);
533
+ y += 0.3 * Math.cos(x * surfaceComplexity * 2) * Math.sin(z * surfaceComplexity * 2);
534
+ y += 0.2 * Math.sin(x * surfaceComplexity * 3 + z * surfaceComplexity * 2);
535
+
536
+ positions[i + 1] = y * 0.8;
537
+ }
538
+
539
+ geometry.computeVertexNormals();
540
+ scene.add(lossSurface);
541
+
542
+ // Add wireframe
543
+ const wireframeGeometry = new THREE.WireframeGeometry(geometry);
544
+ const wireframeMaterial = new THREE.LineBasicMaterial({
545
+ color: 0x4facfe,
546
+ transparent: true,
547
+ opacity: 0.3
548
+ });
549
+ const wireframe = new THREE.LineSegments(wireframeGeometry, wireframeMaterial);
550
+ lossSurface.add(wireframe);
551
+ }
552
+
553
+ // Create gradient descent path visualization
554
+ function createGradientPath() {
555
+ if (gradientPath) scene.remove(gradientPath);
556
+
557
+ const pathGeometry = new THREE.BufferGeometry();
558
+ const pathMaterial = new THREE.LineBasicMaterial({
559
+ color: 0x00f2fe,
560
+ linewidth: 3
561
+ });
562
+
563
+ gradientPath = new THREE.Line(pathGeometry, pathMaterial);
564
+ scene.add(gradientPath);
565
+ }
566
+
567
+ // Create current point indicator
568
+ function createCurrentPoint() {
569
+ if (currentPoint) scene.remove(currentPoint);
570
+
571
+ const pointGeometry = new THREE.SphereGeometry(0.1, 16, 16);
572
+ const pointMaterial = new THREE.MeshBasicMaterial({ color: 0xff6b6b });
573
+ currentPoint = new THREE.Mesh(pointGeometry, pointMaterial);
574
+ scene.add(currentPoint);
575
+ }
576
+
577
+ // Perform one step of gradient descent
578
+ function gradientDescentStep() {
579
+ if (currentIteration >= totalIterations) {
580
+ isAnimating = false;
581
+ return;
582
+ }
583
+
584
+ // Calculate gradient (simplified for visualization)
585
+ const x = currentPoint.position.x;
586
+ const z = currentPoint.position.z;
587
+
588
+ // Complex gradient calculation matching our surface
589
+ let gradX = 0;
590
+ let gradZ = 0;
591
+
592
+ gradX += surfaceComplexity * 0.5 * Math.cos(x * surfaceComplexity * 0.5) * Math.cos(z * surfaceComplexity * 0.5);
593
+ gradX += 0.5 * surfaceComplexity * Math.cos(x * surfaceComplexity) * Math.sin(z * surfaceComplexity);
594
+ gradX += 0.3 * surfaceComplexity * 2 * -Math.sin(x * surfaceComplexity * 2) * Math.sin(z * surfaceComplexity * 2);
595
+ gradX += 0.2 * surfaceComplexity * 3 * Math.cos(x * surfaceComplexity * 3 + z * surfaceComplexity * 2);
596
+
597
+ gradZ += surfaceComplexity * 0.5 * Math.sin(x * surfaceComplexity * 0.5) * -Math.sin(z * surfaceComplexity * 0.5);
598
+ gradZ += 0.5 * surfaceComplexity * Math.sin(x * surfaceComplexity) * Math.cos(z * surfaceComplexity);
599
+ gradZ += 0.3 * surfaceComplexity * 2 * Math.cos(x * surfaceComplexity * 2) * Math.cos(z * surfaceComplexity * 2);
600
+ gradZ += 0.2 * surfaceComplexity * 2 * Math.cos(x * surfaceComplexity * 3 + z * surfaceComplexity * 2);
601
+
602
+ // Update position
603
+ currentPoint.position.x -= learningRate * gradX;
604
+ currentPoint.position.z -= learningRate * gradZ;
605
+
606
+ // Calculate y position on surface
607
+ const y = calculateSurfaceHeight(currentPoint.position.x, currentPoint.position.z);
608
+ currentPoint.position.y = y;
609
+
610
+ // Update path
611
+ updateGradientPath();
612
+
613
+ currentIteration++;
614
+ }
615
+
616
+ // Calculate height on the loss surface
617
+ function calculateSurfaceHeight(x, z) {
618
+ let y = 0;
619
+ y += Math.sin(x * surfaceComplexity * 0.5) * Math.cos(z * surfaceComplexity * 0.5);
620
+ y += 0.5 * Math.sin(x * surfaceComplexity) * Math.sin(z * surfaceComplexity);
621
+ y += 0.3 * Math.cos(x * surfaceComplexity * 2) * Math.sin(z * surfaceComplexity * 2);
622
+ y += 0.2 * Math.sin(x * surfaceComplexity * 3 + z * surfaceComplexity * 2);
623
+
624
+ return y * 0.8;
625
+ }
626
+
627
+ // Update the gradient path visualization
628
+ function updateGradientPath() {
629
+ const positions = [];
630
+
631
+ // Start from initial position
632
+ positions.push(3, calculateSurfaceHeight(3, 3), 3);
633
+
634
+ // Add current path points (simplified for demo)
635
+ for (let i = 0; i <= currentIteration; i++) {
636
+ const t = i / totalIterations;
637
+ const pathX = 3 - t * 6;
638
+ const pathZ = 3 - t * 6;
639
+ positions.push(pathX, calculateSurfaceHeight(pathX, pathZ), pathZ);
640
+ }
641
+
642
+ const pathGeometry = new THREE.BufferGeometry();
643
+ pathGeometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
644
+ gradientPath.geometry = pathGeometry;
645
+ }
646
+
647
+ // Animation loop
648
+ function animate() {
649
+ animationId = requestAnimationFrame(animate);
650
+
651
+ if (isAnimating) {
652
+ for (let i = 0; i < animationSpeed; i++) {
653
+ gradientDescentStep();
654
+ }
655
+
656
+ // Rotate camera slowly for better visualization
657
+ camera.position.x = 5 * Math.sin(Date.now() * 0.0001);
658
+ camera.position.z = 5 * Math.cos(Date.now() * 0.0001);
659
+ camera.lookAt(0, 0, 0);
660
+ }
661
+
662
+ renderer.render(scene, camera);
663
+ }
664
+
665
+ // Handle window resize
666
+ function onWindowResize() {
667
+ const canvasWrapper = document.querySelector('.canvas-wrapper');
668
+ camera.aspect = canvasWrapper.clientWidth / canvasWrapper.clientHeight;
669
+ camera.updateProjectionMatrix();
670
+ renderer.setSize(canvasWrapper.clientWidth, canvasWrapper.clientHeight);
671
+ }
672
+
673
+ // Reset the visualization
674
+ function resetVisualization() {
675
+ isAnimating = false;
676
+ currentIteration = 0;
677
+
678
+ // Reset current point to starting position
679
+ currentPoint.position.set(3, calculateSurfaceHeight(3, 3), 3);
680
+
681
+ // Reset path
682
+ updateGradientPath();
683
+ }
684
+
685
+ // Randomize starting position
686
+ function randomizeStart() {
687
+ isAnimating = false;
688
+ currentIteration = 0;
689
+
690
+ const startX = (Math.random() - 0.5) * 6;
691
+ const startZ = (Math.random() - 0.5) * 6;
692
+ currentPoint.position.set(startX, calculateSurfaceHeight(startX, startZ), startZ);
693
+
694
+ // Reset path
695
+ updateGradientPath();
696
+ }
697
+
698
+ // Initialize controls
699
+ function initControls() {
700
+ // Learning rate slider
701
+ document.getElementById('learningRate').addEventListener('input', function(e) {
702
+ learningRate = parseFloat(e.target.value);
703
+ document.getElementById('learningRateValue').textContent = learningRate.toFixed(3);
704
+ resetVisualization();
705
+ createLossSurface();
706
+ });
707
+
708
+ // Iterations slider
709
+ document.getElementById('iterations').addEventListener('input', function(e) {
710
+ totalIterations = parseInt(e.target.value);
711
+ document.getElementById('iterationsValue').textContent = totalIterations;
712
+ });
713
+
714
+ // Animation speed slider
715
+ document.getElementById('animationSpeed').addEventListener('input', function(e) {
716
+ animationSpeed = parseFloat(e.target.value);
717
+ document.getElementById('speedValue').textContent = animationSpeed.toFixed(1);
718
+ });
719
+
720
+ // Surface complexity slider
721
+ document.getElementById('surfaceComplexity').addEventListener('input', function(e) {
722
+ surfaceComplexity = parseInt(e.target.value);
723
+ document.getElementById('complexityValue').textContent = surfaceComplexity;
724
+ resetVisualization();
725
+ createLossSurface();
726
+ });
727
+
728
+ // Control buttons
729
+ document.getElementById('startBtn').addEventListener('click', function() {
730
+ isAnimating = true;
731
+ });
732
+
733
+ document.getElementById('resetBtn').addEventListener('click', resetVisualization);
734
+
735
+ document.getElementById('pauseBtn').addEventListener('click', function() {
736
+ isAnimating = false;
737
+ });
738
+
739
+ document.getElementById('randomizeBtn').addEventListener('click', randomizeStart);
740
+ }
741
+
742
+ // Initialize when DOM is loaded
743
+ document.addEventListener('DOMContentLoaded', function() {
744
+ init();
745
+ initControls();
746
+ });
747
+ </script>
748
+ </body>
749
+ </html>