Spaces:
Running
Running
Update index.html
Browse files- index.html +892 -1449
index.html
CHANGED
@@ -1,1460 +1,903 @@
|
|
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>AI
|
7 |
-
<style>
|
8 |
-
|
9 |
-
:
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
}
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
}
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
}
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
}
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
transform: translateX(24px);
|
257 |
-
}
|
258 |
-
|
259 |
-
/* ============ Section Management ============ */
|
260 |
-
.section {
|
261 |
-
display: none;
|
262 |
-
opacity: 0;
|
263 |
-
transform: translateY(20px);
|
264 |
-
transition: opacity 0.3s, transform 0.3s;
|
265 |
-
}
|
266 |
-
|
267 |
-
.section.active {
|
268 |
-
display: block;
|
269 |
-
opacity: 1;
|
270 |
-
transform: translateY(0);
|
271 |
-
}
|
272 |
-
|
273 |
-
/* ============ Flashcards Section ============ */
|
274 |
-
.category-tabs {
|
275 |
-
display: flex;
|
276 |
-
justify-content: center;
|
277 |
-
flex-wrap: wrap;
|
278 |
-
gap: 12px;
|
279 |
-
margin-bottom: 30px;
|
280 |
-
padding: 20px;
|
281 |
-
background: var(--bg-primary);
|
282 |
-
border-radius: 16px;
|
283 |
-
box-shadow: var(--shadow-sm);
|
284 |
-
}
|
285 |
-
|
286 |
-
.category-tab {
|
287 |
-
padding: 10px 20px;
|
288 |
-
background: var(--bg-tertiary);
|
289 |
-
border: 2px solid transparent;
|
290 |
-
border-radius: 10px;
|
291 |
-
cursor: pointer;
|
292 |
-
font-weight: 600;
|
293 |
-
color: var(--text-primary);
|
294 |
-
transition: var(--transition);
|
295 |
-
position: relative;
|
296 |
-
}
|
297 |
-
|
298 |
-
.category-tab:hover {
|
299 |
-
transform: translateY(-2px);
|
300 |
-
border-color: var(--primary);
|
301 |
-
}
|
302 |
-
|
303 |
-
.category-tab.active {
|
304 |
-
background: var(--primary);
|
305 |
-
color: white;
|
306 |
-
box-shadow: var(--shadow-md);
|
307 |
-
}
|
308 |
-
|
309 |
-
/* Progress indicator */
|
310 |
-
.progress-container {
|
311 |
-
margin-bottom: 25px;
|
312 |
-
background: var(--bg-primary);
|
313 |
-
padding: 20px;
|
314 |
-
border-radius: 16px;
|
315 |
-
box-shadow: var(--shadow-sm);
|
316 |
-
}
|
317 |
-
|
318 |
-
.progress {
|
319 |
-
height: 8px;
|
320 |
-
background: var(--bg-tertiary);
|
321 |
-
border-radius: 10px;
|
322 |
-
overflow: hidden;
|
323 |
-
margin-bottom: 15px;
|
324 |
-
}
|
325 |
-
|
326 |
-
.progress-bar {
|
327 |
-
height: 100%;
|
328 |
-
background: var(--gradient);
|
329 |
-
border-radius: 10px;
|
330 |
-
transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
|
331 |
-
position: relative;
|
332 |
-
overflow: hidden;
|
333 |
-
}
|
334 |
-
|
335 |
-
.progress-bar::after {
|
336 |
-
content: '';
|
337 |
-
position: absolute;
|
338 |
-
top: 0;
|
339 |
-
left: 0;
|
340 |
-
bottom: 0;
|
341 |
-
right: 0;
|
342 |
-
background: linear-gradient(
|
343 |
-
90deg,
|
344 |
-
transparent,
|
345 |
-
rgba(255, 255, 255, 0.3),
|
346 |
-
transparent
|
347 |
-
);
|
348 |
-
animation: shimmer 2s infinite;
|
349 |
-
}
|
350 |
-
|
351 |
-
@keyframes shimmer {
|
352 |
-
0% { transform: translateX(-100%); }
|
353 |
-
100% { transform: translateX(100%); }
|
354 |
-
}
|
355 |
-
|
356 |
-
.card-counter {
|
357 |
-
text-align: center;
|
358 |
-
font-weight: 600;
|
359 |
-
font-size: 1.1rem;
|
360 |
-
color: var(--text-secondary);
|
361 |
-
}
|
362 |
-
|
363 |
-
/* Flashcard styles */
|
364 |
-
.flashcard-container {
|
365 |
-
perspective: 1000px;
|
366 |
-
height: 400px;
|
367 |
-
margin-bottom: 30px;
|
368 |
-
}
|
369 |
-
|
370 |
-
.flashcard {
|
371 |
-
position: relative;
|
372 |
-
width: 100%;
|
373 |
-
height: 100%;
|
374 |
-
cursor: pointer;
|
375 |
-
transform-style: preserve-3d;
|
376 |
-
transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
|
377 |
-
}
|
378 |
-
|
379 |
-
.flashcard.flipped {
|
380 |
-
transform: rotateY(180deg);
|
381 |
-
}
|
382 |
-
|
383 |
-
.flashcard-front,
|
384 |
-
.flashcard-back {
|
385 |
-
position: absolute;
|
386 |
-
width: 100%;
|
387 |
-
height: 100%;
|
388 |
-
backface-visibility: hidden;
|
389 |
-
display: flex;
|
390 |
-
align-items: center;
|
391 |
-
justify-content: center;
|
392 |
-
padding: 40px;
|
393 |
-
border-radius: 20px;
|
394 |
-
box-shadow: var(--shadow-xl);
|
395 |
-
text-align: center;
|
396 |
-
}
|
397 |
-
|
398 |
-
.flashcard-front {
|
399 |
-
background: var(--bg-primary);
|
400 |
-
border: 3px solid var(--border);
|
401 |
-
color: var(--text-primary);
|
402 |
-
}
|
403 |
-
|
404 |
-
.flashcard-front p {
|
405 |
-
font-size: 1.5rem;
|
406 |
-
font-weight: 700;
|
407 |
-
line-height: 1.4;
|
408 |
-
color: var(--text-primary);
|
409 |
-
}
|
410 |
-
|
411 |
-
.flashcard-back {
|
412 |
-
background: var(--gradient);
|
413 |
-
color: white;
|
414 |
-
transform: rotateY(180deg);
|
415 |
-
}
|
416 |
-
|
417 |
-
.flashcard-back p {
|
418 |
-
font-size: 1.2rem;
|
419 |
-
line-height: 1.6;
|
420 |
-
font-weight: 500;
|
421 |
-
}
|
422 |
-
|
423 |
-
/* Controls */
|
424 |
-
.controls {
|
425 |
-
display: flex;
|
426 |
-
justify-content: center;
|
427 |
-
flex-wrap: wrap;
|
428 |
-
gap: 15px;
|
429 |
-
margin: 20px 0;
|
430 |
-
}
|
431 |
-
|
432 |
-
button {
|
433 |
-
padding: 12px 28px;
|
434 |
-
border: none;
|
435 |
-
background: var(--primary);
|
436 |
-
color: white;
|
437 |
-
border-radius: 10px;
|
438 |
-
cursor: pointer;
|
439 |
-
font-weight: 600;
|
440 |
-
font-size: 1rem;
|
441 |
-
transition: var(--transition);
|
442 |
-
box-shadow: var(--shadow-md);
|
443 |
-
position: relative;
|
444 |
-
overflow: hidden;
|
445 |
-
}
|
446 |
-
|
447 |
-
button::before {
|
448 |
-
content: '';
|
449 |
-
position: absolute;
|
450 |
-
top: 50%;
|
451 |
-
left: 50%;
|
452 |
-
width: 0;
|
453 |
-
height: 0;
|
454 |
-
background: rgba(255, 255, 255, 0.2);
|
455 |
-
border-radius: 50%;
|
456 |
-
transform: translate(-50%, -50%);
|
457 |
-
transition: width 0.6s, height 0.6s;
|
458 |
-
}
|
459 |
-
|
460 |
-
button:hover {
|
461 |
-
background: var(--primary-dark);
|
462 |
-
transform: translateY(-2px);
|
463 |
-
box-shadow: var(--shadow-lg);
|
464 |
-
}
|
465 |
-
|
466 |
-
button:hover::before {
|
467 |
-
width: 300px;
|
468 |
-
height: 300px;
|
469 |
-
}
|
470 |
-
|
471 |
-
button:active {
|
472 |
-
transform: translateY(0);
|
473 |
-
}
|
474 |
-
|
475 |
-
button:disabled {
|
476 |
-
background: var(--text-secondary);
|
477 |
-
cursor: not-allowed;
|
478 |
-
transform: none;
|
479 |
-
box-shadow: none;
|
480 |
-
opacity: 0.6;
|
481 |
-
}
|
482 |
-
|
483 |
-
/* ============ Playground Section ============ */
|
484 |
-
.play-task {
|
485 |
-
margin-bottom: 30px;
|
486 |
-
padding: 30px;
|
487 |
-
background: var(--bg-primary);
|
488 |
-
border-radius: 20px;
|
489 |
-
box-shadow: var(--shadow-lg);
|
490 |
-
border: 1px solid var(--border);
|
491 |
-
}
|
492 |
-
|
493 |
-
.play-task h3 {
|
494 |
-
font-size: 1.4rem;
|
495 |
-
margin-bottom: 15px;
|
496 |
-
color: var(--primary);
|
497 |
-
display: flex;
|
498 |
-
align-items: center;
|
499 |
-
gap: 10px;
|
500 |
-
}
|
501 |
-
|
502 |
-
.task-badge {
|
503 |
-
display: inline-flex;
|
504 |
-
align-items: center;
|
505 |
-
padding: 4px 12px;
|
506 |
-
background: var(--bg-tertiary);
|
507 |
-
border-radius: 20px;
|
508 |
-
font-size: 0.9rem;
|
509 |
-
font-weight: 600;
|
510 |
-
color: var(--text-secondary);
|
511 |
-
}
|
512 |
-
|
513 |
-
.play-task p {
|
514 |
-
margin-bottom: 20px;
|
515 |
-
color: var(--text-secondary);
|
516 |
-
line-height: 1.6;
|
517 |
-
}
|
518 |
-
|
519 |
-
.play-task code {
|
520 |
-
background: var(--bg-tertiary);
|
521 |
-
padding: 2px 8px;
|
522 |
-
border-radius: 6px;
|
523 |
-
font-family: 'Consolas', 'Monaco', monospace;
|
524 |
-
font-size: 0.95rem;
|
525 |
-
color: var(--primary);
|
526 |
-
}
|
527 |
-
|
528 |
-
.code-editor {
|
529 |
-
position: relative;
|
530 |
-
margin-bottom: 20px;
|
531 |
-
}
|
532 |
-
|
533 |
-
.code-editor textarea {
|
534 |
-
width: 100%;
|
535 |
-
min-height: 200px;
|
536 |
-
padding: 20px;
|
537 |
-
border: 2px solid var(--border);
|
538 |
-
border-radius: 12px;
|
539 |
-
font-family: 'Consolas', 'Monaco', monospace;
|
540 |
-
font-size: 14px;
|
541 |
-
line-height: 1.5;
|
542 |
-
background: var(--bg-secondary);
|
543 |
-
color: var(--text-primary);
|
544 |
-
resize: vertical;
|
545 |
-
transition: var(--transition);
|
546 |
-
}
|
547 |
-
|
548 |
-
.code-editor textarea:focus {
|
549 |
-
outline: none;
|
550 |
-
border-color: var(--primary);
|
551 |
-
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
|
552 |
-
}
|
553 |
-
|
554 |
-
body.dark-mode .code-editor textarea {
|
555 |
-
background: var(--bg-tertiary);
|
556 |
-
}
|
557 |
-
|
558 |
-
.play-output {
|
559 |
-
margin-top: 20px;
|
560 |
-
padding: 15px 20px;
|
561 |
-
border-radius: 10px;
|
562 |
-
font-family: monospace;
|
563 |
-
font-size: 1rem;
|
564 |
-
line-height: 1.5;
|
565 |
-
white-space: pre-wrap;
|
566 |
-
transition: var(--transition);
|
567 |
-
}
|
568 |
-
|
569 |
-
.play-success {
|
570 |
-
background: rgba(16, 185, 129, 0.1);
|
571 |
-
color: var(--success);
|
572 |
-
border: 2px solid var(--success);
|
573 |
-
}
|
574 |
-
|
575 |
-
.play-error {
|
576 |
-
background: rgba(239, 68, 68, 0.1);
|
577 |
-
color: var(--error);
|
578 |
-
border: 2px solid var(--error);
|
579 |
-
}
|
580 |
-
|
581 |
-
/* ============ Test Section ============ */
|
582 |
-
.quiz-card {
|
583 |
-
background: var(--bg-primary);
|
584 |
-
padding: 35px;
|
585 |
-
border-radius: 20px;
|
586 |
-
box-shadow: var(--shadow-lg);
|
587 |
-
border: 1px solid var(--border);
|
588 |
-
margin-bottom: 30px;
|
589 |
-
}
|
590 |
-
|
591 |
-
.quiz-card h3 {
|
592 |
-
font-size: 1.5rem;
|
593 |
-
margin-bottom: 20px;
|
594 |
-
color: var(--primary);
|
595 |
-
}
|
596 |
-
|
597 |
-
.quiz-card p {
|
598 |
-
font-size: 1.1rem;
|
599 |
-
margin-bottom: 25px;
|
600 |
-
line-height: 1.6;
|
601 |
-
color: var(--text-primary);
|
602 |
-
}
|
603 |
-
|
604 |
-
.quiz-option {
|
605 |
-
display: block;
|
606 |
-
margin: 10px 0;
|
607 |
-
padding: 15px 20px;
|
608 |
-
border: 2px solid var(--border);
|
609 |
-
border-radius: 12px;
|
610 |
-
cursor: pointer;
|
611 |
-
transition: var(--transition);
|
612 |
-
background: var(--bg-secondary);
|
613 |
-
color: var(--text-primary);
|
614 |
-
font-weight: 500;
|
615 |
-
}
|
616 |
-
|
617 |
-
.quiz-option:hover {
|
618 |
-
border-color: var(--primary);
|
619 |
-
transform: translateX(5px);
|
620 |
-
box-shadow: var(--shadow-md);
|
621 |
-
}
|
622 |
-
|
623 |
-
.quiz-option.selected {
|
624 |
-
background: var(--primary);
|
625 |
-
color: white;
|
626 |
-
border-color: var(--primary);
|
627 |
-
box-shadow: var(--shadow-lg);
|
628 |
-
}
|
629 |
-
|
630 |
-
.quiz-score {
|
631 |
-
font-size: 2rem;
|
632 |
-
font-weight: 700;
|
633 |
-
text-align: center;
|
634 |
-
margin-top: 30px;
|
635 |
-
background: var(--gradient);
|
636 |
-
-webkit-background-clip: text;
|
637 |
-
-webkit-text-fill-color: transparent;
|
638 |
-
background-clip: text;
|
639 |
-
}
|
640 |
-
|
641 |
-
/* ============ Help Section ============ */
|
642 |
-
.help-button {
|
643 |
-
position: fixed;
|
644 |
-
bottom: 30px;
|
645 |
-
right: 30px;
|
646 |
-
width: 60px;
|
647 |
-
height: 60px;
|
648 |
-
border-radius: 50%;
|
649 |
-
background: var(--gradient);
|
650 |
-
color: white;
|
651 |
-
border: none;
|
652 |
-
cursor: pointer;
|
653 |
-
box-shadow: var(--shadow-xl);
|
654 |
-
font-size: 1.5rem;
|
655 |
-
display: flex;
|
656 |
-
align-items: center;
|
657 |
-
justify-content: center;
|
658 |
-
transition: var(--transition);
|
659 |
-
z-index: 1000;
|
660 |
-
}
|
661 |
-
|
662 |
-
.help-button:hover {
|
663 |
-
transform: scale(1.1);
|
664 |
-
}
|
665 |
-
|
666 |
-
.help-modal {
|
667 |
-
position: fixed;
|
668 |
-
top: 0;
|
669 |
-
left: 0;
|
670 |
-
right: 0;
|
671 |
-
bottom: 0;
|
672 |
-
background: rgba(0, 0, 0, 0.5);
|
673 |
-
display: none;
|
674 |
-
align-items: center;
|
675 |
-
justify-content: center;
|
676 |
-
z-index: 2000;
|
677 |
-
backdrop-filter: blur(5px);
|
678 |
-
}
|
679 |
-
|
680 |
-
.help-modal.active {
|
681 |
-
display: flex;
|
682 |
-
}
|
683 |
-
|
684 |
-
.help-content {
|
685 |
-
background: var(--bg-primary);
|
686 |
-
padding: 40px;
|
687 |
-
border-radius: 20px;
|
688 |
-
max-width: 600px;
|
689 |
-
max-height: 80vh;
|
690 |
-
overflow-y: auto;
|
691 |
-
box-shadow: var(--shadow-xl);
|
692 |
-
position: relative;
|
693 |
-
animation: modalSlideIn 0.3s ease;
|
694 |
-
}
|
695 |
-
|
696 |
-
@keyframes modalSlideIn {
|
697 |
-
from {
|
698 |
-
opacity: 0;
|
699 |
-
transform: translateY(-50px);
|
700 |
-
}
|
701 |
-
to {
|
702 |
-
opacity: 1;
|
703 |
-
transform: translateY(0);
|
704 |
-
}
|
705 |
-
}
|
706 |
-
|
707 |
-
.help-content h2 {
|
708 |
-
margin-bottom: 20px;
|
709 |
-
color: var(--primary);
|
710 |
-
}
|
711 |
-
|
712 |
-
.help-content h3 {
|
713 |
-
margin-top: 20px;
|
714 |
-
margin-bottom: 10px;
|
715 |
-
color: var(--primary);
|
716 |
-
}
|
717 |
-
|
718 |
-
.help-content p {
|
719 |
-
margin-bottom: 15px;
|
720 |
-
line-height: 1.6;
|
721 |
-
color: var(--text-primary);
|
722 |
-
}
|
723 |
-
|
724 |
-
.close-help {
|
725 |
-
position: absolute;
|
726 |
-
top: 20px;
|
727 |
-
right: 20px;
|
728 |
-
background: none;
|
729 |
-
border: none;
|
730 |
-
font-size: 1.5rem;
|
731 |
-
cursor: pointer;
|
732 |
-
color: var(--text-secondary);
|
733 |
-
padding: 5px;
|
734 |
-
}
|
735 |
-
|
736 |
-
/* ============ Footer ============ */
|
737 |
-
footer {
|
738 |
-
text-align: center;
|
739 |
-
margin-top: 60px;
|
740 |
-
padding: 30px;
|
741 |
-
background: var(--bg-primary);
|
742 |
-
border-radius: 20px;
|
743 |
-
box-shadow: var(--shadow-md);
|
744 |
-
}
|
745 |
-
|
746 |
-
footer p {
|
747 |
-
color: var(--text-secondary);
|
748 |
-
font-size: 1rem;
|
749 |
-
}
|
750 |
-
|
751 |
-
footer a {
|
752 |
-
color: var(--primary);
|
753 |
-
text-decoration: none;
|
754 |
-
font-weight: 600;
|
755 |
-
transition: var(--transition);
|
756 |
-
}
|
757 |
-
|
758 |
-
footer a:hover {
|
759 |
-
text-decoration: underline;
|
760 |
-
}
|
761 |
-
|
762 |
-
/* ============ Responsive Design ============ */
|
763 |
-
@media (max-width: 768px) {
|
764 |
-
h1 {
|
765 |
-
font-size: 2rem;
|
766 |
-
}
|
767 |
-
|
768 |
-
.main-tabs {
|
769 |
-
padding: 15px;
|
770 |
-
}
|
771 |
-
|
772 |
-
.flashcard-container {
|
773 |
-
height: 350px;
|
774 |
-
}
|
775 |
-
|
776 |
-
.flashcard-front p {
|
777 |
-
font-size: 1.2rem;
|
778 |
-
}
|
779 |
-
|
780 |
-
.flashcard-back p {
|
781 |
-
font-size: 1rem;
|
782 |
-
}
|
783 |
-
|
784 |
-
.play-task {
|
785 |
-
padding: 20px;
|
786 |
-
}
|
787 |
-
|
788 |
-
.quiz-card {
|
789 |
-
padding: 25px;
|
790 |
-
}
|
791 |
-
|
792 |
-
.help-content {
|
793 |
-
padding: 30px;
|
794 |
-
margin: 20px;
|
795 |
-
}
|
796 |
-
}
|
797 |
-
|
798 |
-
/* ============ Loading Animation ============ */
|
799 |
-
.loading {
|
800 |
-
display: inline-block;
|
801 |
-
width: 20px;
|
802 |
-
height: 20px;
|
803 |
-
border: 3px solid var(--border);
|
804 |
-
border-radius: 50%;
|
805 |
-
border-top-color: var(--primary);
|
806 |
-
animation: spin 1s ease-in-out infinite;
|
807 |
-
}
|
808 |
-
|
809 |
-
@keyframes spin {
|
810 |
-
to { transform: rotate(360deg); }
|
811 |
-
}
|
812 |
-
|
813 |
-
/* ============ Tooltips ============ */
|
814 |
-
.tooltip {
|
815 |
-
position: relative;
|
816 |
-
display: inline-block;
|
817 |
-
cursor: help;
|
818 |
-
color: var(--text-secondary);
|
819 |
-
}
|
820 |
-
|
821 |
-
.tooltip .tooltiptext {
|
822 |
-
visibility: hidden;
|
823 |
-
width: 200px;
|
824 |
-
background: var(--bg-tertiary);
|
825 |
-
color: var(--text-primary);
|
826 |
-
text-align: center;
|
827 |
-
border-radius: 8px;
|
828 |
-
padding: 10px;
|
829 |
-
position: absolute;
|
830 |
-
z-index: 1;
|
831 |
-
bottom: 125%;
|
832 |
-
left: 50%;
|
833 |
-
margin-left: -100px;
|
834 |
-
opacity: 0;
|
835 |
-
transition: opacity 0.3s;
|
836 |
-
box-shadow: var(--shadow-lg);
|
837 |
-
font-size: 0.9rem;
|
838 |
-
border: 1px solid var(--border);
|
839 |
-
}
|
840 |
-
|
841 |
-
.tooltip:hover .tooltiptext {
|
842 |
-
visibility: visible;
|
843 |
-
opacity: 1;
|
844 |
-
}
|
845 |
-
</style>
|
846 |
</head>
|
847 |
<body>
|
848 |
-
<div class="container">
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
<button class="main-tab active" data-section="flashcards">📚 Flashcards</button>
|
858 |
-
<button class="main-tab" data-section="playground">💻 Playground</button>
|
859 |
-
<button class="main-tab" data-section="test">📝 Test</button>
|
860 |
-
<label class="dark-toggle">
|
861 |
-
<span>🌙 Dark Mode</span>
|
862 |
-
<div class="toggle-switch">
|
863 |
-
<input type="checkbox" id="darkToggle"/>
|
864 |
-
<span class="slider"></span>
|
865 |
-
</div>
|
866 |
-
</label>
|
867 |
-
</nav>
|
868 |
-
|
869 |
-
<!-- Flashcards Section -->
|
870 |
-
<section id="flashcards" class="section active">
|
871 |
-
<div class="category-tabs">
|
872 |
-
<div class="category-tab active" data-category="core">Core Concepts</div>
|
873 |
-
<div class="category-tab" data-category="terms">Key Terms</div>
|
874 |
-
<div class="category-tab" data-category="applications">AI Applications</div>
|
875 |
-
<div class="category-tab" data-category="ethics">Ethics & Challenges</div>
|
876 |
-
</div>
|
877 |
-
|
878 |
-
<div class="progress-container">
|
879 |
-
<div class="progress">
|
880 |
-
<div class="progress-bar" style="width: 0%"></div>
|
881 |
-
</div>
|
882 |
-
<div class="card-counter">Card 1 of 10</div>
|
883 |
-
</div>
|
884 |
-
|
885 |
-
<div class="flashcard-container">
|
886 |
-
<div class="flashcard">
|
887 |
-
<div class="flashcard-front">
|
888 |
-
<p></p>
|
889 |
</div>
|
890 |
-
|
891 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
892 |
</div>
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
</div>
|
915 |
-
|
916 |
-
|
917 |
-
<
|
918 |
-
<div class="
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
</
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
function shuffleCards() {
|
1069 |
-
flashcards[currentCategory] = flashcards[currentCategory].sort(() => Math.random() - 0.5);
|
1070 |
-
currentCardIndex = 0;
|
1071 |
-
resetCard();
|
1072 |
-
}
|
1073 |
-
|
1074 |
-
function resetCard() {
|
1075 |
-
isFlipped = false;
|
1076 |
-
flashcardEl.classList.remove('flipped');
|
1077 |
-
updateCard();
|
1078 |
-
}
|
1079 |
-
|
1080 |
-
// ==================== Event Listeners ====================
|
1081 |
-
flashcardEl.addEventListener('click', toggleFlip);
|
1082 |
-
flipBtn.addEventListener('click', toggleFlip);
|
1083 |
-
prevBtn.addEventListener('click', prevCard);
|
1084 |
-
nextBtn.addEventListener('click', nextCard);
|
1085 |
-
shuffleBtn.addEventListener('click', shuffleCards);
|
1086 |
-
|
1087 |
-
// Category switching
|
1088 |
-
categoryTabs.forEach(tab => {
|
1089 |
-
tab.addEventListener('click', () => {
|
1090 |
-
categoryTabs.forEach(t => t.classList.remove('active'));
|
1091 |
-
tab.classList.add('active');
|
1092 |
-
currentCategory = tab.dataset.category;
|
1093 |
-
currentCardIndex = 0;
|
1094 |
-
isFlipped = false;
|
1095 |
-
flashcardEl.classList.remove('flipped');
|
1096 |
-
loadSavedProgress();
|
1097 |
-
updateCard();
|
1098 |
-
});
|
1099 |
-
});
|
1100 |
-
|
1101 |
-
// Keyboard navigation
|
1102 |
-
document.addEventListener('keydown', (e) => {
|
1103 |
-
if (document.getElementById('flashcards').classList.contains('active')) {
|
1104 |
-
switch(e.key) {
|
1105 |
-
case ' ':
|
1106 |
-
e.preventDefault();
|
1107 |
-
toggleFlip();
|
1108 |
-
break;
|
1109 |
-
case 'ArrowLeft':
|
1110 |
-
prevCard();
|
1111 |
-
break;
|
1112 |
-
case 'ArrowRight':
|
1113 |
-
nextCard();
|
1114 |
-
break;
|
1115 |
-
}
|
1116 |
-
}
|
1117 |
-
});
|
1118 |
-
|
1119 |
-
// ==================== Dark Mode ====================
|
1120 |
-
const darkToggle = document.getElementById('darkToggle');
|
1121 |
-
darkToggle.addEventListener('change', (e) => {
|
1122 |
-
document.body.classList.toggle('dark-mode', e.target.checked);
|
1123 |
-
localStorage.setItem('dark-mode', e.target.checked);
|
1124 |
-
});
|
1125 |
-
|
1126 |
-
// Load dark mode preference
|
1127 |
-
if (localStorage.getItem('dark-mode') === 'true') {
|
1128 |
-
darkToggle.checked = true;
|
1129 |
-
document.body.classList.add('dark-mode');
|
1130 |
-
}
|
1131 |
-
|
1132 |
-
// ==================== Navigation ====================
|
1133 |
-
const mainTabs = document.querySelectorAll('.main-tab');
|
1134 |
-
mainTabs.forEach(btn => {
|
1135 |
-
btn.addEventListener('click', () => {
|
1136 |
-
mainTabs.forEach(b => b.classList.remove('active'));
|
1137 |
-
btn.classList.add('active');
|
1138 |
-
|
1139 |
-
document.querySelectorAll('.section').forEach(s => {
|
1140 |
-
s.classList.remove('active');
|
1141 |
-
});
|
1142 |
-
|
1143 |
-
const targetSection = document.getElementById(btn.dataset.section);
|
1144 |
-
setTimeout(() => {
|
1145 |
-
targetSection.classList.add('active');
|
1146 |
-
}, 10);
|
1147 |
-
});
|
1148 |
-
});
|
1149 |
-
|
1150 |
-
// ==================== Playground Section ====================
|
1151 |
-
const playgroundSection = document.getElementById('playground');
|
1152 |
-
const tasks = [
|
1153 |
-
{
|
1154 |
-
title: 'Sum of Two Numbers',
|
1155 |
-
desc: 'Write a function <code>add(a, b)</code> that returns the sum of two numbers.',
|
1156 |
-
hint: 'Use the + operator to add the numbers',
|
1157 |
-
test: code => {
|
1158 |
-
try {
|
1159 |
-
const func = new Function(code + '; return add(2, 3);');
|
1160 |
-
return func() === 5;
|
1161 |
-
} catch (e) {
|
1162 |
-
throw e;
|
1163 |
-
}
|
1164 |
-
}
|
1165 |
-
},
|
1166 |
-
{
|
1167 |
-
title: 'Even Number Checker',
|
1168 |
-
desc: 'Write a function <code>isEven(n)</code> that returns <code>true</code> if a number is even, <code>false</code> otherwise.',
|
1169 |
-
hint: 'Use the modulo operator (%) to check divisibility by 2',
|
1170 |
-
test: code => {
|
1171 |
-
try {
|
1172 |
-
const func = new Function(code + '; return isEven(4) && !isEven(5) && isEven(0);');
|
1173 |
-
return func();
|
1174 |
-
} catch (e) {
|
1175 |
-
throw e;
|
1176 |
-
}
|
1177 |
-
}
|
1178 |
-
},
|
1179 |
-
{
|
1180 |
-
title: 'String Reversal',
|
1181 |
-
desc: 'Write a function <code>reverseString(s)</code> that returns the reversed version of a string.',
|
1182 |
-
hint: 'You can split the string into an array, reverse it, and join it back',
|
1183 |
-
test: code => {
|
1184 |
-
try {
|
1185 |
-
const func = new Function(code + '; return reverseString("hello") === "olleh" && reverseString("AI") === "IA";');
|
1186 |
-
return func();
|
1187 |
-
} catch (e) {
|
1188 |
-
throw e;
|
1189 |
-
}
|
1190 |
-
}
|
1191 |
-
},
|
1192 |
-
{
|
1193 |
-
title: 'Find Maximum in Array',
|
1194 |
-
desc: 'Write a function <code>maxArray(arr)</code> that returns the largest number in an array.',
|
1195 |
-
hint: 'Use Math.max() with the spread operator or iterate through the array',
|
1196 |
-
test: code => {
|
1197 |
-
try {
|
1198 |
-
const func = new Function(code + '; return maxArray([1, 8, 3, 7]) === 8 && maxArray([-5, -1, -10]) === -1;');
|
1199 |
-
return func();
|
1200 |
-
} catch (e) {
|
1201 |
-
throw e;
|
1202 |
-
}
|
1203 |
-
}
|
1204 |
-
},
|
1205 |
-
{
|
1206 |
-
title: 'Factorial Calculator',
|
1207 |
-
desc: 'Write a function <code>factorial(n)</code> that returns the factorial of n (n!).',
|
1208 |
-
hint: 'Remember: 5! = 5 × 4 × 3 × 2 × 1 = 120',
|
1209 |
-
test: code => {
|
1210 |
-
try {
|
1211 |
-
const func = new Function(code + '; return factorial(5) === 120 && factorial(0) === 1 && factorial(3) === 6;');
|
1212 |
-
return func();
|
1213 |
-
} catch (e) {
|
1214 |
-
throw e;
|
1215 |
-
}
|
1216 |
-
}
|
1217 |
-
}
|
1218 |
-
];
|
1219 |
-
|
1220 |
-
let taskIndex = 0;
|
1221 |
-
|
1222 |
-
function renderTask() {
|
1223 |
-
const task = tasks[taskIndex];
|
1224 |
-
playgroundSection.innerHTML = `
|
1225 |
-
<div class="play-task">
|
1226 |
-
<h3>
|
1227 |
-
<span class="task-badge">Task ${taskIndex + 1}/${tasks.length}</span>
|
1228 |
-
${task.title}
|
1229 |
-
</h3>
|
1230 |
-
<p>${task.desc}</p>
|
1231 |
-
<div class="tooltip">
|
1232 |
-
💡 <span class="tooltiptext">${task.hint}</span>
|
1233 |
-
</div>
|
1234 |
-
<div class="code-editor">
|
1235 |
-
<textarea id="codeArea" spellcheck="false" placeholder="// Write your solution here
|
1236 |
-
function functionName(parameters) {
|
1237 |
-
// Your code
|
1238 |
-
}"></textarea>
|
1239 |
-
</div>
|
1240 |
-
<button id="runCode">▶ Run Code</button>
|
1241 |
-
<div id="output" class="play-output" style="display: none;"></div>
|
1242 |
-
<div class="controls" style="margin-top: 20px;">
|
1243 |
-
<button id="prevTask" ${taskIndex === 0 ? 'disabled' : ''}>← Previous</button>
|
1244 |
-
<button id="nextTask" ${taskIndex === tasks.length - 1 ? 'disabled' : ''}>Next →</button>
|
1245 |
-
</div>
|
1246 |
-
</div>
|
1247 |
-
`;
|
1248 |
-
|
1249 |
-
// Add event listeners
|
1250 |
-
document.getElementById('runCode').onclick = runCode;
|
1251 |
-
document.getElementById('prevTask').onclick = () => {
|
1252 |
-
taskIndex--;
|
1253 |
-
renderTask();
|
1254 |
-
};
|
1255 |
-
document.getElementById('nextTask').onclick = () => {
|
1256 |
-
taskIndex++;
|
1257 |
-
renderTask();
|
1258 |
-
};
|
1259 |
-
|
1260 |
-
// Load saved code if exists
|
1261 |
-
const savedCode = localStorage.getItem(`task-${taskIndex}-code`);
|
1262 |
-
if (savedCode) {
|
1263 |
-
document.getElementById('codeArea').value = savedCode;
|
1264 |
-
}
|
1265 |
-
}
|
1266 |
-
|
1267 |
-
function runCode() {
|
1268 |
-
const code = document.getElementById('codeArea').value;
|
1269 |
-
const output = document.getElementById('output');
|
1270 |
-
const task = tasks[taskIndex];
|
1271 |
-
|
1272 |
-
// Save code
|
1273 |
-
localStorage.setItem(`task-${taskIndex}-code`, code);
|
1274 |
-
|
1275 |
-
try {
|
1276 |
-
const passed = task.test(code);
|
1277 |
-
output.textContent = passed ? '✅ Excellent! All tests passed!' : '❌ Not quite right. Check your solution and try again.';
|
1278 |
-
output.className = 'play-output ' + (passed ? 'play-success' : 'play-error');
|
1279 |
-
output.style.display = 'block';
|
1280 |
-
|
1281 |
-
// Mark task as completed if passed
|
1282 |
-
if (passed) {
|
1283 |
-
localStorage.setItem(`task-${taskIndex}-completed`, 'true');
|
1284 |
-
}
|
1285 |
-
} catch (err) {
|
1286 |
-
output.textContent = `⚠️ Error: ${err.message}`;
|
1287 |
-
output.className = 'play-output play-error';
|
1288 |
-
output.style.display = 'block';
|
1289 |
-
}
|
1290 |
-
}
|
1291 |
-
|
1292 |
-
// ==================== Test Section ====================
|
1293 |
-
const testSection = document.getElementById('test');
|
1294 |
-
const quizQuestions = [
|
1295 |
-
{
|
1296 |
-
q: 'Which algorithm is commonly used to minimize a loss function in neural networks?',
|
1297 |
-
opts: ['K-means clustering', 'Gradient Descent', 'Apriori algorithm', 'Breadth-first search'],
|
1298 |
-
ans: 1,
|
1299 |
-
explanation: 'Gradient Descent iteratively adjusts parameters to minimize the loss function.'
|
1300 |
-
},
|
1301 |
-
{
|
1302 |
-
q: 'Overfitting is primarily an example of which type of error?',
|
1303 |
-
opts: ['High bias', 'High variance', 'Syntax error', 'Runtime error'],
|
1304 |
-
ans: 1,
|
1305 |
-
explanation: 'Overfitting occurs when a model has high variance, fitting too closely to training data.'
|
1306 |
-
},
|
1307 |
-
{
|
1308 |
-
q: 'Which field of AI focuses on understanding and processing images?',
|
1309 |
-
opts: ['Natural Language Processing', 'Speech Recognition', 'Computer Vision', 'Game Theory'],
|
1310 |
-
ans: 2,
|
1311 |
-
explanation: 'Computer Vision deals with extracting information from visual inputs.'
|
1312 |
-
},
|
1313 |
-
{
|
1314 |
-
q: 'In classification metrics, which metric is calculated as TP/(TP+FP)?',
|
1315 |
-
opts: ['Recall', 'Accuracy', 'F1-Score', 'Precision'],
|
1316 |
-
ans: 3,
|
1317 |
-
explanation: 'Precision measures the accuracy of positive predictions.'
|
1318 |
-
},
|
1319 |
-
{
|
1320 |
-
q: 'What does XAI stand for in the context of AI?',
|
1321 |
-
opts: ['eXternal AI', 'Explainable AI', 'Extreme AI', 'Experimental AI'],
|
1322 |
-
ans: 1,
|
1323 |
-
explanation: 'Explainable AI focuses on making AI decisions transparent and understandable.'
|
1324 |
-
},
|
1325 |
-
{
|
1326 |
-
q: 'Transfer learning is particularly useful when:',
|
1327 |
-
opts: ['Data is abundant', 'Training from scratch is costly', 'Models are tiny', 'Labels are perfect'],
|
1328 |
-
ans: 1,
|
1329 |
-
explanation: 'Transfer learning saves time and resources by reusing pre-trained models.'
|
1330 |
-
},
|
1331 |
-
{
|
1332 |
-
q: 'The AI alignment problem primarily concerns:',
|
1333 |
-
opts: ['Model efficiency', 'Matching AI goals with human values', 'Hardware scaling', 'Syntax errors'],
|
1334 |
-
ans: 1,
|
1335 |
-
explanation: 'AI alignment ensures AI systems pursue goals aligned with human values.'
|
1336 |
-
},
|
1337 |
-
{
|
1338 |
-
q: 'Which learning paradigm uses rewards and penalties?',
|
1339 |
-
opts: ['Supervised Learning', 'Unsupervised Learning', 'Reinforcement Learning', 'Self-supervised Learning'],
|
1340 |
-
ans: 2,
|
1341 |
-
explanation: 'Reinforcement Learning uses rewards and penalties to guide learning.'
|
1342 |
-
},
|
1343 |
-
{
|
1344 |
-
q: 'Bias in AI systems often originates from:',
|
1345 |
-
opts: ['Noisy sensors', 'Biased training data', 'GPU memory limitations', 'Slow CPUs'],
|
1346 |
-
ans: 1,
|
1347 |
-
explanation: 'Biased training data is a primary source of bias in AI systems.'
|
1348 |
-
},
|
1349 |
-
{
|
1350 |
-
q: 'In the context of AI, LLM stands for:',
|
1351 |
-
opts: ['Large Logic Model', 'Long-Lived Model', 'Large Language Model', 'Layered Learning Method'],
|
1352 |
-
ans: 2,
|
1353 |
-
explanation: 'Large Language Models are trained on vast text data for language tasks.'
|
1354 |
-
}
|
1355 |
-
];
|
1356 |
-
|
1357 |
-
let quizIndex = 0;
|
1358 |
-
let score = 0;
|
1359 |
-
|
1360 |
-
function renderQuiz() {
|
1361 |
-
if (quizIndex >= quizQuestions.length) {
|
1362 |
-
testSection.innerHTML = `
|
1363 |
-
<div class="quiz-card">
|
1364 |
-
<h3>🎉 Test Complete!</h3>
|
1365 |
-
<p class="quiz-score">You scored ${score} out of ${quizQuestions.length}</p>
|
1366 |
-
<p style="text-align: center; margin-top: 20px;">
|
1367 |
-
${score >= 8 ? '🌟 Excellent work!' : score >= 6 ? '👍 Good job!' : '📚 Keep studying!'}
|
1368 |
-
</p>
|
1369 |
-
<div style="text-align: center; margin-top: 30px;">
|
1370 |
-
<button onclick="restartQuiz()">🔄 Retake Test</button>
|
1371 |
</div>
|
1372 |
-
</div>
|
1373 |
-
`;
|
1374 |
-
return;
|
1375 |
-
}
|
1376 |
-
|
1377 |
-
const q = quizQuestions[quizIndex];
|
1378 |
-
let optionsHTML = '';
|
1379 |
-
q.opts.forEach((opt, i) => {
|
1380 |
-
optionsHTML += `
|
1381 |
-
<label class="quiz-option">
|
1382 |
-
<input type="radio" name="opt" value="${i}" style="display: none;">
|
1383 |
-
${opt}
|
1384 |
-
</label>
|
1385 |
-
`;
|
1386 |
-
});
|
1387 |
-
|
1388 |
-
testSection.innerHTML = `
|
1389 |
-
<div class="quiz-card">
|
1390 |
-
<h3>Question ${quizIndex + 1} of ${quizQuestions.length}</h3>
|
1391 |
-
<p>${q.q}</p>
|
1392 |
-
${optionsHTML}
|
1393 |
-
<div style="text-align: center; margin-top: 25px;">
|
1394 |
-
<button id="submitAns">Submit Answer</button>
|
1395 |
-
</div>
|
1396 |
</div>
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
|
1416 |
-
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
}
|
1430 |
-
|
1431 |
-
//
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
-
|
1455 |
-
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1459 |
</body>
|
1460 |
</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>AI Explainer: How Neural Networks Work</title>
|
7 |
+
<style>
|
8 |
+
* {
|
9 |
+
margin: 0;
|
10 |
+
padding: 0;
|
11 |
+
box-sizing: border-box;
|
12 |
+
}
|
13 |
+
|
14 |
+
body {
|
15 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
16 |
+
background: #0a0a0a;
|
17 |
+
color: #e0e0e0;
|
18 |
+
line-height: 1.6;
|
19 |
+
overflow-x: hidden;
|
20 |
+
}
|
21 |
+
|
22 |
+
.container {
|
23 |
+
max-width: 1200px;
|
24 |
+
margin: 0 auto;
|
25 |
+
padding: 20px;
|
26 |
+
}
|
27 |
+
|
28 |
+
header {
|
29 |
+
text-align: center;
|
30 |
+
padding: 40px 20px;
|
31 |
+
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
|
32 |
+
margin-bottom: 40px;
|
33 |
+
border-radius: 20px;
|
34 |
+
}
|
35 |
+
|
36 |
+
h1 {
|
37 |
+
font-size: clamp(2rem, 5vw, 3rem);
|
38 |
+
margin-bottom: 10px;
|
39 |
+
background: linear-gradient(135deg, #fff 0%, #a8dadc 100%);
|
40 |
+
-webkit-background-clip: text;
|
41 |
+
-webkit-text-fill-color: transparent;
|
42 |
+
}
|
43 |
+
|
44 |
+
.mode-toggle {
|
45 |
+
display: flex;
|
46 |
+
justify-content: center;
|
47 |
+
gap: 20px;
|
48 |
+
margin: 30px 0;
|
49 |
+
flex-wrap: wrap;
|
50 |
+
}
|
51 |
+
|
52 |
+
.mode-btn {
|
53 |
+
padding: 12px 30px;
|
54 |
+
background: #2a5298;
|
55 |
+
color: white;
|
56 |
+
border: none;
|
57 |
+
border-radius: 50px;
|
58 |
+
cursor: pointer;
|
59 |
+
font-size: 16px;
|
60 |
+
transition: all 0.3s ease;
|
61 |
+
font-weight: 600;
|
62 |
+
}
|
63 |
+
|
64 |
+
.mode-btn.active {
|
65 |
+
background: #4CAF50;
|
66 |
+
transform: scale(1.05);
|
67 |
+
}
|
68 |
+
|
69 |
+
.mode-btn:hover {
|
70 |
+
transform: translateY(-2px);
|
71 |
+
box-shadow: 0 5px 15px rgba(74, 144, 226, 0.3);
|
72 |
+
}
|
73 |
+
|
74 |
+
.section {
|
75 |
+
background: #1a1a1a;
|
76 |
+
padding: 30px;
|
77 |
+
margin-bottom: 30px;
|
78 |
+
border-radius: 20px;
|
79 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
|
80 |
+
}
|
81 |
+
|
82 |
+
.section h2 {
|
83 |
+
color: #4CAF50;
|
84 |
+
margin-bottom: 20px;
|
85 |
+
font-size: clamp(1.5rem, 4vw, 2rem);
|
86 |
+
}
|
87 |
+
|
88 |
+
.section h3 {
|
89 |
+
color: #81C784;
|
90 |
+
margin: 20px 0 10px 0;
|
91 |
+
font-size: clamp(1.2rem, 3vw, 1.5rem);
|
92 |
+
}
|
93 |
+
|
94 |
+
.math-content {
|
95 |
+
background: #0d0d0d;
|
96 |
+
padding: 20px;
|
97 |
+
border-radius: 10px;
|
98 |
+
overflow-x: auto;
|
99 |
+
margin: 15px 0;
|
100 |
+
border: 1px solid #333;
|
101 |
+
}
|
102 |
+
|
103 |
+
.learn-content {
|
104 |
+
background: #1e3c72;
|
105 |
+
padding: 20px;
|
106 |
+
border-radius: 10px;
|
107 |
+
margin: 15px 0;
|
108 |
+
line-height: 1.8;
|
109 |
+
}
|
110 |
+
|
111 |
+
#xor-demo {
|
112 |
+
background: #0d0d0d;
|
113 |
+
padding: 20px;
|
114 |
+
border-radius: 15px;
|
115 |
+
margin: 20px 0;
|
116 |
+
}
|
117 |
+
|
118 |
+
#network-canvas {
|
119 |
+
width: 100%;
|
120 |
+
max-width: 800px;
|
121 |
+
height: 400px;
|
122 |
+
background: #000;
|
123 |
+
border-radius: 10px;
|
124 |
+
margin: 20px auto;
|
125 |
+
display: block;
|
126 |
+
}
|
127 |
+
|
128 |
+
.controls {
|
129 |
+
display: flex;
|
130 |
+
gap: 15px;
|
131 |
+
justify-content: center;
|
132 |
+
flex-wrap: wrap;
|
133 |
+
margin: 20px 0;
|
134 |
+
}
|
135 |
+
|
136 |
+
.control-btn {
|
137 |
+
padding: 10px 25px;
|
138 |
+
background: #4CAF50;
|
139 |
+
color: white;
|
140 |
+
border: none;
|
141 |
+
border-radius: 5px;
|
142 |
+
cursor: pointer;
|
143 |
+
font-size: 16px;
|
144 |
+
transition: all 0.3s ease;
|
145 |
+
}
|
146 |
+
|
147 |
+
.control-btn:hover {
|
148 |
+
background: #45a049;
|
149 |
+
transform: translateY(-2px);
|
150 |
+
}
|
151 |
+
|
152 |
+
.control-btn:disabled {
|
153 |
+
background: #666;
|
154 |
+
cursor: not-allowed;
|
155 |
+
}
|
156 |
+
|
157 |
+
.stats {
|
158 |
+
display: grid;
|
159 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
160 |
+
gap: 15px;
|
161 |
+
margin: 20px 0;
|
162 |
+
}
|
163 |
+
|
164 |
+
.stat-box {
|
165 |
+
background: #1a1a1a;
|
166 |
+
padding: 15px;
|
167 |
+
border-radius: 10px;
|
168 |
+
text-align: center;
|
169 |
+
border: 1px solid #333;
|
170 |
+
}
|
171 |
+
|
172 |
+
.stat-label {
|
173 |
+
color: #888;
|
174 |
+
font-size: 14px;
|
175 |
+
}
|
176 |
+
|
177 |
+
.stat-value {
|
178 |
+
color: #4CAF50;
|
179 |
+
font-size: 24px;
|
180 |
+
font-weight: bold;
|
181 |
+
margin-top: 5px;
|
182 |
+
}
|
183 |
+
|
184 |
+
.loss-chart {
|
185 |
+
width: 100%;
|
186 |
+
height: 200px;
|
187 |
+
background: #000;
|
188 |
+
border-radius: 10px;
|
189 |
+
margin: 20px 0;
|
190 |
+
}
|
191 |
+
|
192 |
+
.formula {
|
193 |
+
font-family: 'Courier New', monospace;
|
194 |
+
color: #64B5F6;
|
195 |
+
padding: 10px;
|
196 |
+
background: rgba(0, 0, 0, 0.5);
|
197 |
+
border-radius: 5px;
|
198 |
+
overflow-x: auto;
|
199 |
+
white-space: nowrap;
|
200 |
+
margin: 10px 0;
|
201 |
+
}
|
202 |
+
|
203 |
+
.highlight {
|
204 |
+
background: #4CAF50;
|
205 |
+
color: #000;
|
206 |
+
padding: 2px 6px;
|
207 |
+
border-radius: 3px;
|
208 |
+
font-weight: bold;
|
209 |
+
}
|
210 |
+
|
211 |
+
@media (max-width: 768px) {
|
212 |
+
.container {
|
213 |
+
padding: 10px;
|
214 |
+
}
|
215 |
+
|
216 |
+
.section {
|
217 |
+
padding: 20px;
|
218 |
+
}
|
219 |
+
|
220 |
+
#network-canvas {
|
221 |
+
height: 300px;
|
222 |
+
}
|
223 |
+
|
224 |
+
.controls {
|
225 |
+
gap: 10px;
|
226 |
+
}
|
227 |
+
|
228 |
+
.control-btn {
|
229 |
+
padding: 8px 20px;
|
230 |
+
font-size: 14px;
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
.mode-content {
|
235 |
+
display: none;
|
236 |
+
}
|
237 |
+
|
238 |
+
.mode-content.active {
|
239 |
+
display: block;
|
240 |
+
}
|
241 |
+
|
242 |
+
.animated-number {
|
243 |
+
transition: all 0.3s ease;
|
244 |
+
}
|
245 |
+
|
246 |
+
@keyframes pulse {
|
247 |
+
0% { transform: scale(1); }
|
248 |
+
50% { transform: scale(1.1); }
|
249 |
+
100% { transform: scale(1); }
|
250 |
+
}
|
251 |
+
|
252 |
+
.pulse {
|
253 |
+
animation: pulse 0.5s ease;
|
254 |
+
}
|
255 |
+
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
</head>
|
257 |
<body>
|
258 |
+
<div class="container">
|
259 |
+
<header>
|
260 |
+
<h1>🧠 How AI Really Works</h1>
|
261 |
+
<p>An Interactive Journey Inside Neural Networks</p>
|
262 |
+
</header>
|
263 |
+
|
264 |
+
<div class="mode-toggle">
|
265 |
+
<button class="mode-btn active" onclick="setMode('learn')">🎓 Learn Mode</button>
|
266 |
+
<button class="mode-btn" onclick="setMode('math')">🔢 Math Mode</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
</div>
|
268 |
+
|
269 |
+
<div class="section">
|
270 |
+
<h2>What is a Neural Network?</h2>
|
271 |
+
|
272 |
+
<div class="mode-content learn-mode active">
|
273 |
+
<div class="learn-content">
|
274 |
+
<p>Imagine your brain is made of billions of tiny decision-makers called neurons. Each neuron:</p>
|
275 |
+
<ul style="margin: 15px 0; padding-left: 30px;">
|
276 |
+
<li>🎯 Takes in information (inputs)</li>
|
277 |
+
<li>🤔 Thinks about it (processing)</li>
|
278 |
+
<li>💡 Makes a decision (output)</li>
|
279 |
+
</ul>
|
280 |
+
<p>An AI neural network works the same way! It's like a simplified brain made of math. Let's see it in action!</p>
|
281 |
+
</div>
|
282 |
+
</div>
|
283 |
+
|
284 |
+
<div class="mode-content math-mode">
|
285 |
+
<div class="math-content">
|
286 |
+
<p>A neural network is a function approximator that transforms inputs through layers of neurons:</p>
|
287 |
+
<div class="formula">
|
288 |
+
f(x) = σ(W₃ · σ(W₂ · σ(W₁ · x + b₁) + b₂) + b₃)
|
289 |
+
</div>
|
290 |
+
<p>Where:</p>
|
291 |
+
<ul style="margin: 15px 0; padding-left: 30px;">
|
292 |
+
<li>x = input vector</li>
|
293 |
+
<li>Wᵢ = weight matrix for layer i</li>
|
294 |
+
<li>bᵢ = bias vector for layer i</li>
|
295 |
+
<li>σ = activation function (e.g., ReLU, sigmoid)</li>
|
296 |
+
</ul>
|
297 |
+
</div>
|
298 |
+
</div>
|
299 |
</div>
|
300 |
+
|
301 |
+
<div class="section">
|
302 |
+
<h2>🎮 Live XOR Training Demo</h2>
|
303 |
+
<p>Watch an AI learn the XOR problem in real-time! XOR outputs 1 when inputs are different, 0 when same.</p>
|
304 |
+
|
305 |
+
<div id="xor-demo">
|
306 |
+
<canvas id="network-canvas"></canvas>
|
307 |
+
|
308 |
+
<div class="controls">
|
309 |
+
<button class="control-btn" onclick="startTraining()">▶️ Start Training</button>
|
310 |
+
<button class="control-btn" onclick="pauseTraining()">⏸️ Pause</button>
|
311 |
+
<button class="control-btn" onclick="resetNetwork()">🔄 Reset</button>
|
312 |
+
<button class="control-btn" onclick="stepTraining()">⏭️ Step</button>
|
313 |
+
</div>
|
314 |
+
|
315 |
+
<div class="stats">
|
316 |
+
<div class="stat-box">
|
317 |
+
<div class="stat-label">Epoch</div>
|
318 |
+
<div class="stat-value animated-number" id="epoch">0</div>
|
319 |
+
</div>
|
320 |
+
<div class="stat-box">
|
321 |
+
<div class="stat-label">Loss</div>
|
322 |
+
<div class="stat-value animated-number" id="loss">1.000</div>
|
323 |
+
</div>
|
324 |
+
<div class="stat-box">
|
325 |
+
<div class="stat-label">Accuracy</div>
|
326 |
+
<div class="stat-value animated-number" id="accuracy">0%</div>
|
327 |
+
</div>
|
328 |
+
<div class="stat-box">
|
329 |
+
<div class="stat-label">Learning Rate</div>
|
330 |
+
<div class="stat-value" id="learning-rate">0.1</div>
|
331 |
+
</div>
|
332 |
+
</div>
|
333 |
+
|
334 |
+
<canvas id="loss-chart" class="loss-chart"></canvas>
|
335 |
+
</div>
|
336 |
+
</div>
|
337 |
+
|
338 |
+
<div class="section">
|
339 |
+
<h2>How Does Learning Work?</h2>
|
340 |
+
|
341 |
+
<div class="mode-content learn-mode active">
|
342 |
+
<h3>🎯 Forward Pass: Making Predictions</h3>
|
343 |
+
<div class="learn-content">
|
344 |
+
<p>The network makes a prediction by passing data forward through each layer:</p>
|
345 |
+
<ol style="margin: 15px 0; padding-left: 30px;">
|
346 |
+
<li><span class="highlight">Input</span>: Feed in the data (like 0,1 for XOR)</li>
|
347 |
+
<li><span class="highlight">Multiply & Add</span>: Each connection has a "strength" (weight)</li>
|
348 |
+
<li><span class="highlight">Activate</span>: Decide if the neuron should "fire"</li>
|
349 |
+
<li><span class="highlight">Output</span>: Get the final prediction</li>
|
350 |
+
</ol>
|
351 |
+
</div>
|
352 |
+
|
353 |
+
<h3>📉 Backward Pass: Learning from Mistakes</h3>
|
354 |
+
<div class="learn-content">
|
355 |
+
<p>When the network is wrong, it learns by adjusting its connections:</p>
|
356 |
+
<ol style="margin: 15px 0; padding-left: 30px;">
|
357 |
+
<li><span class="highlight">Calculate Error</span>: How wrong was the prediction?</li>
|
358 |
+
<li><span class="highlight">Blame Game</span>: Which connections caused the error?</li>
|
359 |
+
<li><span class="highlight">Adjust Weights</span>: Make connections stronger or weaker</li>
|
360 |
+
<li><span class="highlight">Repeat</span>: Try again with new weights!</li>
|
361 |
+
</ol>
|
362 |
+
</div>
|
363 |
+
</div>
|
364 |
+
|
365 |
+
<div class="mode-content math-mode">
|
366 |
+
<h3>Forward Propagation</h3>
|
367 |
+
<div class="math-content">
|
368 |
+
<p>For each layer l:</p>
|
369 |
+
<div class="formula">
|
370 |
+
z[l] = W[l] · a[l-1] + b[l]
|
371 |
+
</div>
|
372 |
+
<div class="formula">
|
373 |
+
a[l] = σ(z[l])
|
374 |
+
</div>
|
375 |
+
<p>Where a[0] = x (input) and a[L] = ŷ (output)</p>
|
376 |
+
</div>
|
377 |
+
|
378 |
+
<h3>Backpropagation</h3>
|
379 |
+
<div class="math-content">
|
380 |
+
<p>Loss function (Mean Squared Error):</p>
|
381 |
+
<div class="formula">
|
382 |
+
L = ½ Σ(y - ŷ)²
|
383 |
+
</div>
|
384 |
+
<p>Gradient computation:</p>
|
385 |
+
<div class="formula">
|
386 |
+
δ[L] = ∇ₐL ⊙ σ'(z[L])
|
387 |
+
</div>
|
388 |
+
<div class="formula">
|
389 |
+
δ[l] = (W[l+1]ᵀ · δ[l+1]) ⊙ σ'(z[l])
|
390 |
+
</div>
|
391 |
+
<p>Weight update:</p>
|
392 |
+
<div class="formula">
|
393 |
+
W[l] = W[l] - α · δ[l] · a[l-1]ᵀ
|
394 |
+
</div>
|
395 |
+
<div class="formula">
|
396 |
+
b[l] = b[l] - α · δ[l]
|
397 |
+
</div>
|
398 |
+
</div>
|
399 |
+
</div>
|
400 |
+
</div>
|
401 |
+
|
402 |
+
<div class="section">
|
403 |
+
<h2>Key Components Explained</h2>
|
404 |
+
|
405 |
+
<div class="mode-content learn-mode active">
|
406 |
+
<h3>🔗 Weights & Biases</h3>
|
407 |
+
<div class="learn-content">
|
408 |
+
<p><span class="highlight">Weights</span> are like volume knobs - they control how much each input matters.</p>
|
409 |
+
<p><span class="highlight">Biases</span> are like thresholds - they decide when a neuron should activate.</p>
|
410 |
+
</div>
|
411 |
+
|
412 |
+
<h3>⚡ Activation Functions</h3>
|
413 |
+
<div class="learn-content">
|
414 |
+
<p>These decide if a neuron should "fire" or not:</p>
|
415 |
+
<ul style="margin: 15px 0; padding-left: 30px;">
|
416 |
+
<li><span class="highlight">ReLU</span>: If positive, pass it on. If negative, block it!</li>
|
417 |
+
<li><span class="highlight">Sigmoid</span>: Squash everything between 0 and 1</li>
|
418 |
+
<li><span class="highlight">Tanh</span>: Squash everything between -1 and 1</li>
|
419 |
+
</ul>
|
420 |
+
</div>
|
421 |
+
|
422 |
+
<h3>🎯 Gradient Descent</h3>
|
423 |
+
<div class="learn-content">
|
424 |
+
<p>Imagine you're blindfolded on a hill, trying to reach the bottom:</p>
|
425 |
+
<ol style="margin: 15px 0; padding-left: 30px;">
|
426 |
+
<li>Feel the slope around you (calculate gradient)</li>
|
427 |
+
<li>Take a small step downhill (adjust weights)</li>
|
428 |
+
<li>Repeat until you reach the bottom (minimum loss)</li>
|
429 |
+
</ol>
|
430 |
+
</div>
|
431 |
+
</div>
|
432 |
+
|
433 |
+
<div class="mode-content math-mode">
|
434 |
+
<h3>Activation Functions</h3>
|
435 |
+
<div class="math-content">
|
436 |
+
<p><strong>ReLU:</strong></p>
|
437 |
+
<div class="formula">
|
438 |
+
f(x) = max(0, x)
|
439 |
+
</div>
|
440 |
+
<div class="formula">
|
441 |
+
f'(x) = {1 if x > 0, 0 if x ≤ 0}
|
442 |
+
</div>
|
443 |
+
|
444 |
+
<p><strong>Sigmoid:</strong></p>
|
445 |
+
<div class="formula">
|
446 |
+
σ(x) = 1 / (1 + e⁻ˣ)
|
447 |
+
</div>
|
448 |
+
<div class="formula">
|
449 |
+
σ'(x) = σ(x) · (1 - σ(x))
|
450 |
+
</div>
|
451 |
+
|
452 |
+
<p><strong>Tanh:</strong></p>
|
453 |
+
<div class="formula">
|
454 |
+
tanh(x) = (eˣ - e⁻ˣ) / (eˣ + e⁻ˣ)
|
455 |
+
</div>
|
456 |
+
<div class="formula">
|
457 |
+
tanh'(x) = 1 - tanh²(x)
|
458 |
+
</div>
|
459 |
+
</div>
|
460 |
+
|
461 |
+
<h3>Gradient Descent Update Rule</h3>
|
462 |
+
<div class="math-content">
|
463 |
+
<div class="formula">
|
464 |
+
θₜ₊₁ = θₜ - α · ∇θ L(θₜ)
|
465 |
+
</div>
|
466 |
+
<p>Where:</p>
|
467 |
+
<ul style="margin: 15px 0; padding-left: 30px;">
|
468 |
+
<li>θ = parameters (weights and biases)</li>
|
469 |
+
<li>α = learning rate</li>
|
470 |
+
<li>∇θ L = gradient of loss with respect to parameters</li>
|
471 |
+
</ul>
|
472 |
+
</div>
|
473 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
475 |
</div>
|
476 |
+
|
477 |
+
<script>
|
478 |
+
// Global variables
|
479 |
+
let mode = 'learn';
|
480 |
+
let network = null;
|
481 |
+
let training = false;
|
482 |
+
let epoch = 0;
|
483 |
+
let lossHistory = [];
|
484 |
+
const canvas = document.getElementById('network-canvas');
|
485 |
+
const ctx = canvas.getContext('2d');
|
486 |
+
const lossCanvas = document.getElementById('loss-chart');
|
487 |
+
const lossCtx = lossCanvas.getContext('2d');
|
488 |
+
|
489 |
+
// Set canvas sizes
|
490 |
+
function resizeCanvases() {
|
491 |
+
canvas.width = canvas.offsetWidth;
|
492 |
+
canvas.height = canvas.offsetHeight;
|
493 |
+
lossCanvas.width = lossCanvas.offsetWidth;
|
494 |
+
lossCanvas.height = lossCanvas.offsetHeight;
|
495 |
+
}
|
496 |
+
resizeCanvases();
|
497 |
+
window.addEventListener('resize', resizeCanvases);
|
498 |
+
|
499 |
+
// Mode switching
|
500 |
+
function setMode(newMode) {
|
501 |
+
mode = newMode;
|
502 |
+
document.querySelectorAll('.mode-btn').forEach(btn => {
|
503 |
+
btn.classList.toggle('active', btn.textContent.toLowerCase().includes(newMode));
|
504 |
+
});
|
505 |
+
document.querySelectorAll('.mode-content').forEach(content => {
|
506 |
+
content.classList.toggle('active', content.classList.contains(`${newMode}-mode`));
|
507 |
+
});
|
508 |
+
}
|
509 |
+
|
510 |
+
// Neural Network Class
|
511 |
+
class NeuralNetwork {
|
512 |
+
constructor() {
|
513 |
+
// Network architecture: 2-25-25-1 (roughly 100 parameters)
|
514 |
+
this.layers = [2, 25, 25, 1];
|
515 |
+
this.weights = [];
|
516 |
+
this.biases = [];
|
517 |
+
this.activations = [];
|
518 |
+
this.zValues = [];
|
519 |
+
this.gradients = [];
|
520 |
+
this.learningRate = 0.1;
|
521 |
+
|
522 |
+
this.initializeNetwork();
|
523 |
+
}
|
524 |
+
|
525 |
+
initializeNetwork() {
|
526 |
+
// Xavier initialization
|
527 |
+
for (let i = 1; i < this.layers.length; i++) {
|
528 |
+
const rows = this.layers[i];
|
529 |
+
const cols = this.layers[i-1];
|
530 |
+
const scale = Math.sqrt(2.0 / cols);
|
531 |
+
|
532 |
+
// Initialize weights
|
533 |
+
this.weights[i-1] = [];
|
534 |
+
for (let r = 0; r < rows; r++) {
|
535 |
+
this.weights[i-1][r] = [];
|
536 |
+
for (let c = 0; c < cols; c++) {
|
537 |
+
this.weights[i-1][r][c] = (Math.random() * 2 - 1) * scale;
|
538 |
+
}
|
539 |
+
}
|
540 |
+
|
541 |
+
// Initialize biases
|
542 |
+
this.biases[i-1] = new Array(rows).fill(0);
|
543 |
+
}
|
544 |
+
}
|
545 |
+
|
546 |
+
sigmoid(x) {
|
547 |
+
return 1 / (1 + Math.exp(-x));
|
548 |
+
}
|
549 |
+
|
550 |
+
sigmoidDerivative(x) {
|
551 |
+
const s = this.sigmoid(x);
|
552 |
+
return s * (1 - s);
|
553 |
+
}
|
554 |
+
|
555 |
+
relu(x) {
|
556 |
+
return Math.max(0, x);
|
557 |
+
}
|
558 |
+
|
559 |
+
reluDerivative(x) {
|
560 |
+
return x > 0 ? 1 : 0;
|
561 |
+
}
|
562 |
+
|
563 |
+
forward(input) {
|
564 |
+
this.activations = [input];
|
565 |
+
this.zValues = [];
|
566 |
+
|
567 |
+
for (let i = 0; i < this.weights.length; i++) {
|
568 |
+
const z = [];
|
569 |
+
const a = [];
|
570 |
+
|
571 |
+
for (let j = 0; j < this.weights[i].length; j++) {
|
572 |
+
let sum = this.biases[i][j];
|
573 |
+
for (let k = 0; k < this.weights[i][j].length; k++) {
|
574 |
+
sum += this.weights[i][j][k] * this.activations[i][k];
|
575 |
+
}
|
576 |
+
z.push(sum);
|
577 |
+
|
578 |
+
// Use ReLU for hidden layers, sigmoid for output
|
579 |
+
if (i < this.weights.length - 1) {
|
580 |
+
a.push(this.relu(sum));
|
581 |
+
} else {
|
582 |
+
a.push(this.sigmoid(sum));
|
583 |
+
}
|
584 |
+
}
|
585 |
+
|
586 |
+
this.zValues.push(z);
|
587 |
+
this.activations.push(a);
|
588 |
+
}
|
589 |
+
|
590 |
+
return this.activations[this.activations.length - 1][0];
|
591 |
+
}
|
592 |
+
|
593 |
+
backward(input, target) {
|
594 |
+
const output = this.forward(input);
|
595 |
+
const error = output - target;
|
596 |
+
|
597 |
+
// Initialize gradients
|
598 |
+
this.gradients = [];
|
599 |
+
|
600 |
+
// Output layer gradients
|
601 |
+
let delta = [error * this.sigmoidDerivative(this.zValues[this.zValues.length - 1][0])];
|
602 |
+
this.gradients.unshift(delta);
|
603 |
+
|
604 |
+
// Hidden layer gradients
|
605 |
+
for (let i = this.weights.length - 2; i >= 0; i--) {
|
606 |
+
const newDelta = [];
|
607 |
+
for (let j = 0; j < this.weights[i].length; j++) {
|
608 |
+
let sum = 0;
|
609 |
+
for (let k = 0; k < delta.length; k++) {
|
610 |
+
sum += this.weights[i+1][k][j] * delta[k];
|
611 |
+
}
|
612 |
+
const activation = i > 0 ?
|
613 |
+
this.reluDerivative(this.zValues[i][j]) :
|
614 |
+
this.reluDerivative(this.zValues[i][j]);
|
615 |
+
newDelta.push(sum * activation);
|
616 |
+
}
|
617 |
+
delta = newDelta;
|
618 |
+
this.gradients.unshift(delta);
|
619 |
+
}
|
620 |
+
|
621 |
+
// Update weights and biases
|
622 |
+
for (let i = 0; i < this.weights.length; i++) {
|
623 |
+
for (let j = 0; j < this.weights[i].length; j++) {
|
624 |
+
for (let k = 0; k < this.weights[i][j].length; k++) {
|
625 |
+
this.weights[i][j][k] -= this.learningRate * this.gradients[i][j] * this.activations[i][k];
|
626 |
+
}
|
627 |
+
this.biases[i][j] -= this.learningRate * this.gradients[i][j];
|
628 |
+
}
|
629 |
+
}
|
630 |
+
|
631 |
+
return error * error;
|
632 |
+
}
|
633 |
+
|
634 |
+
train(inputs, targets) {
|
635 |
+
let totalLoss = 0;
|
636 |
+
for (let i = 0; i < inputs.length; i++) {
|
637 |
+
totalLoss += this.backward(inputs[i], targets[i]);
|
638 |
+
}
|
639 |
+
return totalLoss / inputs.length;
|
640 |
+
}
|
641 |
+
|
642 |
+
predict(input) {
|
643 |
+
return this.forward(input);
|
644 |
+
}
|
645 |
+
}
|
646 |
+
|
647 |
+
// XOR training data
|
648 |
+
const xorInputs = [[0, 0], [0, 1], [1, 0], [1, 1]];
|
649 |
+
const xorTargets = [0, 1, 1, 0];
|
650 |
+
|
651 |
+
// Initialize network
|
652 |
+
function resetNetwork() {
|
653 |
+
network = new NeuralNetwork();
|
654 |
+
epoch = 0;
|
655 |
+
lossHistory = [];
|
656 |
+
training = false;
|
657 |
+
updateStats();
|
658 |
+
drawNetwork();
|
659 |
+
drawLossChart();
|
660 |
+
}
|
661 |
+
|
662 |
+
// Training functions
|
663 |
+
function startTraining() {
|
664 |
+
training = true;
|
665 |
+
trainLoop();
|
666 |
+
}
|
667 |
+
|
668 |
+
function pauseTraining() {
|
669 |
+
training = false;
|
670 |
+
}
|
671 |
+
|
672 |
+
function stepTraining() {
|
673 |
+
if (!network) resetNetwork();
|
674 |
+
trainStep();
|
675 |
+
}
|
676 |
+
|
677 |
+
function trainStep() {
|
678 |
+
const loss = network.train(xorInputs, xorTargets);
|
679 |
+
epoch++;
|
680 |
+
lossHistory.push(loss);
|
681 |
+
if (lossHistory.length > 100) lossHistory.shift();
|
682 |
+
|
683 |
+
updateStats();
|
684 |
+
drawNetwork();
|
685 |
+
drawLossChart();
|
686 |
+
}
|
687 |
+
|
688 |
+
function trainLoop() {
|
689 |
+
if (!training) return;
|
690 |
+
|
691 |
+
trainStep();
|
692 |
+
|
693 |
+
if (epoch < 1000 && lossHistory[lossHistory.length - 1] > 0.001) {
|
694 |
+
requestAnimationFrame(trainLoop);
|
695 |
+
} else {
|
696 |
+
training = false;
|
697 |
+
}
|
698 |
+
}
|
699 |
+
|
700 |
+
// Update statistics
|
701 |
+
function updateStats() {
|
702 |
+
document.getElementById('epoch').textContent = epoch;
|
703 |
+
|
704 |
+
const loss = lossHistory.length > 0 ? lossHistory[lossHistory.length - 1] : 1;
|
705 |
+
document.getElementById('loss').textContent = loss.toFixed(4);
|
706 |
+
|
707 |
+
// Calculate accuracy
|
708 |
+
let correct = 0;
|
709 |
+
for (let i = 0; i < xorInputs.length; i++) {
|
710 |
+
const prediction = network ? network.predict(xorInputs[i]) : 0.5;
|
711 |
+
const rounded = Math.round(prediction);
|
712 |
+
if (rounded === xorTargets[i]) correct++;
|
713 |
+
}
|
714 |
+
const accuracy = (correct / xorInputs.length * 100).toFixed(0);
|
715 |
+
document.getElementById('accuracy').textContent = accuracy + '%';
|
716 |
+
|
717 |
+
// Add pulse animation on high accuracy
|
718 |
+
if (accuracy >= 100) {
|
719 |
+
document.getElementById('accuracy').parentElement.classList.add('pulse');
|
720 |
+
setTimeout(() => {
|
721 |
+
document.getElementById('accuracy').parentElement.classList.remove('pulse');
|
722 |
+
}, 500);
|
723 |
+
}
|
724 |
+
}
|
725 |
+
|
726 |
+
// Visualization functions
|
727 |
+
function drawNetwork() {
|
728 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
729 |
+
|
730 |
+
if (!network) return;
|
731 |
+
|
732 |
+
const layerSpacing = canvas.width / (network.layers.length + 1);
|
733 |
+
const neurons = [];
|
734 |
+
|
735 |
+
// Calculate neuron positions
|
736 |
+
for (let i = 0; i < network.layers.length; i++) {
|
737 |
+
neurons[i] = [];
|
738 |
+
const layerSize = network.layers[i];
|
739 |
+
const ySpacing = canvas.height / (layerSize + 1);
|
740 |
+
|
741 |
+
for (let j = 0; j < layerSize; j++) {
|
742 |
+
const x = layerSpacing * (i + 1);
|
743 |
+
const y = ySpacing * (j + 1);
|
744 |
+
neurons[i].push({ x, y });
|
745 |
+
}
|
746 |
+
}
|
747 |
+
|
748 |
+
// Draw connections
|
749 |
+
for (let i = 0; i < network.weights.length; i++) {
|
750 |
+
for (let j = 0; j < network.weights[i].length; j++) {
|
751 |
+
for (let k = 0; k < network.weights[i][j].length; k++) {
|
752 |
+
const weight = network.weights[i][j][k];
|
753 |
+
const opacity = Math.min(Math.abs(weight) / 2, 1);
|
754 |
+
|
755 |
+
ctx.beginPath();
|
756 |
+
ctx.moveTo(neurons[i][k].x, neurons[i][k].y);
|
757 |
+
ctx.lineTo(neurons[i+1][j].x, neurons[i+1][j].y);
|
758 |
+
|
759 |
+
if (weight > 0) {
|
760 |
+
ctx.strokeStyle = `rgba(76, 175, 80, ${opacity})`;
|
761 |
+
} else {
|
762 |
+
ctx.strokeStyle = `rgba(244, 67, 54, ${opacity})`;
|
763 |
+
}
|
764 |
+
|
765 |
+
ctx.lineWidth = Math.abs(weight) * 2;
|
766 |
+
ctx.stroke();
|
767 |
+
}
|
768 |
+
}
|
769 |
+
}
|
770 |
+
|
771 |
+
// Draw neurons
|
772 |
+
for (let i = 0; i < neurons.length; i++) {
|
773 |
+
for (let j = 0; j < neurons[i].length; j++) {
|
774 |
+
const neuron = neurons[i][j];
|
775 |
+
|
776 |
+
// Get activation value
|
777 |
+
let activation = 0;
|
778 |
+
if (network.activations[i] && network.activations[i][j] !== undefined) {
|
779 |
+
activation = network.activations[i][j];
|
780 |
+
}
|
781 |
+
|
782 |
+
const intensity = Math.min(activation * 255, 255);
|
783 |
+
|
784 |
+
ctx.beginPath();
|
785 |
+
ctx.arc(neuron.x, neuron.y, 15, 0, Math.PI * 2);
|
786 |
+
ctx.fillStyle = `rgb(${intensity}, ${intensity}, ${255})`;
|
787 |
+
ctx.fill();
|
788 |
+
ctx.strokeStyle = '#4CAF50';
|
789 |
+
ctx.lineWidth = 2;
|
790 |
+
ctx.stroke();
|
791 |
+
|
792 |
+
// Draw activation value for visible neurons
|
793 |
+
if (network.layers[i] <= 5 || i === 0 || i === network.layers.length - 1) {
|
794 |
+
ctx.fillStyle = '#fff';
|
795 |
+
ctx.font = '10px Arial';
|
796 |
+
ctx.textAlign = 'center';
|
797 |
+
ctx.textBaseline = 'middle';
|
798 |
+
ctx.fillText(activation.toFixed(2), neuron.x, neuron.y);
|
799 |
+
}
|
800 |
+
}
|
801 |
+
}
|
802 |
+
|
803 |
+
// Draw layer labels
|
804 |
+
ctx.fillStyle = '#888';
|
805 |
+
ctx.font = '14px Arial';
|
806 |
+
ctx.textAlign = 'center';
|
807 |
+
|
808 |
+
const labels = ['Input', 'Hidden 1', 'Hidden 2', 'Output'];
|
809 |
+
for (let i = 0; i < network.layers.length; i++) {
|
810 |
+
const x = layerSpacing * (i + 1);
|
811 |
+
ctx.fillText(labels[i], x, 30);
|
812 |
+
ctx.fillText(`(${network.layers[i]} neurons)`, x, 45);
|
813 |
+
}
|
814 |
+
|
815 |
+
// Draw XOR truth table
|
816 |
+
ctx.fillStyle = '#4CAF50';
|
817 |
+
ctx.font = '12px Arial';
|
818 |
+
ctx.textAlign = 'left';
|
819 |
+
ctx.fillText('XOR Truth Table:', 20, canvas.height - 80);
|
820 |
+
ctx.fillStyle = '#888';
|
821 |
+
ctx.fillText('0 XOR 0 = 0', 20, canvas.height - 60);
|
822 |
+
ctx.fillText('0 XOR 1 = 1', 20, canvas.height - 45);
|
823 |
+
ctx.fillText('1 XOR 0 = 1', 20, canvas.height - 30);
|
824 |
+
ctx.fillText('1 XOR 1 = 0', 20, canvas.height - 15);
|
825 |
+
|
826 |
+
// Show current predictions
|
827 |
+
if (network) {
|
828 |
+
ctx.fillStyle = '#4CAF50';
|
829 |
+
ctx.fillText('Network Output:', 150, canvas.height - 80);
|
830 |
+
ctx.fillStyle = '#888';
|
831 |
+
for (let i = 0; i < xorInputs.length; i++) {
|
832 |
+
const prediction = network.predict(xorInputs[i]);
|
833 |
+
const text = `${xorInputs[i][0]} XOR ${xorInputs[i][1]} = ${prediction.toFixed(3)}`;
|
834 |
+
ctx.fillText(text, 150, canvas.height - 60 + i * 15);
|
835 |
+
}
|
836 |
+
}
|
837 |
+
}
|
838 |
+
|
839 |
+
function drawLossChart() {
|
840 |
+
lossCtx.clearRect(0, 0, lossCanvas.width, lossCanvas.height);
|
841 |
+
|
842 |
+
if (lossHistory.length < 2) return;
|
843 |
+
|
844 |
+
// Find min and max for scaling
|
845 |
+
const maxLoss = Math.max(...lossHistory, 0.5);
|
846 |
+
const minLoss = 0;
|
847 |
+
|
848 |
+
// Draw axes
|
849 |
+
lossCtx.strokeStyle = '#444';
|
850 |
+
lossCtx.lineWidth = 1;
|
851 |
+
lossCtx.beginPath();
|
852 |
+
lossCtx.moveTo(40, 10);
|
853 |
+
lossCtx.lineTo(40, lossCanvas.height - 30);
|
854 |
+
lossCtx.lineTo(lossCanvas.width - 10, lossCanvas.height - 30);
|
855 |
+
lossCtx.stroke();
|
856 |
+
|
857 |
+
// Draw labels
|
858 |
+
lossCtx.fillStyle = '#888';
|
859 |
+
lossCtx.font = '12px Arial';
|
860 |
+
lossCtx.textAlign = 'right';
|
861 |
+
lossCtx.fillText(maxLoss.toFixed(3), 35, 15);
|
862 |
+
lossCtx.fillText('0', 35, lossCanvas.height - 30);
|
863 |
+
lossCtx.textAlign = 'center';
|
864 |
+
lossCtx.fillText('Loss over Time', lossCanvas.width / 2, lossCanvas.height - 10);
|
865 |
+
|
866 |
+
// Draw loss curve
|
867 |
+
lossCtx.strokeStyle = '#4CAF50';
|
868 |
+
lossCtx.lineWidth = 2;
|
869 |
+
lossCtx.beginPath();
|
870 |
+
|
871 |
+
const xStep = (lossCanvas.width - 50) / (lossHistory.length - 1);
|
872 |
+
const yScale = (lossCanvas.height - 50) / (maxLoss - minLoss);
|
873 |
+
|
874 |
+
for (let i = 0; i < lossHistory.length; i++) {
|
875 |
+
const x = 40 + i * xStep;
|
876 |
+
const y = lossCanvas.height - 30 - (lossHistory[i] - minLoss) * yScale;
|
877 |
+
|
878 |
+
if (i === 0) {
|
879 |
+
lossCtx.moveTo(x, y);
|
880 |
+
} else {
|
881 |
+
lossCtx.lineTo(x, y);
|
882 |
+
}
|
883 |
+
}
|
884 |
+
|
885 |
+
lossCtx.stroke();
|
886 |
+
|
887 |
+
// Draw current loss point
|
888 |
+
if (lossHistory.length > 0) {
|
889 |
+
const lastX = 40 + (lossHistory.length - 1) * xStep;
|
890 |
+
const lastY = lossCanvas.height - 30 - (lossHistory[lossHistory.length - 1] - minLoss) * yScale;
|
891 |
+
|
892 |
+
lossCtx.beginPath();
|
893 |
+
lossCtx.arc(lastX, lastY, 4, 0, Math.PI * 2);
|
894 |
+
lossCtx.fillStyle = '#4CAF50';
|
895 |
+
lossCtx.fill();
|
896 |
+
}
|
897 |
+
}
|
898 |
+
|
899 |
+
// Initialize
|
900 |
+
resetNetwork();
|
901 |
+
</script>
|
902 |
</body>
|
903 |
</html>
|