ProCreations commited on
Commit
b86ae0f
·
verified ·
1 Parent(s): ccc846f

Add walkthrough mode functionality

Browse files
Files changed (1) hide show
  1. index.html +323 -0
index.html CHANGED
@@ -2388,6 +2388,329 @@
2388
  // Developer mode event listeners
2389
  devArchitecture.addEventListener('input', updateParameterCount);
2390
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2391
  // Initialize
2392
  startAnimation();
2393
  </script>
 
2388
  // Developer mode event listeners
2389
  devArchitecture.addEventListener('input', updateParameterCount);
2390
 
2391
+ // Walkthrough Mode functionality
2392
+ let walkthroughActive = false;
2393
+ let walkthroughStep = 0;
2394
+ let walkthroughTutorial = null;
2395
+ let walkthroughTrainingSpeed = 500; // Slower training speed for walkthrough
2396
+
2397
+ const walkthroughTutorials = {
2398
+ basics: {
2399
+ title: 'Neural Network Basics',
2400
+ steps: [
2401
+ {
2402
+ title: 'Welcome to Neural Networks!',
2403
+ content: 'Neural networks are inspired by the human brain. They consist of layers of interconnected neurons that process information. Let\'s explore how they work!',
2404
+ element: null,
2405
+ position: 'center'
2406
+ },
2407
+ {
2408
+ title: 'Input Layer',
2409
+ content: 'This is the input layer (left side). It receives the raw data - like numbers, images, or text. Each circle represents one input neuron that holds a piece of information.',
2410
+ element: '#networkCanvas',
2411
+ position: 'right',
2412
+ highlight: {x: 0, y: 0, width: 150, height: 300}
2413
+ },
2414
+ {
2415
+ title: 'Hidden Layers',
2416
+ content: 'These middle layers are where the "magic" happens! They transform the input data through mathematical operations, finding patterns and relationships.',
2417
+ element: '#networkCanvas',
2418
+ position: 'top',
2419
+ highlight: {x: 150, y: 0, width: 100, height: 300}
2420
+ },
2421
+ {
2422
+ title: 'Output Layer',
2423
+ content: 'The final layer gives us the result - a prediction, classification, or decision based on what the network learned from the input.',
2424
+ element: '#networkCanvas',
2425
+ position: 'left',
2426
+ highlight: {x: 250, y: 0, width: 150, height: 300}
2427
+ },
2428
+ {
2429
+ title: 'Connections (Weights)',
2430
+ content: 'The lines between neurons are called weights. They determine how strongly one neuron influences another. Green lines mean positive influence, red means negative.',
2431
+ element: '#networkCanvas',
2432
+ position: 'bottom'
2433
+ }
2434
+ ]
2435
+ },
2436
+ training: {
2437
+ title: 'How Training Works',
2438
+ steps: [
2439
+ {
2440
+ title: 'The Training Process',
2441
+ content: 'Training is how neural networks learn! We show the network examples with known answers, and it adjusts its connections to get better at predicting the right answers.',
2442
+ element: null,
2443
+ position: 'center'
2444
+ },
2445
+ {
2446
+ title: 'Training Controls',
2447
+ content: 'Use these buttons to start, pause, or reset training. In walkthrough mode, training runs slower so you can see what\'s happening.',
2448
+ element: '.control-panel',
2449
+ position: 'bottom'
2450
+ },
2451
+ {
2452
+ title: 'Epochs Counter',
2453
+ content: 'An epoch is one complete pass through all training examples. More epochs usually mean better learning, but too many can cause overfitting.',
2454
+ element: '#epochValue',
2455
+ position: 'bottom'
2456
+ },
2457
+ {
2458
+ title: 'Loss Value',
2459
+ content: 'Loss measures how wrong the network\'s predictions are. Lower is better! Watch this number decrease as the network learns.',
2460
+ element: '#lossValue',
2461
+ position: 'bottom'
2462
+ },
2463
+ {
2464
+ title: 'Accuracy',
2465
+ content: 'This shows the percentage of correct predictions. 100% means the network gets every example right!',
2466
+ element: '#accuracyValue',
2467
+ position: 'bottom'
2468
+ }
2469
+ ]
2470
+ },
2471
+ visualization: {
2472
+ title: 'Understanding the Visualizations',
2473
+ steps: [
2474
+ {
2475
+ title: 'Reading the Network Diagram',
2476
+ content: 'The network diagram shows neurons as circles. Brighter neurons are more "activated" (have higher values). Watch them light up as data flows through!',
2477
+ element: '#networkCanvas',
2478
+ position: 'right'
2479
+ },
2480
+ {
2481
+ title: 'Loss Chart',
2482
+ content: 'This chart shows the training progress over time. The line should go down as the network improves. A flat line means learning has stopped.',
2483
+ element: '#chartContainer',
2484
+ position: 'left'
2485
+ },
2486
+ {
2487
+ title: 'Task Output',
2488
+ content: 'These cards show each training example. Green means correct prediction, red means wrong. The network tries to make all cards green!',
2489
+ element: '#taskOutput',
2490
+ position: 'top'
2491
+ },
2492
+ {
2493
+ title: 'Current Sample',
2494
+ content: 'The blue highlighted card shows which example the network is currently learning from. It cycles through all examples.',
2495
+ element: '.output-card.current',
2496
+ position: 'top'
2497
+ }
2498
+ ]
2499
+ },
2500
+ logic: {
2501
+ title: 'Logic Gates Tutorial',
2502
+ steps: [
2503
+ {
2504
+ title: 'Logic Gates with Neural Networks',
2505
+ content: 'Let\'s see how neural networks can learn logic gates - the building blocks of computers! We\'ll start with the simple AND gate.',
2506
+ element: null,
2507
+ position: 'center',
2508
+ action: () => selectTask('and')
2509
+ },
2510
+ {
2511
+ title: 'AND Gate',
2512
+ content: 'The AND gate outputs 1 only when both inputs are 1. This is "linearly separable" - a simple line can separate the 0s from 1s.',
2513
+ element: '#taskOutput',
2514
+ position: 'top'
2515
+ },
2516
+ {
2517
+ title: 'Start Training',
2518
+ content: 'Click the Start Training button and watch the network learn! Notice how quickly it masters this simple pattern.',
2519
+ element: '#trainBtn',
2520
+ position: 'bottom',
2521
+ action: () => {
2522
+ if (!isTraining) {
2523
+ document.getElementById('trainBtn').click();
2524
+ }
2525
+ }
2526
+ },
2527
+ {
2528
+ title: 'XOR - The Challenge',
2529
+ content: 'Now let\'s try XOR - it outputs 1 when inputs are different. This is much harder because it\'s not linearly separable!',
2530
+ element: null,
2531
+ position: 'center',
2532
+ action: () => {
2533
+ if (isTraining) {
2534
+ document.getElementById('trainBtn').click();
2535
+ }
2536
+ goBack();
2537
+ selectTask('xor');
2538
+ }
2539
+ },
2540
+ {
2541
+ title: 'Deeper Network Needed',
2542
+ content: 'Notice the XOR network has more layers (2→12→8→1). The extra layers let it learn the complex pattern that XOR requires.',
2543
+ element: '#networkCanvas',
2544
+ position: 'right'
2545
+ }
2546
+ ]
2547
+ }
2548
+ };
2549
+
2550
+ function startWalkthrough(tutorialId) {
2551
+ walkthroughTutorial = walkthroughTutorials[tutorialId];
2552
+ walkthroughStep = 0;
2553
+ walkthroughActive = true;
2554
+
2555
+ // Show indicator
2556
+ document.getElementById('walkthroughIndicator').style.display = 'block';
2557
+
2558
+ // Navigate to appropriate section
2559
+ if (tutorialId === 'logic') {
2560
+ document.getElementById('walkthroughMode').style.display = 'none';
2561
+ taskSelection.style.display = 'block';
2562
+ currentCategory = 'fundamentals';
2563
+ showCategory('fundamentals');
2564
+ }
2565
+
2566
+ showWalkthroughStep();
2567
+ }
2568
+
2569
+ function showWalkthroughStep() {
2570
+ const step = walkthroughTutorial.steps[walkthroughStep];
2571
+ const overlay = document.getElementById('walkthroughOverlay');
2572
+ const highlight = document.getElementById('walkthroughHighlight');
2573
+ const popup = document.getElementById('walkthroughPopup');
2574
+ const progress = document.getElementById('walkthroughProgress');
2575
+
2576
+ // Update progress
2577
+ document.getElementById('walkthroughStep').textContent = walkthroughStep + 1;
2578
+ document.getElementById('walkthroughTotal').textContent = walkthroughTutorial.steps.length;
2579
+
2580
+ // Show overlay
2581
+ overlay.style.display = 'block';
2582
+ progress.style.display = 'block';
2583
+
2584
+ // Update popup content
2585
+ document.getElementById('walkthroughTitle').textContent = step.title;
2586
+ document.getElementById('walkthroughContent').textContent = step.content;
2587
+
2588
+ // Position popup and highlight
2589
+ if (step.element) {
2590
+ const element = document.querySelector(step.element);
2591
+ if (element) {
2592
+ const rect = element.getBoundingClientRect();
2593
+
2594
+ // Highlight element
2595
+ if (step.highlight) {
2596
+ const canvasRect = element.getBoundingClientRect();
2597
+ highlight.style.left = (canvasRect.left + step.highlight.x) + 'px';
2598
+ highlight.style.top = (canvasRect.top + step.highlight.y) + 'px';
2599
+ highlight.style.width = step.highlight.width + 'px';
2600
+ highlight.style.height = step.highlight.height + 'px';
2601
+ } else {
2602
+ highlight.style.left = rect.left - 5 + 'px';
2603
+ highlight.style.top = rect.top - 5 + 'px';
2604
+ highlight.style.width = rect.width + 10 + 'px';
2605
+ highlight.style.height = rect.height + 10 + 'px';
2606
+ }
2607
+ highlight.style.display = 'block';
2608
+
2609
+ // Position popup
2610
+ positionPopup(popup, rect, step.position);
2611
+ }
2612
+ } else {
2613
+ // Center popup
2614
+ highlight.style.display = 'none';
2615
+ popup.style.left = '50%';
2616
+ popup.style.top = '50%';
2617
+ popup.style.transform = 'translate(-50%, -50%)';
2618
+ popup.className = 'walkthrough-popup';
2619
+ }
2620
+
2621
+ popup.style.display = 'block';
2622
+
2623
+ // Execute action if any
2624
+ if (step.action) {
2625
+ setTimeout(step.action, 500);
2626
+ }
2627
+
2628
+ // Update buttons
2629
+ document.getElementById('walkthroughPrev').style.display =
2630
+ walkthroughStep > 0 ? 'block' : 'none';
2631
+ document.getElementById('walkthroughNext').textContent =
2632
+ walkthroughStep < walkthroughTutorial.steps.length - 1 ? 'Next' : 'Finish';
2633
+ }
2634
+
2635
+ function positionPopup(popup, targetRect, position) {
2636
+ const popupRect = popup.getBoundingClientRect();
2637
+ let left, top;
2638
+
2639
+ switch (position) {
2640
+ case 'top':
2641
+ left = targetRect.left + targetRect.width / 2 - popupRect.width / 2;
2642
+ top = targetRect.top - popupRect.height - 20;
2643
+ popup.className = 'walkthrough-popup bottom';
2644
+ break;
2645
+ case 'bottom':
2646
+ left = targetRect.left + targetRect.width / 2 - popupRect.width / 2;
2647
+ top = targetRect.bottom + 20;
2648
+ popup.className = 'walkthrough-popup top';
2649
+ break;
2650
+ case 'left':
2651
+ left = targetRect.left - popupRect.width - 20;
2652
+ top = targetRect.top + targetRect.height / 2 - popupRect.height / 2;
2653
+ popup.className = 'walkthrough-popup right';
2654
+ break;
2655
+ case 'right':
2656
+ left = targetRect.right + 20;
2657
+ top = targetRect.top + targetRect.height / 2 - popupRect.height / 2;
2658
+ popup.className = 'walkthrough-popup left';
2659
+ break;
2660
+ default:
2661
+ return;
2662
+ }
2663
+
2664
+ // Keep popup on screen
2665
+ left = Math.max(10, Math.min(left, window.innerWidth - popupRect.width - 10));
2666
+ top = Math.max(10, Math.min(top, window.innerHeight - popupRect.height - 10));
2667
+
2668
+ popup.style.left = left + 'px';
2669
+ popup.style.top = top + 'px';
2670
+ popup.style.transform = 'none';
2671
+ }
2672
+
2673
+ function nextWalkthroughStep() {
2674
+ if (walkthroughStep < walkthroughTutorial.steps.length - 1) {
2675
+ walkthroughStep++;
2676
+ showWalkthroughStep();
2677
+ } else {
2678
+ exitWalkthrough();
2679
+ }
2680
+ }
2681
+
2682
+ function prevWalkthroughStep() {
2683
+ if (walkthroughStep > 0) {
2684
+ walkthroughStep--;
2685
+ showWalkthroughStep();
2686
+ }
2687
+ }
2688
+
2689
+ function exitWalkthrough() {
2690
+ walkthroughActive = false;
2691
+ document.getElementById('walkthroughOverlay').style.display = 'none';
2692
+ document.getElementById('walkthroughHighlight').style.display = 'none';
2693
+ document.getElementById('walkthroughPopup').style.display = 'none';
2694
+ document.getElementById('walkthroughProgress').style.display = 'none';
2695
+ document.getElementById('walkthroughIndicator').style.display = 'none';
2696
+ }
2697
+
2698
+ // Walkthrough event listeners
2699
+ document.getElementById('walkthroughNext').addEventListener('click', nextWalkthroughStep);
2700
+ document.getElementById('walkthroughPrev').addEventListener('click', prevWalkthroughStep);
2701
+ document.getElementById('walkthroughSkip').addEventListener('click', exitWalkthrough);
2702
+
2703
+ // Override training speed when in walkthrough mode
2704
+ const originalTrainStep = trainStep;
2705
+ trainStep = function() {
2706
+ originalTrainStep();
2707
+
2708
+ if (walkthroughActive && isTraining) {
2709
+ clearInterval(trainInterval);
2710
+ trainInterval = setInterval(trainStep, walkthroughTrainingSpeed);
2711
+ }
2712
+ };
2713
+
2714
  // Initialize
2715
  startAnimation();
2716
  </script>