コード例 #1
0
ファイル: phlearn.py プロジェクト: rdaland/PhoMEnt
## apply constraints (this is the costliest step...)
geneval.apply_mark_list(mt, constraints)

if args.timed:
    mark = timer(" Added violations in")

# 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
optimizer.learn_weights(mt, args.L1, args.L2, args.precision)

if args.timed:
    mark = timer(" Optimized weights in")

# Write the final MegaTableau to file
if args.outfile:
    mt.write_output(args.outfile)

# Read in testing items, generate predictions for them
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)
コード例 #2
0
ファイル: maxent.py プロジェクト: rdaland/PhoMEnt
         help='Gaussian priors file name. If specified, maxent.py \
                uses the mu and sigma values in the file instead of \
                standard L1 and L2 priors to learn weights.')
args = parser.parse_args()

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

# Construct MegaTableau
mt = megatableau.MegaTableau(args.input_file_name)

# If weights are provided, return the probability of the tableau
if args.weights_file:
    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)