def make_hamiltonian(hamiltonian_type, tau_long, ML_param):

    if hamiltonian_type == 'noML':
        hamiltonian_obj = noML_hamiltonian()

    elif hamiltonian_type == 'pairwise_HNN':
        net1 = mlp_net(ML_param.layer_list, ML_param.dropout_list)
        net2 = mlp_net(ML_param.layer_list, ML_param.dropout_list)
        hamiltonian_obj = pairwise_HNN(net1, net2, ML_param.on_off_noML)
        hamiltonian_obj.set_tau_long(tau_long)

    elif hamiltonian_type == 'fields_HNN':
        net1 = mlp_net(ML_param.layer_list, ML_param.dropout_list)
        net2 = mlp_net(ML_param.layer_list, ML_param.dropout_list)
        hamiltonian_obj = fields_HNN(net1, net2, ML_param.dgrid,
                                     ML_param.ngrid, ML_param.on_off_noML)
        hamiltonian_obj.set_tau_long(tau_long)

    else:
        assert (False), 'invalid hamiltonian type given'

    return hamiltonian_obj
def make_hamiltonian(hamiltonian_type, tau_long, ML_param):

    pwnet1 = mlp_net(ML_param.pw_layer_list, ML_param.dropout_list)
    pwnet2 = mlp_net(ML_param.pw_layer_list, ML_param.dropout_list)
    pwhamiltonian_obj = pairwise_HNN(pwnet1, pwnet2, ML_param.on_off_noML)
    pwhamiltonian_obj.set_tau_long(tau_long)
    fnet1 = mlp_net(ML_param.f_layer_list, ML_param.dropout_list)
    fnet2 = mlp_net(ML_param.f_layer_list, ML_param.dropout_list)
    fhamiltonian_obj = fields_HNN(fnet1, fnet2, ML_param.dgrid, ML_param.ngrid,
                                  ML_param.on_off_noML)
    fhamiltonian_obj.set_tau_long(tau_long)

    if hamiltonian_type == 'noML':
        return noML_hamiltonian()
    elif hamiltonian_type == 'pairwise_HNN':
        return pwhamiltonian_obj
    elif hamiltonian_type == 'fields_HNN':
        return fhamiltonian_obj
    elif hamiltonian_type == 'fields_pairwise_HNN':
        fpwhamiltonian_obj = fields_pairwise_HNN(fhamiltonian_obj,
                                                 pwhamiltonian_obj)
        return fpwhamiltonian_obj
    else:
        assert (False), 'invalid hamiltonian type given'
示例#3
0
import json
import torch
import math

if __name__ == '__main__':

    '''python check_gen_by_mc2.py jsonfile1.dict'''

    argv = sys.argv
    json_file = argv[1]

    with open(json_file) as f:
        data = json.load(f)

    phase_space = phase_space()
    hamiltonian_obj = noML_hamiltonian()

    filelist = data['filelist']

    init_e1 = {}
    ke1 = {}
    p_dist1 = {}
    init_u1 = {}
    u1 = {}
    f1_magnitude1 = {}
    rho = [0.10, 0.14, 0.2, 0.27, 0.38]

    for i in range(len(filelist)):

        infile = torch.load(filelist[i])
示例#4
0
    # io varaiables
    filename = MC_parameters.filename

    # seed setting
    np.random.seed(seed)
    random.seed(seed)
    torch.manual_seed(seed)

    torch.set_default_dtype(torch.float64)

    _ = system_logs(mydevice)
    system_logs.print_start_logs()

    data_io_obj = data_io()
    phase_space = phase_space.phase_space()
    noMLhamiltonian = noML_hamiltonian()

    metropolis_mc = metropolis_mc(system_logs)

    q_hist, U, ACCRatio, spec = metropolis_mc.step(noMLhamiltonian,
                                                   phase_space)

    # take q every interval
    q_hist = q_hist[:, 0::interval, :, :]
    # shape is  [mc nsamples, mc interval step, nparticle, DIM]
    q_hist = torch.reshape(q_hist, (-1, q_hist.shape[2], q_hist.shape[3]))
    # shape is  [(mc nsamples x mc step), nparticle, DIM]

    # momentum sampler
    momentum_sampler = momentum_sampler(q_hist.shape[0])
    p_hist = momentum_sampler.momentum_samples()