From 05ccd2d288ddd7a27b5be0d554704e3478a5fcd1 Mon Sep 17 00:00:00 2001 From: Chipe1 Date: Mon, 7 Aug 2017 17:39:41 +0530 Subject: [PATCH] Added minimal-consistent-det --- knowledge.py | 24 ++++++++++++++++++++++++ tests/test_knowledge.py | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/knowledge.py b/knowledge.py index a42640bfd..a5d165e3e 100644 --- a/knowledge.py +++ b/knowledge.py @@ -3,6 +3,7 @@ from random import shuffle from utils import powerset from collections import defaultdict +from itertools import combinations # ______________________________________________________________________________ @@ -205,6 +206,29 @@ def build_h_combinations(hypotheses): # ______________________________________________________________________________ +def minimal_consistent_det(E, A): + n = len(A) + + for i in range(n + 1): + for A_i in combinations(A, i): + if consistent_det(A_i, E): + return set(A_i) + + +def consistent_det(A, E): + H = {} + + for e in E: + attr_values = tuple(e[attr] for attr in A) + if attr_values in H and H[attr_values] != e['GOAL']: + return False + H[attr_values] = e['GOAL'] + + return True + +# ______________________________________________________________________________ + + def check_all_consistency(examples, h): """Check for the consistency of all examples under h""" for e in examples: diff --git a/tests/test_knowledge.py b/tests/test_knowledge.py index ec2623b3e..764777e7d 100644 --- a/tests/test_knowledge.py +++ b/tests/test_knowledge.py @@ -49,6 +49,14 @@ def test_version_space_learning(): assert [{'Pizza': 'Yes'}] in V +def test_minimal_consistent_det(): + assert minimal_consistent_det(party, {'Pizza', 'Soda'}) == {'Pizza'} + assert minimal_consistent_det(party[:2], {'Pizza', 'Soda'}) == set() + assert minimal_consistent_det(animals_umbrellas, {'Species', 'Rain', 'Coat'}) == {'Species', 'Rain', 'Coat'} + assert minimal_consistent_det(conductance, {'Mass', 'Temp', 'Material', 'Size'}) == {'Temp', 'Material'} + assert minimal_consistent_det(conductance, {'Mass', 'Temp', 'Size'}) == {'Mass', 'Temp', 'Size'} + + party = [ {'Pizza': 'Yes', 'Soda': 'No', 'GOAL': True}, {'Pizza': 'Yes', 'Soda': 'Yes', 'GOAL': True}, @@ -65,6 +73,18 @@ def test_version_space_learning(): {'Species': 'Cat', 'Rain': 'No', 'Coat': 'Yes', 'GOAL': True} ] +conductance = [ + {'Sample': 'S1', 'Mass': 12, 'Temp': 26, 'Material': 'Cu', 'Size': 3, 'GOAL': 0.59}, + {'Sample': 'S1', 'Mass': 12, 'Temp': 100, 'Material': 'Cu', 'Size': 3, 'GOAL': 0.57}, + {'Sample': 'S2', 'Mass': 24, 'Temp': 26, 'Material': 'Cu', 'Size': 6, 'GOAL': 0.59}, + {'Sample': 'S3', 'Mass': 12, 'Temp': 26, 'Material': 'Pb', 'Size': 2, 'GOAL': 0.05}, + {'Sample': 'S3', 'Mass': 12, 'Temp': 100, 'Material': 'Pb', 'Size': 2, 'GOAL': 0.04}, + {'Sample': 'S4', 'Mass': 18, 'Temp': 100, 'Material': 'Pb', 'Size': 3, 'GOAL': 0.04}, + {'Sample': 'S4', 'Mass': 18, 'Temp': 100, 'Material': 'Pb', 'Size': 3, 'GOAL': 0.04}, + {'Sample': 'S5', 'Mass': 24, 'Temp': 100, 'Material': 'Pb', 'Size': 4, 'GOAL': 0.04}, + {'Sample': 'S6', 'Mass': 36, 'Temp': 26, 'Material': 'Pb', 'Size': 6, 'GOAL': 0.05}, +] + def r_example(Alt, Bar, Fri, Hun, Pat, Price, Rain, Res, Type, Est, GOAL): return {'Alt': Alt, 'Bar': Bar, 'Fri': Fri, 'Hun': Hun, 'Pat': Pat, 'Price': Price, 'Rain': Rain, 'Res': Res, 'Type': Type, 'Est': Est, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy