AIKA Tutorial: Learn by Example

📚 Prerequisites: Make sure you've completed the Installation Guide before starting.

This tutorial demonstrates AIKA's Python API through three progressive examples. Each example builds on concepts from the previous one.

Example 1: Basic Field Operations

This example shows how to define types, create relations, and perform field computations using AIKA's event-driven system.

import aika
import aika.fields as af

# Define bidirectional relations between types
TEST_RELATION_FROM = af.RelationOne(1, "TEST_FROM")
TEST_RELATION_TO = af.RelationOne(2, "TEST_TO")
TEST_RELATION_TO.setReversed(TEST_RELATION_FROM)
TEST_RELATION_FROM.setReversed(TEST_RELATION_TO)

# Create type registry and define types
registry = af.TypeRegistry()
typeA = af.TestType(registry, "A")
typeB = af.TestType(registry, "B")

# Define input fields
a = typeA.inputField("a")
b = typeA.inputField("b")

# Define computed field (c = a - b)
c = typeB.sub("c")
c.input(TEST_RELATION_FROM, a, 0)  # First input from field 'a'
c.input(TEST_RELATION_FROM, b, 1)  # Second input from field 'b'

# Finalize type definitions
registry.flattenTypeHierarchy()

# Instantiate objects
oa = typeA.instantiate()
ob = typeB.instantiate()

# Link objects and initialize computed fields
af.TestObj.linkObjects(oa, ob)
ob.initFields()

# Set input values
oa.setFieldValue(a, 50.0)
oa.setFieldValue(b, 20.0)

# Read computed result
result = ob.getFieldValue(c)  # Returns 30.0 (50 - 20)
print(f"Result: {result}")

Example 2: Network Construction

This example demonstrates building neural networks using AIKA's builder pattern.

import aika.network as an
from python.networks.standard_network import create_standard_network_types

# Create standard network types
network = create_standard_network_types()
registry = network.get_registry()
model = an.Model(registry)

# Instantiate neurons using the type system
input_neuron = network.T_STANDARD_NEURON.instantiate(model)
output_neuron = network.T_STANDARD_NEURON.instantiate(model)

# Create synapses to connect neurons
synapse = network.T_STANDARD_SYNAPSE.instantiate(
    input_neuron,
    output_neuron
)

print(f"Created network with {model.getNumNeurons()} neurons")

Example 3: Transformer Types (Experimental)

AIKA includes experimental transformer architecture types. Note: The attention mechanism is currently under development.

from python.networks.transformer import create_transformer_types

# Create transformer type hierarchy
transformer = create_transformer_types()

# Access transformer neuron types
emb_type = transformer.T_EMB        # Embedding neurons
key_type = transformer.T_KEY        # Key neurons (Q in attention)
query_type = transformer.T_QUERY    # Query neurons (K in attention)
value_type = transformer.T_VALUE    # Value neurons (V in attention)
attention_type = transformer.T_SOFTMAX  # Attention/Softmax neurons

print(f"Transformer types: {len(transformer.get_all_types())} types defined")

⚠️ Current Status: Type hierarchy is complete, but the attention mechanism requires corrected softmax normalization and latent linking implementation.

Available Operations

The Fields Module provides these operations for field definitions:

All operations support the event-driven propagation model, where field updates automatically trigger recomputation of dependent fields.

Understanding Event-Driven Processing

Unlike conventional neural networks that process data in fixed layers, AIKA processes activations asynchronously using an event queue with lexicographic ordering: (round, phase, -priority, timestamp).

This enables dynamic behavior where neurons and synapses activate based on event triggers rather than precomputed sequences. Changes propagate through the network automatically, making computation sparse and efficient.

Key Concepts

What You've Learned

Next Steps

Ready to dive deeper?

Why AIKA? →    Documentation

Learn what makes AIKA different from traditional frameworks, or explore the full documentation and formal specifications.