NetVecor¶
NetVector – Interpreter for flat Vectors as feedforward neural networks.
This module provides a lightweight helper class that interprets a flat Vector (e.g. created via dim_type=’net’) as a fully connected feedforward network with arbitrary layer structure and activation function.
NetVector does not contain any trainable parameters or evolutionary logic itself. Instead, it unpacks and applies a flat vector (weights + biases) to input data.
- Typical use case:
Use Vector as evolvable parameter container (mutation, crossover etc.)
Use NetVector to define the network structure and perform forward evaluations
Example
para = Vector(…) # created via normal_initializer_net net = NetVector(dim=[1, 8, 1], activation=”tanh”) y = net.forward(x, para.vector)
- class evolib.representation.netvector.NetVector(dim, activation='tanh')[source]¶
Bases:
object- forward(x, vector)[source]¶
Evaluates the network on input x using the flat parameter vector.
Activation is applied after all but the last layer.
- Parameters:
x (
ndarray) – Input vector (shape: [input_dim] or [batch, input_dim])vector (
ndarray) – Flat parameter vector with correct dimension
- Returns:
Output of the network
- Return type:
ndarray