pulsatrix
Loading...
Searching...
No Matches
neuro_symbolic_toy_kb.hpp
Go to the documentation of this file.
1
8#pragma once
9
16#include "pulsatrix/tensor.hpp"
17
18namespace pulsatrix {
19
56public:
66 explicit ToyKnowledgeBase(DeviceBackend* backend, float p = 2.0f);
67
80 [[nodiscard]] float forward(const Tensor& x);
81
88 void backward();
89
98 float train_step(const Tensor& x, SGDOptimizer& optimizer);
99
101 [[nodiscard]] const Tensor& last_a() const { return last_a_; }
102
104 [[nodiscard]] const Tensor& last_b() const { return last_b_; }
105
107 [[nodiscard]] const Tensor& last_rule() const { return last_rule_; }
108
110 [[nodiscard]] LinearModule& predicate_a() { return linear_a_; }
111
113 [[nodiscard]] LinearModule& predicate_b() { return linear_b_; }
114
119 [[nodiscard]] NegationModule& negation_a() { return neg_a_; }
120
123 [[nodiscard]] NegationModule& negation_b() { return neg_b_; }
124
127 [[nodiscard]] DisjunctionModule& disjunction() { return disj_; }
128
129private:
130 DeviceBackend* backend_;
131 LinearModule linear_a_;
132 LinearModule linear_b_;
133 NegationModule neg_a_;
134 NegationModule neg_b_;
135 DisjunctionModule disj_;
136 SatisfactionLoss sat_loss_;
137 Tensor last_a_;
138 Tensor last_b_;
139 Tensor last_rule_;
140 bool has_forwarded_ = false;
141};
142
143} // namespace pulsatrix
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:219
y = a S b for a selected t-conorm S, over two independent fuzzy-truth-valued operand tensors (values ...
Definition disjunction_module.hpp:22
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
y = 1 - x, elementwise. No parameters, no parameter gradients.
Definition negation_module.hpp:21
param -= learning_rate * grad, per parameter, for every parameter a Module exposes.
Definition sgd_optimizer.hpp:12
loss = 1 - agg_p(truth_values) – the standard LTN "Real Logic" training objective (research_2026_neur...
Definition satisfaction_loss.hpp:49
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
A small, hand-traceable knowledge base: two neural predicates A(x)/B(x) (each a sigmoid-squashed Line...
Definition neuro_symbolic_toy_kb.hpp:55
LinearModule & predicate_b()
Predicate B's own LinearModule – test/inspection accessor.
Definition neuro_symbolic_toy_kb.hpp:113
const Tensor & last_a() const
Cached predicate A output from the most recent forward(), shape (N, 1).
Definition neuro_symbolic_toy_kb.hpp:101
ToyKnowledgeBase(DeviceBackend *backend, float p=2.0f)
Constructs the toy KB with fixed, small, sign-varied initial predicate weights (mission file Stage 3'...
NegationModule & negation_a()
Predicate A's own NegationModule (not(A)) – test/inspection accessor, added for Phase 2 Mission 0's e...
Definition neuro_symbolic_toy_kb.hpp:119
float forward(const Tensor &x)
Runs the full forward pass: A(x)/B(x) (Linear+sigmoid) -> not(A)/not(B) (NegationModule) -> rule = no...
LinearModule & predicate_a()
Predicate A's own LinearModule – test/inspection accessor.
Definition neuro_symbolic_toy_kb.hpp:110
const Tensor & last_b() const
Cached predicate B output from the most recent forward(), shape (N, 1).
Definition neuro_symbolic_toy_kb.hpp:104
const Tensor & last_rule() const
Cached rule truth degrees from the most recent forward(), shape (N,).
Definition neuro_symbolic_toy_kb.hpp:107
DisjunctionModule & disjunction()
The rule's own DisjunctionModule (not(A) or not(B), Product) – test/inspection accessor,...
Definition neuro_symbolic_toy_kb.hpp:127
float train_step(const Tensor &x, SGDOptimizer &optimizer)
One SGD step: zero_grad both predicates, forward(), backward(), optimizer step on both predicates.
void backward()
Backpropagates the loss through SatisfactionLoss -> DisjunctionModule -> NegationModule(x2) -> sigmoi...
NegationModule & negation_b()
Predicate B's own NegationModule (not(B)) – test/inspection accessor, same rationale as negation_a().
Definition neuro_symbolic_toy_kb.hpp:123
Abstract interface isolating vendor-specific memory/compute operations from Tensor/ComputationGraph.
Differentiable fuzzy disjunction (t-conorm) – Phase 1 Mission 0 of campaign_exai_dl_library_neuro_sym...
Dense/fully-connected layer – the reference Module implementation.
Definition acquisition_functions.hpp:16
Standard fuzzy negation y = 1 - x – Phase 1 Mission 0 of campaign_exai_dl_library_neuro_symbolic (dif...
Real-Logic-style knowledge-base satisfaction loss – Phase 1 Mission 1 of campaign_exai_dl_library_neu...
Stochastic gradient descent – operates uniformly across any Module's parameters().
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).