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

y = 1 - x, elementwise. No parameters, no parameter gradients. More...

#include <negation_module.hpp>

Inheritance diagram for pulsatrix::NegationModule:
Collaboration diagram for pulsatrix::NegationModule:

Public Member Functions

 NegationModule (DeviceBackend *backend)
 Constructs a negation module.
 
Tensor backward (const Tensor &grad_output) override
 Gradient w.r.t. this module's input: dy/dx = -1, so grad_x = -grad_output.
 
OpType op_type () const override
 Elementwise per this module's own single-input, weight-free operation.
 
Tensor propagate_relevance (const Tensor &relevance_out, const LRPRuleConfig &config) override
 LRP relevance propagation: pass-through, unchanged.
 
std::optional< DeviceType > compute_device () const override
 Where this layer computes, so forward() rejects an input on another device (FND-8).
 
- Public Member Functions inherited from pulsatrix::Module
virtual ~Module ()=default
 
Tensor forward (const Tensor &input)
 Runs this module's forward computation.
 
std::pair< Tensor, NodeId > forward_traced (const Tensor &input, NodeId input_node, ComputationGraph &graph, Autograd &autograd)
 Runs forward() while also registering a ComputationGraph node (tagged with this module's op_type(), parented to input_node) and wiring an Autograd backward function that reuses this module's own backward() – the opt-in traced/explainable path, per Phase 2 Mission 0.
 
virtual bool supports_lrp_rule (LRPRule rule) const
 Whether propagate_relevance() implements rule (no silent fallback: callers such as ExplainerContext::relevance_pass() throw rather than run a module on a rule it does not implement).
 
virtual std::vector< NamedParamRef > named_parameters ()
 This module's trainable parameters, each with its hierarchical name – the one place a module declares its parameters (roadmap FND-1).
 
virtual std::vector< ParamRef > parameters ()
 This module's trainable parameters and their gradients, for an optimizer to update uniformly across module types.
 
void set_requires_grad (bool requires_grad, const std::string &prefix="")
 Freezes (false) or unfreezes (true) parameters by name (roadmap FND-2).
 
virtual void set_training (bool training)
 Sets this module's training/eval mode. Defaults to training (matches every mainstream framework's Module default).
 
bool is_training () const
 Whether this module is currently in training mode.
 

Protected Member Functions

Tensor forward_impl (const Tensor &input) override
 The actual forward computation. Called by forward() after precondition checks.
 

Detailed Description

y = 1 - x, elementwise. No parameters, no parameter gradients.

Note
Unlike ConjunctionModule/DisjunctionModule (genuinely binary, two independent operand tensors), negation is a plain unary elementwise map – it fits Module::forward()'s existing single-Tensor contract with no design question to resolve (see mission_0_tnorm_operators.md's Stage 3 section, which is scoped to the binary operators only).

Constructor & Destructor Documentation

◆ NegationModule()

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

Constructs a negation module.

Parameters
backendBackend to allocate/compute through. Not owned; must outlive this module.

Member Function Documentation

◆ backward()

Tensor pulsatrix::NegationModule::backward ( const Tensor &  grad_output)
overridevirtual

Gradient w.r.t. this module's input: dy/dx = -1, so grad_x = -grad_output.

Parameters
grad_outputGradient w.r.t. this module's output. Must match the shape of the most recent forward() call's output.
Exceptions
std::logic_errorif called before any forward().
std::invalid_argumentif grad_output's shape differs from the cached forward shape.
Note
Device-generic: runs on Cpu, Cuda or Hip tensors (GPU-native-kernels Mission 1b); inputs must share one device.

Implements pulsatrix::Module.

◆ compute_device()

std::optional< DeviceType > pulsatrix::NegationModule::compute_device ( ) const
inlineoverridevirtual

Where this layer computes, so forward() rejects an input on another device (FND-8).

Reimplemented from pulsatrix::Module.

◆ forward_impl()

Tensor pulsatrix::NegationModule::forward_impl ( const Tensor &  input)
overrideprotectedvirtual

The actual forward computation. Called by forward() after precondition checks.

Implements pulsatrix::Module.

◆ op_type()

OpType pulsatrix::NegationModule::op_type ( ) const
inlineoverridevirtual

Elementwise per this module's own single-input, weight-free operation.

Implements pulsatrix::Module.

◆ propagate_relevance()

Tensor pulsatrix::NegationModule::propagate_relevance ( const Tensor &  relevance_out,
const LRPRuleConfig &  config 
)
overridevirtual

LRP relevance propagation: pass-through, unchanged.

Note
Not a placeholder – this is the correct rule for negation given this codebase's own convention (ReluModule's identical justification): LRP rules are defined across combinations of multiple relevance-bearing inputs (the genuinely novel case ConjunctionModule/DisjunctionModule need); a single-input, monotonic, bijective elementwise reparametrization like 1 - x passes relevance through unchanged, exactly like ReluModule's pointwise nonlinearity does. The 1 in y = -x + 1 is a constant bias, absorbed rather than distributed – same bias-exclusion convention LinearModule's own epsilon rule already uses (its denominator is the pre-bias z_j, not the post-bias output).

Implements pulsatrix::Module.


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