brain (macula_tweann v0.18.1)
View SourceBrain process for real-time neural network inference.
A brain is a running neural network that accepts sensor inputs and produces actuator outputs. Unlike the process-per-neuron architecture used during training, this is a single GenServer optimized for real-time inference in applications like games and robotics.
Features
- Synchronous evaluation via evaluate/2 - Internal state persistence for LTC neurons - Visualization data for UI rendering - PubSub notifications for state changes
Usage
Start a brain with a network: Network = network_evaluator:create_feedforward(42, [16, 8], 6), {ok, Pid} = brain:start_link(#{network => Network})
Evaluate with sensor inputs: Outputs = brain:evaluate(Pid, Inputs)
Get visualization data: VizData = brain:get_viz(Pid)
Subscribe to viz updates (Erlang): brain:subscribe(Pid) receive {brain_viz, Pid, VizData} -> ... end
Summary
Functions
Evaluate the brain with sensor inputs.
Evaluate and return both outputs and all layer activations.
Get the current network.
Get network topology information.
Get current visualization data.
Replace the network (e.g., after mutation).
Start a brain process.
Start a named brain process.
Stop the brain process.
Subscribe to visualization updates.
Subscribe a specific process to visualization updates.
Unsubscribe from visualization updates.
Unsubscribe a specific process from visualization updates.
Functions
Evaluate the brain with sensor inputs.
Returns the output values from the neural network. Also updates internal state and notifies subscribers.
Evaluate and return both outputs and all layer activations.
This is used by the learning system to record experiences. Returns {Outputs, Activations} where Activations includes all layers.
-spec get_network(pid()) -> network_evaluator:network().
Get the current network.
Get network topology information.
Get current visualization data.
Returns a map with nodes, connections, and activation levels.
-spec set_network(pid(), network_evaluator:network()) -> ok.
Replace the network (e.g., after mutation).
Start a brain process.
Options: - network - The neural network (required, from network_evaluator) - id - Optional identifier for this brain - input_labels - Labels for input neurons (for visualization) - viz_enabled - Enable visualization data (default: true)
Start a named brain process.
-spec stop(pid()) -> ok.
Stop the brain process.
-spec subscribe(pid()) -> ok.
Subscribe to visualization updates.
The calling process will receive {brain_viz, Pid, VizData} messages after each evaluation.
Subscribe a specific process to visualization updates.
-spec unsubscribe(pid()) -> ok.
Unsubscribe from visualization updates.
Unsubscribe a specific process from visualization updates.