def getUncertaintyRankings(model, data, forward=True):
    embeds = []
    for i in range(10):
        bn = buildNetwork(seed=i,dropout=np.random.random(1)[0])
        m = bn.build(data[0], data[-1])
        m = bn.compiler(m,q_net=False,actor=False)
        embeds.append(forwardPass(m, data[0], len(model.layers)-1))
    
    stacked = np.stack(embeds, axis=-1)
    variance = []
    for i in range(len(stacked)):
        variance.append(np.var(stacked[:,0:1][i][0]))
    
    variance = pd.DataFrame(variance)
    variance = variance.sort_values(0, ascending=forward)
    
    return variance
Exemplo n.º 2
0
def vanillaCurriculum(model, batches, outs, data, recursion, plot=True):
    for curric in ('m', 'c', 'w'):
        bn = buildNetwork()
        model = bn.build(data[0], pd.DataFrame(uniques))
        model = bn.compiler(model, q_net=False, actor=False)
        training_loss = []
        validation_loss = []
        training_acc = []
        validation_acc = []
        embs = dict()
        embs[0] = getEmbeddeds(model, batches)
        for r in range(repetitions):
            model, l, a, va_l, va_a = train(model,
                                            batches,
                                            outs,
                                            data[2],
                                            data[3],
                                            curriculum=curric,
                                            recurs=1000)
            embs[r + 1] = getEmbeddeds(model, batches)
            training_loss.append(l)
            validation_loss.append(va_l)
            training_acc.append(a)
            validation_acc.append(va_a)

        validation_acc = flattenList(validation_acc)
        training_acc = flattenList(training_acc)
        training_loss = flattenList(training_loss)
        validation_loss = flattenList(validation_loss)

        if plot:
            plt.plot(validation_acc)
            plt.ylabel("validation accuracy")
            plt.xlabel("Iteration")
            plt.legend(['m', 'c', 'w'])
            plt.show()

            plt.plot(validation_loss)
            plt.ylabel("validation loss")
            plt.xlabel("Iteration")
            plt.legend(['m', 'c', 'w'])
            plt.show()
Exemplo n.º 3
0
            curric = curric.sort_values(0, ascending=False)
        else:
            curric = curric.sort_values(0)
        for batch in range(numbatches):
            if cumulative == True:
                ba[batch] = datas[0].iloc[0:(batch+1)*k]
            else:
                ba[batch] = datas[0].iloc[batch*k:(batch+1)*k]
            ou = datas[1].iloc[ba[batch].index]
        batches[i] = ba
        outs[i] = ou
    
    return batches, outs
    
data = loadData()
uniques = data[-1]
datas = dict()
for z in range(len(data)):
    datas[z] = toDataframe(data[z])

ma, co, wa = getRankings(datas[0])

batches, outs = createBatches(datas, 10, False)

bn = buildNetwork()
model = bn.build(data[0],pd.DataFrame(uniques))
model = bn.compiler(model, q_net=False, actor=False)