Пример #1
0
def get_model(num_timesteps, num_input_vars, num_output_vars, p_params=None):
    params = dict(archtype='rnn',
                  optimizer='rmsprop',
                  discount=0.9,
                  hidden_layer_dims=[])

    if p_params:
        params.update(p_params)

    #params.update( dict(macro_dims=500, archtype='RNN',hidden_activation='leakyrelu') )
    #params.update( dict(macro_dims=500, hidden_activation='leakyrelu') ) # gets better than mean perfornace on ieee300
    #params.update( dict(macro_dims=trajs_trn.shape[2], archtype='RNNIdentity', hidden_activation='leakyrelu') ) # gets better than mean perfornace on ieee300
    #params.update( dict(macro_dims=trajs_trn.shape[2], archtype='RNNIdentity', hidden_activation='linear') ) # gets better than mean perfornace on ieee300
    #params.update( dict(macro_dims=500, hidden_activation='srelu') )# , hidden_layer_dims=[500,])


    model_name = "models/" + "_".join(["%s"%x[1] for x in sorted(params.items()) if x[1]]) + \
                 "-" + "-".join(map(str, [num_timesteps, num_input_vars, num_output_vars]))

    if False:
        # elsewhere...
        from keras.models import model_from_json
        with timeIt("Loading model object"):
            model = model_from_json(open('%s.json' % model_name).read())
            model.load_weights('%s_weights.h5' % model_name)
    else:
        with timeIt("Creating model object"):
            model = trainrnn.get_rnn_model(num_timesteps,
                                           num_input_vars,
                                           num_output_vars=num_output_vars,
                                           output_type='real',
                                           **params)

    model.model_name = model_name
    return model
Пример #2
0
def get_model(num_timesteps, num_input_vars, num_output_vars, p_params=None):
    params = dict(archtype='rnn',optimizer='rmsprop',discount=0.9, hidden_layer_dims=[])

    if p_params:
        params.update( p_params )

    #params.update( dict(macro_dims=500, archtype='RNN',hidden_activation='leakyrelu') ) 
    #params.update( dict(macro_dims=500, hidden_activation='leakyrelu') ) # gets better than mean perfornace on ieee300
    #params.update( dict(macro_dims=trajs_trn.shape[2], archtype='RNNIdentity', hidden_activation='leakyrelu') ) # gets better than mean perfornace on ieee300
    #params.update( dict(macro_dims=trajs_trn.shape[2], archtype='RNNIdentity', hidden_activation='linear') ) # gets better than mean perfornace on ieee300
    #params.update( dict(macro_dims=500, hidden_activation='srelu') )# , hidden_layer_dims=[500,]) 


    model_name = "models/" + "_".join(["%s"%x[1] for x in sorted(params.items()) if x[1]]) + \
                 "-" + "-".join(map(str, [num_timesteps, num_input_vars, num_output_vars]))

    if False:
        # elsewhere...
        from keras.models import model_from_json
        with timeIt("Loading model object"):
            model = model_from_json(open('%s.json'%model_name).read())
            model.load_weights('%s_weights.h5' % model_name)
    else:
        with timeIt("Creating model object"):
            model = trainrnn.get_rnn_model(num_timesteps, num_input_vars, num_output_vars=num_output_vars, output_type='real', **params)
    
    model.model_name = model_name
    return model
Пример #3
0
        if t == 0:
            if clocs is not None:
                if len(clocs) == 15:
                    yield np.vstack(df.Effs2.iloc[clocs])
            clocs = []
        clocs.append(ndx)
    if len(clocs) == 15:
        yield np.vstack(df.Effs2.iloc[clocs])


trajs = np.stack(split_mx(df))

import trainrnn
import logging
logging.getLogger('keras').setLevel(logging.INFO)
hidden_dims = 350

model = trainrnn.get_rnn_model(dshape=trajs.shape,
                               hidden_dims=hidden_dims,
                               output_type='real')

# model.fit(trajs, trajs, nb_epoch=100, batch_size=10, validation_split=0.1, show_accuracy=True, verbose=1)
#model.fit(trajs, trajs, nb_epoch=10, batch_size=5, validation_split=0.1, show_accuracy=True, verbose=1)
model.fit(trajs,
          trajs,
          nb_epoch=100,
          batch_size=1,
          validation_split=0.1,
          show_accuracy=True,
          verbose=1)
Пример #4
0
import numpy as np

df = pd.read_pickle('out1.pkl')
def split_mx(df):
    clocs = None
    for ndx, t in enumerate(df[df.PertId!=-1].t):
        if t == 0:
            if clocs is not None: 
                if len(clocs) == 15:
                    yield np.vstack(df.Effs2.iloc[clocs])
            clocs = []
        clocs.append(ndx)
    if len(clocs) == 15:
        yield np.vstack(df.Effs2.iloc[clocs])
    
trajs = np.stack(split_mx(df))


import trainrnn
import logging    
logging.getLogger('keras').setLevel(logging.INFO)
hidden_dims = 350

model = trainrnn.get_rnn_model(dshape=trajs.shape, hidden_dims=hidden_dims, output_type='real')


# model.fit(trajs, trajs, nb_epoch=100, batch_size=10, validation_split=0.1, show_accuracy=True, verbose=1)
#model.fit(trajs, trajs, nb_epoch=10, batch_size=5, validation_split=0.1, show_accuracy=True, verbose=1)
model.fit(trajs, trajs, nb_epoch=100, batch_size=1, validation_split=0.1, show_accuracy=True, verbose=1)