rfho/examples/data_hypercleaner.py
def baseline(saver, model, y, data, T, lr, lmd=None, name='baseline'):
    # TODO other optimizers?
    """
    BASELINE EXECUTION (valid also for oracle and final training,
    with optimized values of lambda)

    :param saver: `Saver` object (can be None)
    :param name: optional name for the saver
    :param data: `Datasets` object
    :param T: number of iterations
    :param lmd: weights for the examples, if None sets to 1.
    :param model: a model (should comply with `rf.Network`)
    :param y: placeholder for output
    :param lr: learning rate
    :return:
    """
    # if saver: saver.save_setting(vars(), append_string=name)
    x = model.inp[0]

    # def _train_and_valid_s():
    #     return {x: np.vstack((data.train.data, data.validation.data)),
    #             y: np.vstack((data.train.target, data.validation.target))}
    train_and_valid = rf.datasets.Dataset.stack(data.train, data.validation)
    train_and_valid_s = train_and_valid.create_supplier(x, y)

    tst_s = data.test.create_supplier(x, y)

    if lmd is None: lmd = np.ones(train_and_valid.num_examples)

    error2 = tf.reduce_mean(lmd * rf.cross_entropy_loss(y, model.out))
    correct_prediction2 = tf.equal(tf.argmax(model.out, 1), tf.argmax(y, 1))
    accuracy2 = tf.reduce_mean(tf.cast(correct_prediction2, "float"))

    opt = tf.train.GradientDescentOptimizer(lr)
    ts1 = opt.minimize(error2, var_list=model.var_list)

    # saver related
    if saver:
        saver.clear_items()
        saver.add_items(
            'Test Accuracy', accuracy2, tst_s,
        )

    with tf.Session(config=rf.CONFIG_GPU_GROWTH).as_default():
        tf.variables_initializer(model.var_list).run()
        for _ in range(T):
            ts1.run(feed_dict=train_and_valid_s())
        if saver: saver.save(name)
        baseline_test_accuracy = accuracy2.eval(feed_dict=tst_s())
        return baseline_test_accuracy

    BASELINE EXECUTION (valid also for oracle and final training,
    with optimized values of lambda)

    :param saver: `Saver` object (can be None)
    :param name: optional name for the saver
    :param data: `Datasets` object
    :param T: number of iterations
    :param lmd: weights for the examples, if None sets to 1.
    :param model: a model (should comply with `rf.Network`)
    :param y: placeholder for output
    :param lr: learning rate
    :return:
    
BASELINE EXECUTION (valid also for oracle and final training,
with optimized values of lambda)
BASELINE EXECUTION ( valid also for oracle and final training with optimized values of lambda )
def baseline(saver, model, y, data, T, lr, lmd=None, name='baseline'):
    x = model.inp[0]
    train_and_valid = rf.datasets.Dataset.stack(data.train, data.validation)
    train_and_valid_s = train_and_valid.create_supplier(x, y)
    tst_s = data.test.create_supplier(x, y)
    if lmd is None: lmd = np.ones(train_and_valid.num_examples)
    error2 = tf.reduce_mean(lmd * rf.cross_entropy_loss(y, model.out))
    correct_prediction2 = tf.equal(tf.argmax(model.out, 1), tf.argmax(y, 1))
    accuracy2 = tf.reduce_mean(tf.cast(correct_prediction2, "float"))
    opt = tf.train.GradientDescentOptimizer(lr)
    ts1 = opt.minimize(error2, var_list=model.var_list)
    if saver:
        saver.clear_items()
        saver.add_items(
            'Test Accuracy', accuracy2, tst_s,
        )
    with tf.Session(config=rf.CONFIG_GPU_GROWTH).as_default():
        tf.variables_initializer(model.var_list).run()
        for _ in range(T):
            ts1.run(feed_dict=train_and_valid_s())
        if saver: saver.save(name)
        baseline_test_accuracy = accuracy2.eval(feed_dict=tst_s())
        return baseline_test_accuracy
def baseline ( saver , model , y , data , T , lr , lmd = None , name = 'baseline' ) : x = model . inp [ 0 ] train_and_valid = rf . datasets . Dataset . stack ( data . train , data . validation ) train_and_valid_s = train_and_valid . create_supplier ( x , y ) tst_s = data . test . create_supplier ( x , y ) if lmd is None : lmd = np . ones ( train_and_valid . num_examples ) error2 = tf . reduce_mean ( lmd * rf . cross_entropy_loss ( y , model . out ) ) correct_prediction2 = tf . equal ( tf . argmax ( model . out , 1 ) , tf . argmax ( y , 1 ) ) accuracy2 = tf . reduce_mean ( tf . cast ( correct_prediction2 , "float" ) ) opt = tf . train . GradientDescentOptimizer ( lr ) ts1 = opt . minimize ( error2 , var_list = model . var_list ) if saver : saver . clear_items ( ) saver . add_items ( 'Test Accuracy' , accuracy2 , tst_s , ) with tf . Session ( config = rf . CONFIG_GPU_GROWTH ) . as_default ( ) : tf . variables_initializer ( model . var_list ) . run ( ) for _ in range ( T ) : ts1 . run ( feed_dict = train_and_valid_s ( ) ) if saver : saver . save ( name ) baseline_test_accuracy = accuracy2 . eval ( feed_dict = tst_s ( ) ) return baseline_test_accuracy
BASELINE EXECUTION (valid also for oracle and final training,
with optimized values of lambda)
BASELINE EXECUTION ( valid also for oracle and final training with optimized values of lambda )
# TODO other optimizers? """
    BASELINE EXECUTION (valid also for oracle and final training,
    with optimized values of lambda)

    :param saver: `Saver` object (can be None)
    :param name: optional name for the saver
    :param data: `Datasets` object
    :param T: number of iterations
    :param lmd: weights for the examples, if None sets to 1.
    :param model: a model (should comply with `rf.Network`)
    :param y: placeholder for output
    :param lr: learning rate
    :return:
    """ # if saver: saver.save_setting(vars(), append_string=name) # def _train_and_valid_s(): #     return {x: np.vstack((data.train.data, data.validation.data)), #             y: np.vstack((data.train.target, data.validation.target))} # saver related
None
saver
`Saver` object (can be None)
` Saver ` object ( can be None )
model
a model (should comply with `rf.Network`)
a model ( should comply with ` rf . Network ` )
y
placeholder for output
placeholder for output
data
None
T
number of iterations
number of iterations
lr
None
lmd
weights for the examples, if None sets to 1.
weights for the examples if None sets to 1 .
name
optional name for the saver
optional name for the saver