pub struct AutoNCP { /* private fields */ }Expand description
Automatic NCP configuration with simplified parameters.
AutoNCP is the recommended way to create NCP wirings. It automatically
calculates layer sizes and connectivity based on just a few high-level parameters.
§Simplified Interface
Instead of specifying 7 parameters like NCP, you only need 4:
| Parameter | Description |
|---|---|
units | Total number of neurons (hidden state size) |
output_size | Number of motor neurons (output dimension) |
sparsity_level | Fraction of connections to remove (0.0 - 0.9) |
seed | Random seed for reproducibility |
§How Auto-Configuration Works
Given your parameters, AutoNCP:
- Allocates neurons:
units - output_sizesplit 60/40 between inter/command - Sets connectivity: Based on
density = 1.0 - sparsity_levelsensory_fanout = inter_neurons × densityinter_fanout = command_neurons × densitymotor_fanin = command_neurons × densityrecurrent_command_synapses = command_neurons × density × 2
§Example
use ncps::wirings::{AutoNCP, Wiring};
// Create with automatic configuration
let mut wiring = AutoNCP::new(
32, // units: total neurons
8, // output_size: motor neurons
0.5, // sparsity_level: 50% connections removed
42, // seed
);
wiring.build(16); // 16 input features
// Check auto-calculated structure
assert_eq!(wiring.units(), 32);
assert_eq!(wiring.output_dim(), Some(8));
assert_eq!(wiring.num_layers(), 3); // inter, command, motor§Sparsity Level Guide
| Sparsity | Effect | Use Case |
|---|---|---|
| 0.0 | Dense connections | Maximum expressiveness |
| 0.3-0.5 | Moderate sparsity | Recommended starting point |
| 0.7-0.9 | Very sparse | Edge deployment, interpretability |
§Constraints
output_size < units - 2(need at least 2 neurons for inter + command)sparsity_levelmust be in[0.0, 0.9]
§Panics
ⓘ
use ncps::wirings::AutoNCP;
// Panics: output_size too large
let wiring = AutoNCP::new(10, 9, 0.5, 42);ⓘ
use ncps::wirings::AutoNCP;
// Panics: sparsity_level out of range
let wiring = AutoNCP::new(32, 8, 0.95, 42);Implementations§
Trait Implementations§
Source§impl Wiring for AutoNCP
impl Wiring for AutoNCP
Source§fn units(&self) -> usize
fn units(&self) -> usize
Returns the total number of neurons (hidden units) in this wiring. Read more
Source§fn input_dim(&self) -> Option<usize>
fn input_dim(&self) -> Option<usize>
Returns the input dimension (number of input features), or
None if not yet built. Read moreSource§fn output_dim(&self) -> Option<usize>
fn output_dim(&self) -> Option<usize>
Returns the output dimension (number of motor neurons). Read more
Source§fn num_layers(&self) -> usize
fn num_layers(&self) -> usize
Returns the number of logical layers in this wiring. Read more
Source§fn get_neurons_of_layer(&self, layer_id: usize) -> Vec<usize>
fn get_neurons_of_layer(&self, layer_id: usize) -> Vec<usize>
Returns the neuron IDs belonging to a specific layer. Read more
Source§fn get_type_of_neuron(&self, neuron_id: usize) -> &'static str
fn get_type_of_neuron(&self, neuron_id: usize) -> &'static str
Returns the type of a neuron by its ID. Read more
Source§fn build(&mut self, input_dim: usize)
fn build(&mut self, input_dim: usize)
Builds the wiring by setting the input dimension and creating sensory connections. Read more
Source§fn is_built(&self) -> bool
fn is_built(&self) -> bool
Returns
true if the wiring has been built (input dimension is set). Read moreSource§fn adjacency_matrix(&self) -> &Array2<i32>
fn adjacency_matrix(&self) -> &Array2<i32>
Returns the internal adjacency matrix representing neuron-to-neuron synapses. Read more
Source§fn sensory_adjacency_matrix(&self) -> Option<&Array2<i32>>
fn sensory_adjacency_matrix(&self) -> Option<&Array2<i32>>
Returns the sensory adjacency matrix (input-to-neuron connections). Read more
Source§fn add_synapse(&mut self, src: usize, dest: usize, polarity: i32)
fn add_synapse(&mut self, src: usize, dest: usize, polarity: i32)
Adds or modifies an internal synapse between two neurons. Read more
Source§fn add_sensory_synapse(&mut self, src: usize, dest: usize, polarity: i32)
fn add_sensory_synapse(&mut self, src: usize, dest: usize, polarity: i32)
Adds or modifies a sensory synapse from an input feature to a neuron. Read more
Source§fn get_config(&self) -> WiringConfig
fn get_config(&self) -> WiringConfig
Creates a serializable configuration for this wiring. Read more
Source§fn erev_initializer(&self) -> Array2<i32>
fn erev_initializer(&self) -> Array2<i32>
Returns the reversal potential initializer (same as adjacency matrix). Read more
Source§fn sensory_erev_initializer(&self) -> Option<Array2<i32>>
fn sensory_erev_initializer(&self) -> Option<Array2<i32>>
Returns the sensory reversal potential initializer. Read more
Source§fn synapse_count(&self) -> usize
fn synapse_count(&self) -> usize
Returns the total number of internal synapses (non-zero entries in adjacency matrix). Read more
Source§fn sensory_synapse_count(&self) -> usize
fn sensory_synapse_count(&self) -> usize
Returns the total number of sensory synapses (input-to-neuron connections). Read more
Source§fn input_required(&self) -> bool
fn input_required(&self) -> bool
Returns
true if this wiring requires external input (has sensory connections). Read moreAuto Trait Implementations§
impl Freeze for AutoNCP
impl RefUnwindSafe for AutoNCP
impl Send for AutoNCP
impl Sync for AutoNCP
impl Unpin for AutoNCP
impl UnwindSafe for AutoNCP
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more