def main(args): setup = experiment_setups.parse(args.setup) processes = setup.processes max_quantifier_length = setup.max_quantifier_length model_size = setup.model_size file_util = FileUtil( fileutil.base_dir(setup.dest_dir, setup.name, max_quantifier_length, model_size)) folderName = "{0}/{1}_length={2}_size={3}".format(setup.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.')
def main(): processes = args.processes setup = experiment_setups.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)) 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 = 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.')
def main(args): setup = experiment_setups.parse(args.setup) file_util_out = FileUtil( fileutil.run_dir(setup.dest_dir, setup.name, setup.max_quantifier_length, setup.model_size, setup.random_name)) file_util_in = FileUtil( fileutil.base_dir(setup.dest_dir, setup.name, setup.max_quantifier_length, setup.model_size)) unevaluated_expressions = file_util_in.load_dill('expressions.dill') if args.indices is not None: index_sets = [] for indices_name in args.indices: index_sets.append( set( file_util_in.load_dill( '{0}_expression_indices.dill'.format(indices_name)))) indices = set.intersection(*index_sets) else: indices = range(len(unevaluated_expressions)) if args.sample is None: languages = generate_all(indices, args.max_words, args.fixedwordcount) else: languages = generate_sampled(indices, setup.max_words, args.sample) file_util_out.dump_dill(languages, 'language_indices.dill') file_util_out.save_stringlist([list(map(str, lang)) for lang in languages], 'languages.txt') print("languages.py finished.")
def init(use_base_dir=False): parser = argparse.ArgumentParser(description="Analyze") parser.add_argument('--setup', help='Path to the setup json file.', required=True) args = parser.parse_args() setup = experiment_setups.parse(args.setup) dirname = fileutil.base_dir(setup.dest_dir, setup.name, setup.max_quantifier_length, setup.model_size) if use_base_dir \ else fileutil.run_dir(setup.dest_dir, setup.name, setup.max_quantifier_length, setup.model_size, setup.name) file_util = FileUtil(dirname) return args, setup, file_util
def __init__(self, props): self._props = props # private # common setups self.name = props['name'] self.pareto_name = props['pareto_name'] self.natural_name = props['natural_name'] self.random_name = props['random_name'] self.lexical_quantifiers_filename = \ path.join(path.dirname(props['setup_filename']), props['lexical_quantifiers_filename']) self.generate_models = locate(props['model_generator']) self.generate_primitives = locate(props['primitive_generator']) self.parse_primitive = locate(props['primitive_parser']) self.measure_expression_complexity = locate( props['expression_complexity_measurer']) self.measure_quantifier_complexity = locate( props['quantifier_complexity_measurer']) self.operators = { name: op.operators[name] for name in props['operators'] } self.natural_languages_dirname = \ path.join(path.dirname(props['setup_filename']), 'Languages/{0}'.format(props['name'])) self.possible_input_types = [] for (name, operator) in self.operators.items(): self.possible_input_types.append(operator.inputTypes) #set up of quantifiers, sizes, etc self.max_quantifier_length = int(props['max_quantifier_length']) self.model_size = int(props['model_size']) self.processes = int(props['processes']) # self.run_name = props['run_name'] self.comp_strat = props['comp_strat'] self.inf_strat = props['inf_strat'] self.max_words = props['max_words'] #set up of files self.dest_dir = props['dest_dir'] self.use_base_dir = True if props['use_base_dir'].lower( ) == "true" else False self.dirname = fileutil.base_dir(self.dest_dir, self.name, self.max_quantifier_length, self.model_size) \ if self.use_base_dir else \ fileutil.run_dir(self.dest_dir, self.name, self.max_quantifier_length, self.model_size, self.run_name) self.file_util = FileUtil(self.dirname)
def main(args): processes = args.processes setup = experiment_setups.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.')