def test_load_rb_s_07(): data = load_rb_s_07(num_instances=1) known = { '_guid': '660ac76d-93b3-4ce7-8a15-a3213e9103f5', 'component0': { 'b': 0.0, 'l': 0.0, 'r': 3.0, 't': 1.0, 'type': 'plat0' }, 'component1': { 'b': 1.0, 'l': 1.0, 'r': 2.0, 't': 4.0, 'type': 'plat90' }, 'component8': { 'b': 4.0, 'l': 0.0, 'r': 3.0, 't': 5.0, 'type': 'ufoo0' }, 'success': '0' } assert known == data[0]
def test_load_rb_s_07(): data = load_rb_s_07(num_instances=1) known = {'_guid': '660ac76d-93b3-4ce7-8a15-a3213e9103f5', 'component0': {'b': 0.0, 'l': 0.0, 'r': 3.0, 't': 1.0, 'type': 'plat0'}, 'component1': {'b': 1.0, 'l': 1.0, 'r': 2.0, 't': 4.0, 'type': 'plat90'}, 'component8': {'b': 4.0, 'l': 0.0, 'r': 3.0, 't': 5.0, 'type': 'ufoo0'}, 'success': '0'} assert known == data[0]
def output_json(file="forest", size=100, prune=True, seed=50, burn=1): random.seed(seed) if file == "forest": instances = ds.load_forest_fires() variables = False elif file == "voting": instances = ds.load_congressional_voting() variables = False elif file == "iris": instances = ds.load_iris() variables = False elif file == "mushroom": instances = ds.load_mushroom() variables = False elif file == "rb_com_11": instances = ds.load_rb_com_11() variables = True elif file == "rb_s_07": instances = ds.load_rb_s_07() variables = True elif file == "rb_s_13": instances = ds.load_rb_s_13() variables = True elif file == "rb_wb_03": instances = ds.load_rb_wb_03() variables = True else: instances = ds.load_forest_fires() variables = False random.shuffle(instances) pprint.pprint(instances[0]) instances = instances[:size] print(len(instances)) if variables: variablizer = ObjectVariablizer() instances = [variablizer.transform(t) for t in instances] tree = TrestleTree() tree.fit(instances, iterations=burn) pprint.pprint(tree.root.output_json()) with open('output.js', 'w') as out: out.write("var trestle_output = ") out.write(json.dumps(tree.root.output_json())) out.write(";")
def output_json(file="forest", size=100, prune=True, seed=50, burn=1): random.seed(seed) if file == "forest": instances = ds.load_forest_fires() variables = False elif file == "voting": instances = ds.load_congressional_voting() variables = False elif file == "iris": instances = ds.load_iris() variables = False elif file == "mushroom": instances = ds.load_mushroom() variables = False elif file == "rb_com_11": instances = ds.load_rb_com_11() variables = True elif file == "rb_s_07": instances = ds.load_rb_s_07() variables = True elif file == "rb_s_13": instances = ds.load_rb_s_13() variables = True elif file == "rb_wb_03": instances = ds.load_rb_wb_03() variables = True else: instances = ds.load_forest_fires() variables = False random.shuffle(instances) pprint.pprint(instances[0]) instances = instances[:size] print(len(instances)) if variables: variablizer = ObjectVariablizer() instances = [variablizer.transform(t) for t in instances] tree = TrestleTree() tree.fit(instances, iterations=burn) # pprint.pprint(tree.root.output_json()) with open('output.js', 'w') as out: out.write("var trestle_output = ") out.write(json.dumps(tree.root.output_json())) out.write(";")
from random import seed import numpy as np from concept_formation.examples.examples_utils import lowess from concept_formation.evaluation import incremental_evaluation from concept_formation.trestle import TrestleTree from concept_formation.dummy import DummyTree from concept_formation.datasets import load_rb_s_07 from concept_formation.datasets import load_rb_s_07_human_predictions from concept_formation.preprocessor import ObjectVariablizer seed(5) num_runs = 30 num_examples = 29 towers = load_rb_s_07() variablizer = ObjectVariablizer() towers = [variablizer.transform(t) for t in towers] naive_data = incremental_evaluation(DummyTree(), towers, run_length=num_examples, runs=num_runs, attr="success") cobweb_data = incremental_evaluation(TrestleTree(), towers, run_length=num_examples, runs=num_runs, attr="success") human_data = [] key = None human_predictions = load_rb_s_07_human_predictions() for line in human_predictions:
from concept_formation.trestle import TrestleTree from concept_formation.visualize import visualize # These lines load up and use one of the example datasets included in the # library if you don't have a readily available dataset to test. The rb_s_07 # dataset is similar to but not exactly the same as the one used to generate # the figures in the paper. from concept_formation.datasets import load_rb_s_07 from concept_formation.preprocessor import ObjectVariablizer data = load_rb_s_07() # As long as your data conforms to the instance representation: # https://concept-formation.readthedocs.io/en/latest/instance_representation.html # it can be basically anything. # data = [] # This step is to make sure the component attributes of the instances are # properly tagged as variable. See the instance representation link above for # this. # ov = ObjectVariablizer() # data = ov.batch_transform(data) # These three lines are the core of the process. They will fit the data and # generate a visualization that will automatically open a browser to the view. # If you want to embed the output in some other process, like a LearnSphere # workflow, it would take a little more work but is easy in principle. tree = TrestleTree() tree.fit(data)