コード例 #1
0
def simulacao(input_dim,
              num_samples,
              sparseness,
              learning_rate,
              model_seed,
              data_seed,
              nsteps=1000,
              max_count=100):

    acc = np.zeros(nsteps + 1)
    myDataSet = buildRandomBoolDataSet(num_samples, input_dim,
                                       seed=data_seed).batch(num_samples)

    myIter = myDataSet.make_initializable_iterator()
    myFeatures, myLabels = myIter.get_next()
    x = myFeatures
    y_ = myLabels
    model = Model(x, y_, sparseness, learning_rate, seed=model_seed)
    model.set_vanilla_loss()
    # initialize variables
    sess.run(tf.global_variables_initializer())
    sess.run(myIter.initializer)
    acc[0] = model.accuracy.eval()
    count = 1
    for ss in np.arange(1, nsteps + 1):
        sess.run(myIter.initializer)
        model.reduce_sparsness()
        model.train_step.run()
        model.increase_sparsness()
        sess.run(myIter.initializer)
        acc[ss] = model.accuracy.eval()
        if (acc[ss] == acc[ss - count]):
            count += 1
        else:
            count = 1
        if (count == max_count):
            acc[ss:] = acc[ss]
            break

    return acc
コード例 #2
0
            y_ = myLabels
            #model = Model(x, y_, spars, 0.1) # simple 2-layer network
            #print("data_seed")
            #print(data_seed)

            model = Model(x, y_, sparseness, learning_rate,
                          seed=data_seed)  # simple 2-layer network
            model.set_vanilla_loss()
            # initialize variables
            sess.run(tf.global_variables_initializer())
            sess.run(myIter.initializer)
            #acc[0] = model.accuracy.eval()
            count = 1
            for ss in np.arange(1, nsteps + 1):
                sess.run(myIter.initializer)
                model.reduce_sparsness()
                model.train_step.run()
                #model.aumenta spar
                sess.run(myIter.initializer)
                #acc[ss] = model.accuracy.eval()

                acc[zz, ii, jj] = model.accuracy.eval()

sess.close()

# %%

ax = plt.subplot(111)
#plt.plot(acc[:,:,0])
for zz, sparseness in enumerate(sparse):
    plt.plot(num_samplesV,