Bardo.Morphology (Bardo v0.1.0)
View SourceMorphology module for the Bardo neuroevolution system.
The Morphology module defines the structure and properties of neural networks in the Bardo system. It provides functions for creating, modifying, and querying neural network morphologies, including:
- Sensors: Input mechanisms for receiving data from the environment
- Actuators: Output mechanisms for interacting with the environment
- Substrates: Spatial arrangements of neurons in n-dimensional space
- Connections: Patterns and rules for connecting neurons
This module serves as the foundation for defining the physical structure of neural networks, which combined with learning rules and evolutionary algorithms, enables the creation of complex, adaptive systems.
Summary
Types
Type definition for an actuator specification.
Type definition for a sensor specification.
Type definition for a substrate connection expression producer.
Type definition for a substrate connection pattern producer.
Type definition for a neural network morphology.
Functions
Add an actuator to a morphology.
Add a sensor to a morphology.
Delete a morphology from the database.
Get all available actuators for a morphology.
Get the initial actuators for a morphology.
Get the initial sensors for a morphology.
Get the initial substrate connection expression producers (CEPs) for a morphology.
Get the initial substrate connection pattern producers (CPPs) for a morphology.
Create a physical configuration for an agent.
Get the parameters required for an agent to enter a scape.
Get all available sensors for a morphology.
Get all available substrate connection expression producers (CEPs) for a morphology.
Get all available substrate connection pattern producers (CPPs) for a morphology.
List all morphologies in the database.
Load a morphology from the database.
Get the total number of neurons in a morphology.
Define the neuron pattern for a neural network.
Create a new morphology with the given options.
Save a morphology to the database.
Types
@type actuator() :: %{ id: binary() | nil, name: atom(), type: atom(), cx_id: binary() | nil, scape: atom() | nil, vl: non_neg_integer(), fanin_ids: [binary()], generation: non_neg_integer() | nil, format: atom() | nil, parameters: map() | nil }
Type definition for an actuator specification.
@type sensor() :: %{ id: binary() | nil, name: atom(), type: atom(), cx_id: binary() | nil, scape: atom() | nil, vl: non_neg_integer(), fanout_ids: [binary()], generation: non_neg_integer() | nil, format: atom() | nil, parameters: map() | nil }
Type definition for a sensor specification.
@type substrate_cep() :: %{ id: binary() | nil, name: atom(), type: atom(), cx_id: binary() | nil, scape: atom() | nil, vl: non_neg_integer(), fanin_ids: [binary()], generation: non_neg_integer() | nil, format: atom() | nil, parameters: map() | nil }
Type definition for a substrate connection expression producer.
@type substrate_cpp() :: %{ id: binary() | nil, name: atom(), type: atom(), cx_id: binary() | nil, scape: atom() | nil, vl: non_neg_integer(), fanout_ids: [binary()], generation: non_neg_integer() | nil, format: atom() | nil, parameters: map() | nil }
Type definition for a substrate connection pattern producer.
@type t() :: %{ id: binary(), name: binary(), description: binary(), dimensions: non_neg_integer(), inputs: non_neg_integer(), outputs: non_neg_integer(), hidden_layers: [non_neg_integer()], activation_functions: [atom()], substrate_type: :cartesian | :hypercube | :hypersphere | :custom, connection_pattern: :feedforward | :recurrent | :dense | :custom, plasticity: :none | :hebbian | :stdp | :abcn | :iterative, sensors: [sensor()], actuators: [actuator()], substrate_cpps: [substrate_cpp()], substrate_ceps: [substrate_cep()], parameters: map() }
Type definition for a neural network morphology.
Functions
Add an actuator to a morphology.
Parameters
morphology
- The morphology to add the actuator toactuator
- The actuator to add
Returns
- An updated morphology with the new actuator
Examples
iex> actuator = Models.actuator(%{name: :motor, type: :movement, vl: 2})
iex> morphology = Bardo.Morphology.new()
iex> Bardo.Morphology.add_actuator(morphology, actuator)
%{id: "morph_xxxxxxxxxxx", actuators: [%{name: :motor, type: :movement, vl: 2}, ...], ...}
Add a sensor to a morphology.
Parameters
morphology
- The morphology to add the sensor tosensor
- The sensor to add
Returns
- An updated morphology with the new sensor
Examples
iex> sensor = Models.sensor(%{name: :eye, type: :vision, vl: 100})
iex> morphology = Bardo.Morphology.new()
iex> Bardo.Morphology.add_sensor(morphology, sensor)
%{id: "morph_xxxxxxxxxxx", sensors: [%{name: :eye, type: :vision, vl: 100}, ...], ...}
Delete a morphology from the database.
Parameters
id
- The ID of the morphology to delete
Returns
:ok
on success{:error, reason}
on failure
Examples
iex> Bardo.Morphology.delete("morph_123456789")
:ok
Get all available actuators for a morphology.
Parameters
morphology
- The morphology to get actuators for
Returns
- A list of all actuators
Examples
iex> morphology = Bardo.Morphology.new()
iex> Bardo.Morphology.get_actuators(morphology)
[%{name: :default_actuator, ...}]
Get the initial actuators for a morphology.
Parameters
morphology
- The morphology to get actuators for
Returns
- A list of actuators
Examples
iex> morphology = Bardo.Morphology.new()
iex> Bardo.Morphology.get_init_actuators(morphology)
[%{name: :default_actuator, ...}]
Get the initial sensors for a morphology.
Parameters
morphology
- The morphology to get sensors for
Returns
- A list of sensors
Examples
iex> morphology = Bardo.Morphology.new()
iex> Bardo.Morphology.get_init_sensors(morphology)
[%{name: :default_sensor, ...}]
Get the initial substrate connection expression producers (CEPs) for a morphology.
Parameters
morphology
- The morphology to get substrate CEPs forplasticity
- Optional plasticity type (overrides the morphology's plasticity)
Returns
- A list of substrate CEPs
Examples
iex> morphology = Bardo.Morphology.new(%{plasticity: :hebbian})
iex> Bardo.Morphology.get_init_substrate_ceps(morphology)
[%{name: :delta_weight, ...}]
@spec get_init_substrate_ceps(t() | integer(), atom() | nil) :: [substrate_cep()]
Get the initial substrate connection pattern producers (CPPs) for a morphology.
Parameters
morphology
- The morphology to get substrate CPPs forplasticity
- Optional plasticity type (overrides the morphology's plasticity)
Returns
- A list of substrate CPPs
Examples
iex> morphology = Bardo.Morphology.new(%{plasticity: :hebbian})
iex> Bardo.Morphology.get_init_substrate_cpps(morphology)
[%{name: :cartesian, ...}]
@spec get_init_substrate_cpps(t() | integer(), atom() | nil) :: [substrate_cpp()]
Create a physical configuration for an agent.
Parameters
morphology
- The morphology to create a physical configuration forcortex_id
- The ID of the cortexscape_name
- The name of the scape
Returns
- A map with :sensors and :actuators keys
Examples
iex> morphology = Bardo.Morphology.new()
iex> Bardo.Morphology.get_phys_config(morphology, "cx_123", :test_scape)
%{sensors: [...], actuators: [...]}
Get the parameters required for an agent to enter a scape.
Parameters
morphology
- The morphology to get scape parameters foragent_id
- The ID of the agentcortex_id
- The ID of the cortexscape_name
- The name of the scape
Returns
- A map with scape parameters
Get all available sensors for a morphology.
Parameters
morphology
- The morphology to get sensors for
Returns
- A list of all sensors
Examples
iex> morphology = Bardo.Morphology.new()
iex> Bardo.Morphology.get_sensors(morphology)
[%{name: :default_sensor, ...}]
Get all available substrate connection expression producers (CEPs) for a morphology.
Parameters
morphology
- The morphology to get substrate CEPs forplasticity
- Optional plasticity type (overrides the morphology's plasticity)
Returns
- A list of all substrate CEPs
Examples
iex> morphology = Bardo.Morphology.new(%{plasticity: :hebbian})
iex> Bardo.Morphology.get_substrate_ceps(morphology)
[%{name: :delta_weight, ...}, %{name: :set_abcn, ...}, ...]
@spec get_substrate_ceps(t() | integer(), atom() | nil) :: [substrate_cep()]
Get all available substrate connection pattern producers (CPPs) for a morphology.
Parameters
morphology
- The morphology to get substrate CPPs forplasticity
- Optional plasticity type (overrides the morphology's plasticity)
Returns
- A list of all substrate CPPs
Examples
iex> morphology = Bardo.Morphology.new(%{plasticity: :hebbian})
iex> Bardo.Morphology.get_substrate_cpps(morphology)
[%{name: :cartesian, ...}, %{name: :centripital_distances, ...}, ...]
@spec get_substrate_cpps(t() | integer(), atom() | nil) :: [substrate_cpp()]
List all morphologies in the database.
Returns
{:ok, [morphology]}
on success{:error, reason}
on failure
Examples
iex> Bardo.Morphology.list()
{:ok, [%{id: "morph_123456789", name: "Simple XOR", ...}, ...]}
Load a morphology from the database.
Parameters
id
- The ID of the morphology to load
Returns
{:ok, morphology}
on success{:error, reason}
on failure
Examples
iex> Bardo.Morphology.load("morph_123456789")
{:ok, %{id: "morph_123456789", name: "Simple XOR", ...}}
@spec neuron_count(t()) :: non_neg_integer()
Get the total number of neurons in a morphology.
Parameters
morphology
- The morphology to get the neuron count for
Returns
- The total number of neurons
Examples
iex> morphology = Bardo.Morphology.new(%{inputs: 2, hidden_layers: [3], outputs: 1})
iex> Bardo.Morphology.neuron_count(morphology)
6
Define the neuron pattern for a neural network.
Parameters
morphology
- The morphology to define the neuron pattern foragent_id
- The ID of the agentcortex_id
- The ID of the cortexneural_interface
- A map with sensors and actuators data
Returns
- A map defining the neuron pattern
Create a new morphology with the given options.
Parameters
opts
- A map of options for the morphology
Returns
- A new morphology struct
Examples
iex> Bardo.Morphology.new(%{name: "Simple XOR", dimensions: 2, inputs: 2, outputs: 1})
%{id: "morph_xxxxxxxxxxx", name: "Simple XOR", dimensions: 2, inputs: 2, outputs: 1, ...}
Save a morphology to the database.
Parameters
morphology
- The morphology to save
Returns
:ok
on success{:error, reason}
on failure
Examples
iex> morphology = Bardo.Morphology.new(%{name: "Simple XOR"})
iex> Bardo.Morphology.save(morphology)
:ok