Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ // Initialize configuration object
+ let config = {
+ inputDim: 1,
+ hiddenDim: 32,
+ outputDim: 1,
+ weightFunction: 'linear',
+ activation: 'relu',
+ learningRate: 0.001,
+ epochs: 100
+ };
+
+ // Get DOM elements
+ const applyButton = document.getElementById('apply-config');
+ const configSummary = document.getElementById('config-summary');
+ const networkPreview = document.getElementById('network-preview');
+
+ // Update configuration when inputs change
+ document.querySelectorAll('input, select').forEach(input => {
+ input.addEventListener('change', (e) => {
+ const id = e.target.id;
+ let value = e.target.value;
+
+ // Convert number inputs to floats/integers
+ if (e.target.type === 'number') {
+ value = e.target.step === '1' ? parseInt(value) : parseFloat(value);
+ }
+
+ // Update config object
+ config[toCamelCase(id)] = value;
+
+ // Show visual feedback
+ input.classList.add('changed');
+ setTimeout(() => input.classList.remove('changed'), 500);
+ });
+ });
+
+ // Apply configuration button click handler
+ applyButton.addEventListener('click', () => {
+ updateConfigurationDisplay();
+ visualizeNetwork();
+
+ // Animation feedback
+ applyButton.classList.add('clicked');
+ setTimeout(() => applyButton.classList.remove('clicked'), 200);
+ });
+
+ // Helper function to convert kebab-case to camelCase
+ function toCamelCase(str) {
+ return str.replace(/-([a-z])/g, g => g[1].toUpperCase());
+ }
+
+ // Update configuration display
+ function updateConfigurationDisplay() {
+ configSummary.innerHTML = `
+
Current Configuration:
+
${JSON.stringify(config, null, 2)}
+ `;
+ }
+
+ // Simple network visualization
+ function visualizeNetwork() {
+ const canvas = document.createElement('canvas');
+ canvas.width = networkPreview.offsetWidth;
+ canvas.height = networkPreview.offsetHeight;
+
+ networkPreview.innerHTML = '';
+ networkPreview.appendChild(canvas);
+
+ const ctx = canvas.getContext('2d');
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ // Draw simple network representation
+ drawNetwork(ctx, config);
+ }
+
+ function drawNetwork(ctx, config) {
+ const layers = [config.inputDim, config.hiddenDim, config.outputDim];
+ const maxNodes = Math.max(...layers);
+ const width = ctx.canvas.width;
+ const height = ctx.canvas.height;
+ const padding = 40;
+ const layerSpacing = (width - 2 * padding) / (layers.length - 1);
+ const nodeRadius = 5;
+
+ ctx.strokeStyle = '#3498db';
+ ctx.fillStyle = '#2c3e50';
+
+ // Draw nodes and connections
+ layers.forEach((nodeCount, layerIndex) => {
+ const x = padding + layerIndex * layerSpacing;
+ const nodeSpacing = (height - 2 * padding) / (nodeCount - 1);
+
+ for (let i = 0; i < nodeCount; i++) {
+ const y = padding + i * nodeSpacing;
+
+ // Draw node
+ ctx.beginPath();
+ ctx.arc(x, y, nodeRadius, 0, Math.PI * 2);
+ ctx.fill();
+
+ // Draw connections to next layer
+ if (layerIndex < layers.length - 1) {
+ const nextLayerNodes = layers[layerIndex + 1];
+ const nextX = padding + (layerIndex + 1) * layerSpacing;
+ const nextNodeSpacing = (height - 2 * padding) / (nextLayerNodes - 1);
+
+ for (let j = 0; j < nextLayerNodes; j++) {
+ const nextY = padding + j * nextNodeSpacing;
+ ctx.beginPath();
+ ctx.moveTo(x, y);
+ ctx.lineTo(nextX, nextY);
+ ctx.stroke();
+ }
+ }
+ }
+ });
+ }
+
+ // Initial visualization
+ updateConfigurationDisplay();
+ visualizeNetwork();
+ });