Esempio n. 1
0
calculate_meaning = Generator.MeaningCalculator(universe)


def parse_language(filename):
    with open(filename, 'r') as file:
        spec_dict = json.load(file)
    language = []
    for spec in spec_dict.values():
        expression = Parser.parse_expression(spec, setup)
        complexity = setup.measure_expression_complexity(
            expression, args.max_quantifier_length)
        meaning = calculate_meaning(expression)
        language.append(EvaluatedExpression(expression, meaning, complexity))
    return language


for filename in os.listdir(languages_dir):
    if filename.endswith('.json'):
        languages.append(parse_language(os.path.join(languages_dir, filename)))
        language_names.append(filename[:-5])  # Name without extension

informativeness = zip(language_names, map(informativeness_measurer, languages))
complexity = zip(language_names, map(complexity_measurer, languages))

file_util.dump_dill(
    informativeness,
    'informativeness_{0}_{1}.dill'.format(setup.name, args.inf_strat))
file_util.dump_dill(
    complexity, 'complexity_{0}_{1}.dill'.format(setup.name, args.comp_strat))
Esempio n. 2
0
args = parser.parse_args()

processes = args.processes
setup = ExperimentSetups.parse(args.setup)
max_quantifier_length = args.max_quantifier_length
model_size = args.model_size

file_util = FileUtil(
    fileutil.base_dir(args.dest_dir, setup.name, max_quantifier_length,
                      model_size))

folderName = "{0}/{1}_length={2}_size={3}".format(args.dest_dir, setup.name,
                                                  max_quantifier_length,
                                                  model_size)

processpool = ProcessPool(nodes=processes)

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

complexities = processpool.map(
    lambda ex: setup.measure_expression_complexity(ex, max_quantifier_length),
    expressions)

file_util.dump_dill(complexities, 'expression_complexities.dill')

processpool.close()
processpool.join()

print('Complexity Measuring finished.')
Esempio n. 3
0
                     args.model_size, args.name))

languages = LanguageLoader.load_languages(file_util)

universe = Generator.generate_simplified_models(args.model_size)

pool = ProcessPool(nodes=args.processes)

if args.inf_strat == 'exact':
    informativeness_measurer = InformativenessMeasurer(len(universe))
elif args.inf_strat == 'simmax':
    informativeness_measurer = SimMaxInformativenessMeasurer(universe)
else:
    raise ValueError('{0} is not a valid informativeness strategy.'.format(
        args.inf_strat))

if args.comp_strat == 'wordcount':
    complexity_measurer = WordCountComplexityMeasurer(args.max_words)
elif args.comp_strat == 'wordcomplexity':
    complexity_measurer = SumComplexityMeasurer(args.max_words, 1)
else:
    raise ValueError('{0} is not a valid complexity strategy.'.format(
        args.comp_strat))

informativeness = pool.map(informativeness_measurer, languages)
complexity = pool.map(complexity_measurer, languages)

file_util.dump_dill(informativeness,
                    'informativeness_{0}.dill'.format(args.inf_strat))
file_util.dump_dill(complexity, 'complexity_{0}.dill'.format(args.comp_strat))
Esempio n. 4
0
model_size = args.model_size

file_util = FileUtil(
    fileutil.base_dir(args.dest_dir, setup.name, max_quantifier_length,
                      model_size))

universe = setup.generate_models(model_size)

folderName = "{0}/{1}_length={2}_size={3}".format(args.dest_dir, setup.name,
                                                  max_quantifier_length,
                                                  model_size)
os.makedirs("{0}".format(folderName), exist_ok=True)

processpool = ProcessPool(nodes=processes)
expression_generator = Generator.ExpressionGenerator(setup, model_size,
                                                     universe, processpool)
(generated_expressions_dict, expressions_by_meaning) = \
    expression_generator.generate_all_expressions(max_quantifier_length)

print("{0} expressions!".format(len(expressions_by_meaning[bool].values())))

file_util.dump_dill(expressions_by_meaning[bool], 'generated_expressions.dill')
file_util.dump_dill(list(expressions_by_meaning[bool].values()),
                    'expressions.dill')
file_util.dump_dill(list(expressions_by_meaning[bool].keys()), 'meanings.dill')

processpool.close()
processpool.join()

print('Expression generation finished.')
parser.add_argument('--dest_dir', default='results')
parser.add_argument('--processes', default=4, type=int)

args = parser.parse_args()

processes = args.processes
setup = ExperimentSetups.parse(args.setup)
max_quantifier_length = args.max_quantifier_length
model_size = args.model_size

file_util = FileUtil(
    fileutil.base_dir(args.dest_dir, setup.name, max_quantifier_length,
                      model_size))

folderName = "{0}/{1}_length={2}_size={3}".format(args.dest_dir, setup.name,
                                                  max_quantifier_length,
                                                  model_size)

processpool = ProcessPool(nodes=processes)

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

costs = processpool.map(Measurer.measure_communicative_cost, meanings)

file_util.dump_dill(costs, 'expression_costs.dill')

processpool.close()
processpool.join()

print('Informativeness Measuring finished.')