Example #1
0
mark = time.time()

def timer(task):
    print("{}\t{} seconds".format(task, str(round(time.time() - mark, 4))))
    return time.time()


#####################################################################
## Main code
#####################################################################

# Create and fill MegaTableau
mt = megatableau.MegaTableau()

# read in attested forms and add to MegaTableau
geneval.read_data_only(mt, args.attested_file_name)

if args.timed:
    mark = timer("\n Parsed arguments in")

# get alphabet
if args.alphabet_file_name:
    alphabet = geneval.read_sigma(mt, args.alphabet_file_name)
else:
    alphabet = geneval.read_sigma(mt)

if args.timed:
    mark = timer(" Inferred alphabet in")

## read in constraints
constraints = geneval.read_constraints(mt, args.constraint_file_name)
Example #2
0
    mt.read_weights_file(args.weights_file)
    optimizer.update_maxent_values(mt.weights, mt.tableau) # Needed if -outfile
    print('\nLog probability of data: {}'.format(- optimizer.neg_log_probability
                                (mt.weights, mt.tableau, args.L1, args.L2)))

# If Gaussian priors file is provided, read in to a list
if args.gaussian_priors_file:
    mt.read_priors_file(args.gaussian_priors_file)

# Optimize mt.weights (unless weights were specified)
if not args.weights_file:
    optimizer.learn_weights(mt, args.L1, args.L2, args.precision)

# Output file
if args.outfile:
    mt.write_output(args.outfile)

# Read in testing items, generate predictions for them
# NOTE: This step will only succeed if constraints can be evaluated
# automatically as regular expressions.
if args.testing_infile:
    testing_mt = megatableau.MegaTableau()
    testing_mt.weights = mt.weights
    geneval.read_data_only(testing_mt, args.testing_infile)
    geneval.apply_mark_list(testing_mt, mt.constraints)
    optimizer.update_maxent_values(testing_mt.weights, testing_mt.tableau)

    # Write tableau to file
    if args.testing_outfile:
        testing_mt.write_output(args.testing_outfile)