def test_not_upward_monotone_a():
    expression = Parser.parse_expression(['subset', 'A', 'B'], Setup)
    universe = Generator.generate_simplified_models(10)

    meaning = Generator.MeaningCalculator(universe)(expression)

    measurer = MonotonicityMeasurer(universe, 10, 'A')

    monotonicity = measurer(meaning)

    assert not math.isclose(monotonicity, 1)
def test_completely_downward_monotone():
    expression = Parser.parse_expression(['>', 6, ['card', 'A']], Setup)
    universe = Generator.generate_simplified_models(10)

    meaning = Generator.MeaningCalculator(universe)(expression)

    measurer = MonotonicityMeasurer(universe, 10, 'A', down=True)

    monotonicity = measurer(meaning)

    assert math.isclose(monotonicity, 1)
def test_not_entirely_upward_monotone_a_equals():
    expression = Parser.parse_expression([
        'or', ['=', ['card', ['intersection', 'A', 'B']], 3],
        ['=', 9, ['card', ['intersection', 'A', 'B']]]
    ], Setup)
    universe = Generator.generate_simplified_models(10)

    meaning = Generator.MeaningCalculator(universe)(expression)

    measurer = MonotonicityMeasurer(universe, 10, 'A')

    monotonicity = measurer(meaning)
    print(monotonicity)
    assert not math.isclose(monotonicity, 1)
from pathos.multiprocessing import ProcessPool

import Generator
import analysisutil
from Monotonicity import MonotonicityMeasurer

(args, setup, file_util) = analysisutil.init(use_base_dir=True)

meanings = file_util.load_dill('meanings.dill')

universe = Generator.generate_simplified_models(args.model_size)

measurer_a = MonotonicityMeasurer(universe, args.model_size, 'A')
measurer_b = MonotonicityMeasurer(universe, args.model_size, 'B')

with ProcessPool(nodes=args.processes) as process_pool:
    conservativities_a = process_pool.map(measurer_a, meanings)
    conservativities_b = process_pool.map(measurer_b, meanings)
    conservativities_max = process_pool.map(max, conservativities_a,
                                            conservativities_b)

file_util.dump_dill(conservativities_a, 'conservativities_a.dill')
file_util.dump_dill(conservativities_b, 'conservativities_b.dill')
file_util.dump_dill(conservativities_max, 'conservativities_max.dill')
from pathos.multiprocessing import ProcessPool

import Generator
import analysisutil
from Monotonicity import MonotonicityMeasurer

(args, setup, file_util) = analysisutil.init(use_base_dir=True)

meanings = file_util.load_dill('meanings.dill')

universe = Generator.generate_simplified_models(args.model_size)

measurer_a_up = MonotonicityMeasurer(universe, args.model_size, 'A')
measurer_b_up = MonotonicityMeasurer(universe, args.model_size, 'B')
measurer_a_down = MonotonicityMeasurer(universe,
                                       args.model_size,
                                       'A',
                                       down=True)
measurer_b_down = MonotonicityMeasurer(universe,
                                       args.model_size,
                                       'B',
                                       down=True)

with ProcessPool(nodes=args.processes) as process_pool:
    monotonicities_a_up = process_pool.map(measurer_a_up, meanings)
    monotonicities_b_up = process_pool.map(measurer_b_up, meanings)
    monotonicities_a_down = process_pool.map(measurer_a_down, meanings)
    monotonicities_b_down = process_pool.map(measurer_b_down, meanings)
    monotonicities_a_max = process_pool.map(max, monotonicities_a_up,
                                            monotonicities_a_down)
    monotonicities_b_max = process_pool.map(max, monotonicities_b_up,
Ejemplo n.º 6
0
import random

from pathos.multiprocessing import ProcessPool

import Generator
from Monotonicity import MonotonicityMeasurer
import matplotlib.pyplot as plt

universe = Generator.generate_simplified_models(10)

meanings = [tuple(random.choice([True, False]) for i in range(len(universe))) for j in range(5000)]

measurer_up = MonotonicityMeasurer(universe, 10, 'B')
measurer_down = MonotonicityMeasurer(universe, 10, 'B', down=True)

with ProcessPool(4) as process_pool:
    monotonicities_up = process_pool.map(measurer_up, meanings)
    monotonicities_down = process_pool.map(measurer_down, meanings)
    monotonicities = process_pool.map(max, monotonicities_up, monotonicities_down)

fig = plt.figure()

plt.hist(monotonicities,bins=30,range=[0,1])

plt.show()

fig.savefig('results/random_monotone.png', bbox_inches='tight')