Exemplo n.º 1
0
#GPy parameters
kernel = 'Matern52'
lengthscale = 1.
multi_dim = True #Use multi-dimensional (16) 

generate_tags = ['sgt' + str(energy[0]) + '-' +  str(energy[1]), 'validation' + str(samples),
                 'single_lec_E_curve50/50' + str(lec_sampling) + str(lec_index)]


# Set up necessary classes)
param = Parameters(interval, samples, center_lecs=lec_center)
nsopt = NsoptCaller()
gauss = Gaussfit()
dm = Datamanager(echo=False)

if dm.num_matches(generate_tags) > 0:
    answer = raw_input('Matching data for your tags already exist, add new data as well? (y for yes): ')
    if answer == 'y':
        continue_generate = True

def get_observable(energies, lecs):
    """Wrapper function to measure time with memory profiler."""
    return nsopt.get_nsopt_observable(energies,LECM=lecs)

param.nbr_of_samples = samples
if lec_sampling == 'lhs':
    print('lhs')
    lecs = param.create_lhs_lecs(energy_interval=energy)
    energies = lecs[:,-1]
    lecs = lecs[:,0:-1]
        
from parameters import Parameters
from nsoptcaller import NsoptCaller
from gaussfit import Gaussfit
from datamanager import Datamanager
#from memory_profiler import profile
import numpy as np
import pickle

param = Parameters(interval, samples, center_lecs=lec_center)
nsopt = NsoptCaller()
gauss = Gaussfit()
dm = Datamanager(echo=False)
gauss.save_fig = save_fig
gauss.save_path = save_path

if dm.num_matches(training_tags) <= 0 or dm.num_matches(validation_tags) <= 0:
    sys.exit('Check your tags. No matched found in database.')
else:
    #Set empty arrays with zeros for training and validation data
    train_obs = np.array([0])
    train_energy = np.array([0])
    train_lecs = np.array(np.zeros(LEC_LENGTH))

    #Read database data with the specified tags
    for row in dm.read(training_tags):
        train_obs = np.vstack((train_obs, row.observable))
        train_energy = np.vstack((train_energy, row.energy))
        train_lecs = np.vstack((train_lecs, row.LECs))

    # Clean up initialized zeros
    train_obs = np.delete(train_obs, 0, 0)
Exemplo n.º 3
0
    return nsopt.get_nsopt_observable(energies,LECM=lecs)

@profile
def train_gp_model(train_obs, train_lecs):
    """Populate and optimize GP model."""
    gauss.populate_gp_model(train_obs, train_lecs, rescale=rescale_data)
    gauss.optimize()
    
@profile
def calculate_valid(val_lecs):
    """Wrapper function to measure time with memory profiler."""
    mod_obs, mod_var = gauss.calculate_valid(val_lecs)
    return mod_obs, mod_var

# Check if data tags is already in database
if generate_data and dm.num_matches(generate_tags) <= 0:
    continue_generate = True
elif generate_data and dm.num_matches(generate_tags) > 0:
    answer = raw_input('Matching data for your tags already exist, add new data as well? (y for yes): ')
    if answer == 'y':
        continue_generate = True
else:
    continue_generate = False

# Generate 
if continue_generate:
    param.nbr_of_samples = samples
    
    if lec_sampling == 'lhs':
        print('lhs')
        if energy_as_param:     # Do we want to have energies samples as well?