Exemplo n.º 1
0
def run_test2_2(l, IT, LAMBDA = 1,smalls=False, pens=False ):
    #run_logistics(l = 0.17, IT = 500, LAMBDA = 0.01,smalls=False, pens=False):

    res = logistic_regression_template.run_logistics(l,IT,LAMBDA,smalls, pens)
    print "learnigrate:{}".format(l)
    stat_msg = "TRAIN NLOGL:{:4.2f}  TRAIN CE:{:.6f}  "
    stat_msg += "TRAIN FRAC:{:2.2f}  VALID CE:{:.6f}  VALID FRAC:{:2.2f}"
    stat_msg += "iteration at max frac train:{}  iteration at max frac valid:{}  \n iteration at min CE valid:{}"
    print stat_msg.format(res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7])

    # res[8] is training CE, res[9] is valid CE
    fig_train = plt.plot(np.arange(0, IT), res[8], 'g')
    fig_valid = plt.plot(np.arange(0, IT), res[9], 'b')
    plt.axis([0, IT, 0, 150])
    plt.xlabel('Iteration')
    plt.ylabel('CE')
    gtitle = '''CE as function of the iter number on mnist_train, \n
                    Learning rate: {}, Number of iterations: IT \n green:=train, blue:=validation'''
    plt.title(gtitle.format(l,IT))
    plt.show()
Exemplo n.º 2
0
def run_test2_3(l,IT,smalls):
    final_results = [[],[],[],[],[]]
    for lam in [0.001, 0.01, 0.1, 0.5, 0.8, 1.0]:
    #for lam in [0.001, 0.01, 0.02]:

        res = np.zeros(shape=(5, ))
        res[0] = lam
        for it in range(10):
            tres = logistic_regression_template.run_logistics(l,IT,lam,smalls, True)

            res[1] += tres[1]
            res[2] += tres[2]
            res[3] += tres[3]
            res[4] += tres[4]

        avg_res = res / 10.0
        avg_res[0] *= 10.0

        print  "for Lambda = {} the average results are: \n train CE:{},    train class err:{}," \
               "    valid CE:{},    valid calss err:{}".format(lam, avg_res[1], avg_res[2], avg_res[3],avg_res[4])

        for i in range(5):
            final_results[i].append(avg_res[i])
    plot2_3(l,IT,smalls,final_results)