Bardo.Morphology (Bardo v0.1.0)

View Source

Morphology 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.

t()

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

actuator()

@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.

sensor()

@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.

substrate_cep()

@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.

substrate_cpp()

@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.

t()

@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_actuator(morphology, actuator)

@spec add_actuator(t(), actuator()) :: t()

Add an actuator to a morphology.

Parameters

  • morphology - The morphology to add the actuator to
  • actuator - 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_sensor(morphology, sensor)

@spec add_sensor(t(), sensor()) :: t()

Add a sensor to a morphology.

Parameters

  • morphology - The morphology to add the sensor to
  • sensor - 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(id)

@spec delete(binary()) :: :ok | {:error, term()}

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_actuators(morphology_module)

@spec get_actuators(t() | atom()) :: [actuator()]

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_init_actuators(morphology_module)

@spec get_init_actuators(t() | atom()) :: [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_init_sensors(morphology_module)

@spec get_init_sensors(t() | atom()) :: [sensor()]

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_init_substrate_ceps(map)

Get the initial substrate connection expression producers (CEPs) for a morphology.

Parameters

  • morphology - The morphology to get substrate CEPs for
  • plasticity - 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, ...}]

get_init_substrate_ceps(dimensions, plasticity)

@spec get_init_substrate_ceps(t() | integer(), atom() | nil) :: [substrate_cep()]

get_init_substrate_cpps(map)

Get the initial substrate connection pattern producers (CPPs) for a morphology.

Parameters

  • morphology - The morphology to get substrate CPPs for
  • plasticity - 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, ...}]

get_init_substrate_cpps(dimensions, plasticity)

@spec get_init_substrate_cpps(t() | integer(), atom() | nil) :: [substrate_cpp()]

get_phys_config(morphology, cortex_id, scape_name)

@spec get_phys_config(t() | atom(), binary(), atom()) :: map()

Create a physical configuration for an agent.

Parameters

  • morphology - The morphology to create a physical configuration for
  • cortex_id - The ID of the cortex
  • scape_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_scape_params(morphology, agent_id, cortex_id, scape_name)

@spec get_scape_params(t() | atom(), binary(), binary(), atom()) :: map()

Get the parameters required for an agent to enter a scape.

Parameters

  • morphology - The morphology to get scape parameters for
  • agent_id - The ID of the agent
  • cortex_id - The ID of the cortex
  • scape_name - The name of the scape

Returns

  • A map with scape parameters

get_sensors(morphology_module)

@spec get_sensors(t() | atom()) :: [sensor()]

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_substrate_ceps(map)

Get all available substrate connection expression producers (CEPs) for a morphology.

Parameters

  • morphology - The morphology to get substrate CEPs for
  • plasticity - 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, ...}, ...]

get_substrate_ceps(dimensions, plasticity)

@spec get_substrate_ceps(t() | integer(), atom() | nil) :: [substrate_cep()]

get_substrate_cpps(map)

Get all available substrate connection pattern producers (CPPs) for a morphology.

Parameters

  • morphology - The morphology to get substrate CPPs for
  • plasticity - 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, ...}, ...]

get_substrate_cpps(dimensions, plasticity)

@spec get_substrate_cpps(t() | integer(), atom() | nil) :: [substrate_cpp()]

list()

@spec list() :: {:ok, [t()]} | {:error, term()}

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(id)

@spec load(binary()) :: {:ok, t()} | {:error, term()}

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", ...}}

neuron_count(morphology)

@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

neuron_pattern(morphology, agent_id, cortex_id, neural_interface)

@spec neuron_pattern(t() | atom(), binary(), binary(), map()) :: map()

Define the neuron pattern for a neural network.

Parameters

  • morphology - The morphology to define the neuron pattern for
  • agent_id - The ID of the agent
  • cortex_id - The ID of the cortex
  • neural_interface - A map with sensors and actuators data

Returns

  • A map defining the neuron pattern

new(opts \\ %{})

@spec new(map()) :: t()

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(morphology)

@spec save(t()) :: :ok | {:error, term()}

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