pulsatrix
Loading...
Searching...
No Matches
neuro_symbolic_datalog_bridge.hpp
Go to the documentation of this file.
1
13#pragma once
14
22#include "pulsatrix/tensor.hpp"
23
24namespace pulsatrix::datalog {
25
36
67
129public:
138
151
158 void backward();
159
174 [[nodiscard]] NeuralPredicateRelevanceResult propagate_relevance(double relevance_seed,
175 const LRPRuleConfig& config = LRPRuleConfig{});
176
178 [[nodiscard]] LinearModule& predicate() { return predicate_; }
179
183 [[nodiscard]] static std::vector<Rule> diamond_ancestor_program();
184
188
189private:
190 DeviceBackend* backend_;
191 LinearModule predicate_;
192 Tensor last_x_;
193 Tensor last_s_; // (1,1) -- cached sigmoid output, sigmoid_backward's own "y" input.
194 double last_grad_wrt_s_ = 0.0;
195 bool has_evaluated_ = false;
196};
197
198} // namespace pulsatrix::datalog
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:219
y = x @ W + b, batched (x is (N, in_features), y is (N, out_features)) – migrated from the original u...
Definition linear_module.hpp:37
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Bridges one neural-predicate-weighted base fact into the real-valued weighted Datalog engine.
Definition neuro_symbolic_datalog_bridge.hpp:128
static std::vector< Rule > diamond_ancestor_program()
The diamond-graph ancestor program (ancestor(X,Y):-edge(X,Y). / ancestor(X,Y):-edge(X,...
NeuralPredicateDatalogBridge(DeviceBackend *backend)
Constructs the bridge with a fresh LinearModule(1, 1) neural predicate, initialized to the same small...
LinearModule & predicate()
The neural predicate's own LinearModule – test/inspection accessor.
Definition neuro_symbolic_datalog_bridge.hpp:178
NeuralPredicateQueryResult evaluate(const Tensor &x)
Runs the neural predicate on x, wires its (sigmoid-squashed) scalar output in as edge(a,...
void backward()
Threads evaluate()'s grad_wrt_predicate_output into the neural predicate's own LinearModule::backward...
static WeightedFactDatabase< double > constant_edge_facts()
edge(a,c)=0.4, edge(b,d)=0.6, edge(c,d)=0.3 – the constant-weighted facts of the diamond toy program,...
NeuralPredicateRelevanceResult propagate_relevance(double relevance_seed, const LRPRuleConfig &config=LRPRuleConfig{})
Phase 3 Mission 3's own deliverable: propagates relevance from ancestor(a,d)'s derived weight back th...
A weighted fact database: a map from ground atom to a semiring value type T (bool for the trivial/boo...
Definition datalog_weighted_fact_database.hpp:49
Forward-mode-automatic-differentiation semiring (DualNumber<T>/DualSemiring<T>) – a second,...
LRP-style relevance propagation for the real-valued (+, x) provenance-semiring Datalog circuit built ...
A Datalog rule: head :- body1, body2, ..., range-restricted (safe) by construction....
Generic provenance-semiring abstraction (zero/one/add=(+)/mul=(x)) plus the boolean (trivial) and rea...
A map from ground Datalog atom to a semiring-typed weight. Phase 3 Mission 1 of campaign_exai_dl_libr...
Dense/fully-connected layer – the reference Module implementation.
Selects which LRP rule variant a Module::propagate_relevance() call uses.
Definition datalog_atom.hpp:14
std::unordered_map< Atom, double, AtomHash > RelevanceMap
A map from ground atom to its accumulated relevance (real-valued, per the RealSemiring<double> circui...
Definition datalog_lrp.hpp:112
Configuration for LRP relevance propagation: which rule a module applies and its hyperparameters....
Definition lrp_rule_config.hpp:57
The two numbers a forward pass through the bridge produces: the derived query fact's real-valued weig...
Definition neuro_symbolic_datalog_bridge.hpp:32
double query_weight
ancestor(a,d)'s derived weight.
Definition neuro_symbolic_datalog_bridge.hpp:33
double grad_wrt_predicate_output
d(query_weight) / d(edge(a,b)'s weight, i.e. the sigmoid output).
Definition neuro_symbolic_datalog_bridge.hpp:34
The result of one NeuralPredicateDatalogBridge::propagate_relevance() call – Phase 3 Mission 3's own ...
Definition neuro_symbolic_datalog_bridge.hpp:55
RelevanceMap base_fact_relevance
Relevance at every extensional/base fact in the diamond program, per RelevanceResult::base_facts (dat...
Definition neuro_symbolic_datalog_bridge.hpp:61
Tensor relevance_wrt_x
edge(a,b)'s relevance, continued through the predicate's own sigmoid (pass-through) and LinearModule:...
Definition neuro_symbolic_datalog_bridge.hpp:65
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).