# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # import script import ontology import dataset import graph import collections import ml import numpy as np TEST_SAMPLES = int(script.option('TEST_SAMPLES')) OUTPUT = script.option('OUTPUT') features = ontology.features rooms = ontology.rooms world = dataset.DiscreteDistribution([(1, dist) for cat,dist in rooms.items()]) test_samples = dataset.LabelledSample(world, TEST_SAMPLES) ############################################################################# def map_classifier(sample): best = max([(dataset.SampleProbability(dist, sample), label) for label, dist in rooms.items()]) return best[1] confusion = collections.defaultdict(int)
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # This module loads the ontology and creates distributions defined by: # default_knowledge-semmap.xml and defaultprobs-semmap.txt # import script import re import math import dataset from collections import defaultdict POISSON_EXPANSION = 3 DEFAULT_KNOWLEDGE = script.option('ONTOLOGY_DEFAULT_KNOWLEDGE') DEFAULT_OBJ_PROBS = script.option('ONTOLOGY_DEFAULT_OBJ_PROBS') DROP_FEATURES = script.option('ONTOLOGY_DROP_FEATURES').split() potential = dict() roomcats = set() features = set() feature_space = defaultdict(set) def Load(): print("Loading default knowledge...") for line in open(DEFAULT_KNOWLEDGE): match = re.match('^\s+<item\s+room_category1="(?P<roomcat>\w+)"\s+' + '(?P<proptype>\w+)="(?P<propval>\w+)"\s+' + '(?:potential|probability)="(?P<potential>\S+)"\s*\/>\s*$', line)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # import script import ontology import random import dataset import graph import collections import ml KNOWN_LABELS = script.option('KNOWN_LABELS').split() LABELLED_SAMPLES = int(script.option('LABELLED_SAMPLES')) UNLABELLED_SAMPLES = int(script.option('UNLABELLED_SAMPLES')) TEST_SAMPLES = int(script.option('TEST_SAMPLES')) PLOT = script.option('PLOT').split() OUTPUT = script.option('OUTPUT') features = ontology.features rooms = ontology.rooms ############################################################################# all_labels = rooms.keys() world = dataset.DiscreteDistribution([(1, dist) for cat, dist in rooms.items()]) known = dataset.DiscreteDistribution([(1, dist) for cat, dist in rooms.items()
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # import script import ontology import random import dataset import graph import collections import ml KNOWN_LABELS = script.option('KNOWN_LABELS').split() LABELLED_SAMPLES = int(script.option('LABELLED_SAMPLES')) UNLABELLED_SAMPLES = int(script.option('UNLABELLED_SAMPLES')) TEST_SAMPLES = int(script.option('TEST_SAMPLES')) PLOT = script.option('PLOT').split() OUTPUT = script.option('OUTPUT') features = ontology.features rooms = ontology.rooms ############################################################################# all_labels = rooms.keys()
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # This module loads the ontology and creates distributions defined by: # default_knowledge-semmap.xml and defaultprobs-semmap.txt # import script import re import math import dataset from collections import defaultdict POISSON_EXPANSION = 3 DEFAULT_KNOWLEDGE = script.option('ONTOLOGY_DEFAULT_KNOWLEDGE') DEFAULT_OBJ_PROBS = script.option('ONTOLOGY_DEFAULT_OBJ_PROBS') DROP_FEATURES = script.option('ONTOLOGY_DROP_FEATURES').split() potential = dict() roomcats = set() features = set() feature_space = defaultdict(set) def Load(): print("Loading default knowledge...") for line in open(DEFAULT_KNOWLEDGE): match = re.match( '^\s+<item\s+room_category1="(?P<roomcat>\w+)"\s+' + '(?P<proptype>\w+)="(?P<propval>\w+)"\s+' +
import script import explain from ontology import features, rooms out = explain.ExplainDistributions(sorted(features.items()), sorted(rooms.items())) script.WriteFile(script.option('OUTPUT'), out)