Geometric Algebra Neural Network Concept Demonstrator

Geometric Algebra Neural Network Concept Demonstrator

Calculate Geometric Product of 2D Vectors

Enter components for two 2D vectors, e.g., Vector 1 as a neuron input and Vector 2 as a weight vector.

What is Geometric Algebra (GA)?

Geometric Algebra (also known as Clifford Algebra) is a mathematical framework that unifies real numbers, complex numbers, quaternions, and vector algebra into a single, cohesive system. It allows for a more intuitive and powerful way to handle geometric transformations and relationships.

In GA, vectors are combined using a "geometric product" which results in a multivector containing different "grades" of components:

  • **Scalars (Grade 0):** Just a number, like a length or magnitude.
  • **Vectors (Grade 1):** Directed lines, like $x$-axis or $y$-axis basis vectors.
  • **Bivectors (Grade 2):** Oriented planes, like the $xy$-plane.
  • ...and so on for higher dimensions.

The Geometric Product:

For two vectors $u$ and $v$, their geometric product $uv$ can be decomposed into two parts:
$$uv = u \cdot v + u \wedge v$$

  • The **inner product** ($u \cdot v$) is the scalar part, representing the projection or "overlap" between vectors. It's the same as the standard dot product.
  • The **outer product** ($u \wedge v$) is the bivector part, representing the oriented area or plane spanned by the vectors.

Conceptual Link to Neural Networks:

Traditional neural networks often use the dot product ($u \cdot v$) to compute the "activation" of a neuron, where $u$ might be an input vector and $v$ a weight vector.
In Geometric Algebra, this dot product is simply the **scalar part** of the geometric product.


This tool demonstrates how GA inherently calculates both the scalar (dot product equivalent) and outer (geometric interpretation) parts of vector interaction in 2D. While highly simplified, it shows how GA provides a richer mathematical language that might be useful for developing new types of neural network architectures with built-in geometric understanding.

**Disclaimer:** This tool is a **conceptual demonstrator** for educational purposes only. It illustrates basic Geometric Algebra operations in 2D and how a small part of it conceptually relates to a neuron's activation. It does **NOT** implement a functional neural network, nor does it perform complex "conversion" of neural networks to geometric algebra. Geometric Algebra Neural Networks (GANNs) are an active area of research, far more complex than this simple demonstration. Do not use this tool for research, complex simulations, or any real-world AI development.

The bivector part (${bivectorMagnitude.toFixed(4)} $e_{12}$) represents the oriented area spanned by the two vectors.

`; outputSectionEl.style.display = 'block'; outputData = { method: 'Geometric Product (2D)', inputs: { 'Vector 1 (u)': `(${u_x}, ${u_y})`, 'Vector 2 (v)': `(${v_x}, ${v_y})` }, results: { 'Scalar Part (u.v)': scalarPart.toFixed(4), 'Bivector Part (u^v)': `${bivectorMagnitude.toFixed(4)} e12` } }; console.log('[DEBUG] Geometric product calculation successful.'); } } catch (e) { console.error('[ERROR] Error in calculateGeometricProduct:', e); displayError('An error occurred during calculation. Check console for details.'); } } // --- Reset Function --- function resetForm() { console.log('[DEBUG] resetForm called.'); try { hideError(); hideOutput(); document.getElementById('u_x').value = '1'; document.getElementById('u_y').value = '0'; document.getElementById('v_x').value = '0'; document.getElementById('v_y').value = '1'; console.log('[DEBUG] Form reset successful.'); } catch (e) { console.error('[ERROR] Error in resetForm:', e); displayError('An error occurred during form reset. Check console for details.'); } } // --- PDF Generation --- async function generatePdf() { console.log('[DEBUG] generatePdf called.'); try { if (Object.keys(outputData).length === 0) { displayError("No calculation results to download. Please perform a calculation first."); return; } hideError(); const { jsPDF } = window.jspdf; const doc = new jsPDF(); const title = "Geometric Algebra Neural Network Concept Results"; const currentDateTime = new Date().toLocaleString(); doc.setFontSize(18); doc.text(title, 105, 20, { align: 'center' }); doc.setFontSize(10); doc.text(`Date: ${currentDateTime}`, 105, 28, { align: 'center' }); let yOffset = 40; doc.setFontSize(11); doc.text('Input Vectors:', 20, yOffset); yOffset += 7; const inputRows = Object.entries(outputData.inputs).map(([label, value]) => [label, value]); doc.autoTable({ startY: yOffset, head: [['Parameter', 'Value']], body: inputRows, theme: 'striped', styles: { fontSize: 10, cellPadding: 2, fillColor: [233, 247, 239], textColor: [51, 51, 51] }, headStyles: { fillColor: [40, 167, 69], textColor: [255, 255, 255], fontStyle: 'bold' }, columnStyles: { 0: { cellWidth: 70 }, 1: { cellWidth: 'auto' } } }); yOffset = doc.autoTable.previous.finalY + 10; doc.setFontSize(11); doc.text('Calculated Geometric Product:', 20, yOffset); yOffset += 7; const resultRows = Object.entries(outputData.results).map(([label, value]) => [label, value]); doc.autoTable({ startY: yOffset, head: [['Component', 'Value']], body: resultRows, theme: 'striped', styles: { fontSize: 10, cellPadding: 2, fillColor: [233, 247, 239], textColor: [51, 51, 51] }, headStyles: { fillColor: [40, 167, 69], textColor: [255, 255, 255], fontStyle: 'bold' }, columnStyles: { 0: { cellWidth: 70 }, 1: { cellWidth: 'auto' } } }); yOffset = doc.autoTable.previous.finalY + 15; // Add explanatory text to PDF const explanation = [ "The scalar part represents the traditional dot product, which is analogous to a neuron's activation input.", "The bivector part represents the oriented area spanned by the two vectors, providing geometric insight into their relationship." ]; doc.setFontSize(10); doc.text(doc.splitTextToSize(explanation.join('\n\n'), 170), 20, yOffset); yOffset += doc.getTextDimensions(explanation.join('\n\n')).h + 15; // Add Disclaimer const disclaimerText = "Disclaimer: This tool is a conceptual demonstrator for educational purposes only. It illustrates basic Geometric Algebra operations in 2D and how a small part of it conceptually relates to a neuron's activation. It does NOT implement a functional neural network, nor does it perform complex 'conversion' of neural networks to geometric algebra. Geometric Algebra Neural Networks (GANNs) are an active area of research, far more complex than this simple demonstration. Do not use this tool for research, complex simulations, or any real-world AI development."; const splitDisclaimer = doc.splitTextToSize(disclaimerText, 170); doc.setFontSize(9); doc.setTextColor(108, 117, 125); doc.text(splitDisclaimer, 20, yOffset); doc.save('GA_NN_Concept_Demonstrator.pdf'); console.log('[DEBUG] PDF generated successfully.'); } catch (e) { console.error('[ERROR] Error in generatePdf:', e); displayError('An error occurred during PDF generation. Check console for details.'); } } // --- Initialization --- document.addEventListener('DOMContentLoaded', function() { console.log('[DEBUG] DOMContentLoaded fired.'); try { document.querySelectorAll('.tabs-container .tab-button').forEach(button => { tabButtons.push(button); }); console.log(`[DEBUG] tabButtons array populated with ${tabButtons.length} buttons.`); const initialActiveButton = document.querySelector('.tab-button.active'); if (initialActiveButton) { switchTab('calculatorTab', initialActiveButton); } else { console.warn('[DEBUG] No initial active tab button found, falling back.'); switchTab('calculatorTab', null); } resetForm(); // Set initial example values console.log('[DEBUG] Default values pre-filled.'); console.log('[DEBUG] DOMContentLoaded finished.'); } catch (e) { console.error('[ERROR] Error during DOMContentLoaded:', e); const appContainer = document.getElementById('toolApp'); if (appContainer) { appContainer.innerHTML = '
An critical error occurred during tool initialization. Please check your browser console for details.
'; } } });
Scroll to Top