Esempio n. 1
0
    def train(self, sess, num_epochs=20):
        """
        Remember to initialize all variables outside this method
        """
        batch_size = self.batch_size
        # Placeholder for some more summaries that may be of interest.
        merged_summaries = tf.summary.merge([self.loss_summ])
        self.writer = tf.summary.FileWriter(addDateTime('./logs/log'))

        Ytrain = self.to_one_hot(self.data_dict['Ytrain'], self.yDim)
        Xtrain = self.data_dict['Xtrain']
        Yvalid = self.to_one_hot(self.data_dict['Yvalid'], self.yDim)
        Xvalid = self.data_dict['Xvalid']
        for ep in range(num_epochs):
            num_batches = len(Xtrain) // batch_size
            for idx in range(0, num_batches):
                batch_images = Xtrain[idx * batch_size:(idx + 1) * batch_size]
                batch_labels = Ytrain[idx * batch_size:(idx + 1) * batch_size]

                _, loss, summaries = sess.run(
                    [self.train_op, self.loss, merged_summaries],
                    feed_dict={
                        'FOURIER/X:0': batch_images,
                        'FOURIER/Y:0': batch_labels
                    })
                if (idx * 10) // num_batches > ((idx - 1) * 10) // num_batches:
                    print((100 * idx) // num_batches, '% processed...')

            self.writer.add_summary(summaries, ep)
            print('Ep, cost:', ep, loss)
            ypred = sess.run(tf.nn.softmax(self.output),
                             feed_dict={'FOURIER/X:0': Xtrain[:100]})
            ypred = self.nptensorfloat_to_one_hot(ypred)
            accuracy = np.sum(ypred * Ytrain[:100]) / 100
            print('Accuracy', accuracy)

            if ep % 50 == 0:
                Ypred_valid = sess.run(self.output,
                                       feed_dict={'FOURIER/X:0': Xvalid[:100]})
                Ypred_valid = self.nptensorfloat_to_one_hot(Ypred_valid)
                accuracy = np.sum(Ypred_valid * Yvalid[:100]) / 100
                print('Accuracy', accuracy)
Esempio n. 2
0
def main(_):
    """
    Launches this whole zingamajinga.
    """
    data_path = params.local_data_dir + params.this_data_dir
    rlt_dir = params.local_rlt_dir + params.this_data_dir + addDateTime() + '/'
    if params.mode == 'generate':
        generate_fake_data(lat_mod_class=params.lat_mod_class,
                           gen_mod_class=params.gen_mod_class,
                           params=params,
                           data_path=data_path,
                           save_data_file=params.save_data_file,
                           Nsamps=params.genNsamps,
                           NTbins=params.genNTbins,
                           write_params_file=True,
                           draw_quiver=True,
                           draw_heat_maps=True,
                           savefigs=True)
    if params.mode == 'train':
        graph = tf.Graph()
        with graph.as_default():
            sess = tf.Session(graph=graph)
            with sess.as_default():
                with open(data_path + params.save_data_file, 'rb+') as f:
                    # Set encoding='latin1' for python 2 pickled data
                    datadict = pickle.load(
                        f,
                        encoding='latin1') if params.is_py2 else pickle.load(f)
                    Ytrain = datadict['Ytrain']
                    Yvalid = datadict['Yvalid']

                params.yDim = Ytrain.shape[-1]

                if not os.path.exists(rlt_dir): os.makedirs(rlt_dir)
                write_option_file(rlt_dir)

                opt = Optimizer_TS(params)

                sess.run(tf.global_variables_initializer())
                opt.train(sess, rlt_dir, Ytrain, Yvalid)
Esempio n. 3
0
def main(_):
    """
    Fly babe!
    """
    data_path = params.local_data_dir + params.this_data_dir
    rlt_dir = (params.local_rlt_dir + params.this_data_dir + addDateTime() +
               '/' if not params.restore_from_ckpt else params.load_ckpt_dir)
    if params.mode == 'generate':
        generate_fake_data(params,
                           data_path=data_path,
                           save_data_file=params.save_data_file)
    elif params.mode == 'train':
        sess = tf.Session()
        with sess.as_default():
            train(params, data_path, rlt_dir)
    elif params.mode == 'other':
        with open(data_path + params.save_data_file, 'rb+') as f:
            # Set encoding='latin1' for python 2 pickled data
            datadict = pickle.load(
                f, encoding='latin1') if params.is_py2 else pickle.load(f)
            print(sorted(datadict.keys()))
        other(datadict, data_path)
Esempio n. 4
0
from lasagne.nonlinearities import softmax, linear, softplus, tanh, sigmoid
from lasagne.layers import InputLayer, DenseLayer
from lasagne.init import Orthogonal, Uniform, Normal

# Local imports
import vind
from code.ObservationModels import GaussianObsTSGM, PoissonObsTSGM
from code.LatEvModels import LocallyLinearEvolution

from code.RecognitionModels import SmoothingNLDSTimeSeries
from code.OptimizerVAEC_TS import VAEC_NLDSOptimizer

# from MinibatchIterator import DatasetTrialIterator

from code.datetools import addDateTime
cur_date = addDateTime()

#=== GLOBALS ===#
# AS A USER YOU SHOULD BE ABLE TO GET THIS RUNNING JUST BY CHANGING THESE
# PLEASE READ THE HELP ON EACH OF THESE OPTIONS IN THE PARSER.

### HARDWARE, META
CLUSTER = 0
EXTERNAL_DATA = 1

### DATA  PATHS, ETC ###
LOCAL_DATA_ROOT = "data/"
THIS_DATA_DIR = "poisson_data_002" #  lorenzdata004
IS_DICT = 1
DATA_FILE = 'datadict'
TEST_FILE = None
Esempio n. 5
0
import os
import pickle

import matplotlib
matplotlib.use('Agg')

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

import tensorflow as tf

from code.Optimizer_VAEC import Optimizer_TS
from code.datetools import addDateTime

# DATA_FILE = '/Users/danielhernandez/work/supervind/data/poisson002/datadict'
DATA_FILE = '/Users/danielhernandez/work/vind/data/poisson_data_002/datadict'
RLT_DIR = "/Users/danielhernandez/work/supervind/rslts/poisson002/fit" + addDateTime(
) + '/'
if not os.path.exists(RLT_DIR): os.makedirs(RLT_DIR)

# For information on these parameters, see runner.py
flags = tf.app.flags
flags.DEFINE_integer('yDim', 10, "")
flags.DEFINE_integer('xDim', 2, "")
flags.DEFINE_float('learning_rate', 2e-3, "")
flags.DEFINE_float('initrange_MuX', 0.2, "")
flags.DEFINE_float('initrange_B', 3.0, "")
flags.DEFINE_float('init_Q0', 0.4, "")
flags.DEFINE_float('init_Q', 1.0, "")
flags.DEFINE_float('alpha', 0.2, "")
flags.DEFINE_float('initrange_outY', 3.0, "")
flags.DEFINE_float('initrange_LambdaX', 1.0, "")
params = tf.flags.FLAGS