Logic¶
Elements of propositional logic: constraints, propositions, and conjunctions.
Overview¶
Details¶
-
class
realkd.logic.
Conjunction
(props)¶ Conjunctive aggregation of propositions.
For example:
>>> old = KeyValueProposition('age', Constraint.greater_equals(60)) >>> male = KeyValueProposition('sex', Constraint.equals('male')) >>> high_risk = Conjunction([male, old]) >>> stephanie = {'age': 30, 'sex': 'female'} >>> erika = {'age': 72, 'sex': 'female'} >>> ron = {'age': 67, 'sex': 'male'} >>> high_risk(stephanie), high_risk(erika), high_risk(ron) (False, False, True)
Elements can be accessed via index and are sorted lexicographically. >>> high_risk age>=60 & sex==male >>> high_risk[0] age>=60 >>> len(high_risk) 2
>>> high_risk2 = Conjunction([old, male]) >>> high_risk == high_risk2 True
>>> titanic = pd.read_csv("../datasets/titanic/train.csv") >>> titanic.drop(columns=['PassengerId', 'Name', 'Ticket', 'Cabin'], inplace=True) >>> male = KeyValueProposition('Sex', Constraint.equals('male')) >>> third_class = KeyValueProposition('Pclass', Constraint.greater_equals(3)) >>> conj = Conjunction([male, third_class]) >>> titanic.loc[conj] Survived Pclass Sex Age SibSp Parch Fare Embarked 0 0 3 male 22.0 1 0 7.2500 S 4 0 3 male 35.0 0 0 8.0500 S 5 0 3 male NaN 0 0 8.4583 Q 7 0 3 male 2.0 3 1 21.0750 S 12 0 3 male 20.0 0 0 8.0500 S .. ... ... ... ... ... ... ... ... 877 0 3 male 19.0 0 0 7.8958 S 878 0 3 male NaN 0 0 7.8958 S 881 0 3 male 33.0 0 0 7.8958 S 884 0 3 male 25.0 0 0 7.0500 S 890 0 3 male 32.0 0 0 7.7500 Q [347 rows x 8 columns]