Ratio-Based Inequalities
The `ratios` generator produces simple linear bounds of the form:
where:
(H(x)) is a Predicate (hypothesis),
(T(x)) is the target Property,
(F(x)) is a feature Property,
(c) is a lower bound constant:
\[c = \min_{x \in H^{-1}(\text{True})} \frac{T(x)}{F(x)}\](C) is an upper bound constant:
\[C = \max_{x \in H^{-1}(\text{True})} \frac{T(x)}{F(x)}\]
The generator emits exactly two `Conjecture` objects per feature: one lower-bound and one upper-bound inequality.
Workflow
Restrict the dataset to rows where the hypothesis holds:
\[D_H = \{x : H(x) = \text{True}\}\]Compute ratios for each object in (D_H):
\[r_i = \frac{T(x_i)}{F(x_i)}\]Extract constants:
\[c = \min_i r_i, \quad C = \max_i r_i\]Emit conjectures:
\[H(x) \Rightarrow T(x) \ge c \cdot F(x), \quad H(x) \Rightarrow T(x) \le C \cdot F(x)\]
Usage Example
import pandas as pd
from txgraffiti.logic.conjecture_logic import Property, Predicate
from txgraffiti.generators import ratios
# Sample dataset
df = pd.DataFrame({
'alpha': [1, 2, 3],
'beta': [3, 1, 1],
'connected':[True, True, True],
'tree': [False, False, True],
})
# Define target and features
target = Property('alpha', lambda df: df['alpha'])
features = [Property('beta', lambda df: df['beta'])]
# Define hypothesis
hyp = Predicate('connected', lambda df: df['connected'])
# Generate conjectures
conjs = list(ratios(df, features=features, target=target, hypothesis=hyp))
for c in conjs:
print(c)
Expected Output
(connected) → (alpha >= (1/3 * beta))
(connected) → (alpha <= (3 * beta))
Explanation
For each row with connected == True, the ratios generator computes:
Minimum ratio is (c = tfrac{1}{3}), yielding: (alpha ge tfrac{1}{3} beta)
Maximum ratio is (C = 3), yielding: (alpha le 3 beta)
These two inequalities form conjectures about how alpha is bounded by beta for connected graphs.
Integration with Playground
Use ratios inside the ConjecturePlayground to automate discovery:
from txgraffiti.playground import ConjecturePlayground
from txgraffiti.heuristics import morgan_accept, dalmatian_accept
from txgraffiti.processing import remove_duplicates, sort_by_touch_count
pg = ConjecturePlayground(df, object_symbol='G')
pg.discover(
methods = [ratios],
features = ['beta', 'gamma'],
target = 'alpha',
hypothesis = 'connected',
heuristics = [morgan_accept, dalmatian_accept],
post_processors = [remove_duplicates, sort_by_touch_count],
)
The ratios generator contributes clean, data-driven bounds to your symbolic conjecture workflow.