pulsatrix
Loading...
Searching...
No Matches
pulsatrix::XorNetwork Class Reference

A tiny MLP (Linear(2,4) -> ReLU -> Linear(4,1)) trained on XOR – the canonical not-linearly-separable case, exactly representable by a small MLP, giving an unambiguous convergence target for Phase 1's "prove the training loop works" goal. More...

#include <xor_training_example.hpp>

Public Member Functions

 XorNetwork (DeviceBackend *backend)
 Constructs the network with fixed, non-zero initial weights.
 
Tensor forward (const Tensor &input)
 Runs the network forward.
 
float train_step (const Tensor &input, const Tensor &target, AdamOptimizer &optimizer, MetricsSink &sink, int step)
 Runs one training step: forward, loss, backward through every layer, one Adam update per layer's parameters, and logs the loss.
 
const Tensor & linear1_weight () const
 Test/inspection accessor.
 
LinearModule & linear1 ()
 Mutable layer accessors – Population Based Training's own exploit step needs to read/write this network's live weights directly (to copy a top performer's weights onto a bottom performer mid-training, via each LinearModule's own parameters()), which no existing const-only accessor supports. Logged as a small necessary scope addition, found by campaign_exai_dl_library_evolutionary_deep_learning's Phase 4 Mission 0.
 
LinearModule & linear2 ()
 

Detailed Description

A tiny MLP (Linear(2,4) -> ReLU -> Linear(4,1)) trained on XOR – the canonical not-linearly-separable case, exactly representable by a small MLP, giving an unambiguous convergence target for Phase 1's "prove the training loop works" goal.

Note
Modules are chained directly (no ComputationGraph/Autograd involvement) – see mission_training_loop.md's design rationale. Batch size 1 (operator decision) – trains on one example at a time, no batching added to any module.
Deterministic, hand-picked non-zero initial weights, NOT a general Xavier/He scheme. All-zero initialization was tried first during this mission's design and found to break symmetry completely: with W=0 everywhere, every layer's forward output is 0 regardless of input, and every gradient that depends on multiplying by a zero weight or a zero (pre-activation) ReLU input is itself zero – linear1's weights and linear2's weights never receive a gradient at all, only linear2's bias does. Non-zero initial weights are required to break this symmetry; a small, fixed, sign-varied initialization is sufficient for a network this tiny. A general initialization scheme (Xavier/He) remains deferred until a real dataset needs one.

Constructor & Destructor Documentation

◆ XorNetwork()

pulsatrix::XorNetwork::XorNetwork ( DeviceBackend *  backend)
explicit

Constructs the network with fixed, non-zero initial weights.

Parameters
backendBackend to compute through. Not owned; must outlive this network.

Member Function Documentation

◆ forward()

Tensor pulsatrix::XorNetwork::forward ( const Tensor &  input)

Runs the network forward.

Parameters
inputShape (2,).
Returns
Shape (1,).

◆ linear1()

LinearModule & pulsatrix::XorNetwork::linear1 ( )
inline

Mutable layer accessors – Population Based Training's own exploit step needs to read/write this network's live weights directly (to copy a top performer's weights onto a bottom performer mid-training, via each LinearModule's own parameters()), which no existing const-only accessor supports. Logged as a small necessary scope addition, found by campaign_exai_dl_library_evolutionary_deep_learning's Phase 4 Mission 0.

◆ linear1_weight()

const Tensor & pulsatrix::XorNetwork::linear1_weight ( ) const
inline

Test/inspection accessor.

◆ linear2()

LinearModule & pulsatrix::XorNetwork::linear2 ( )
inline

◆ train_step()

float pulsatrix::XorNetwork::train_step ( const Tensor &  input,
const Tensor &  target,
AdamOptimizer &  optimizer,
MetricsSink &  sink,
int  step 
)

Runs one training step: forward, loss, backward through every layer, one Adam update per layer's parameters, and logs the loss.

Parameters
inputShape (2,).
targetShape (1,).
optimizerOptimizer to update this network's parameters with.
sinkWhere the loss value is logged (tag "loss").
stepTraining step number, passed through to sink.
Returns
The loss value for this example, before the update.

The documentation for this class was generated from the following file: