예제 #1
0
def main_with_validation(fileName, intercept=False, evalFunc = Util.brierScore):
    trainX, trainY, testX, testY = Util.readData(fileName, intercept=intercept)
        
    clf = GLS()
    regs = np.logspace(-3, 3, 7)
    xis = np.linspace(-1., 1.5, 26)
    bestScore, bestXi, bestReg = 1e10, None, None

    for xi in xis:
        clf.setXi(xi)
        print("Current xi = ", xi)
        score, reg = Util.crossValidate(clf, trainX, trainY, \
                                        evalFunc, 5, "Regular", regs)
        if score < bestScore:
            bestScore, bestXi, bestReg = score, xi, reg
    print("bestScore, bestXi, bestReg = ", bestScore, bestXi, bestReg)
    clf.setXi(bestXi)
    clf.setRegular(bestReg)
    clf.fit(trainX, trainY)
    testScore = evalFunc(clf.predict(testX), testY)
    with open("log/GLS_final_log.txt", 'a') as f:
        log = ','.join([dt.now().strftime("%Y/%m/%d %H:%M"), str(fileName), \
                        str(bestReg), str(bestXi), str(intercept), \
                        evalFunc.__name__, str(bestScore), str(testScore)])
        f.write(log + '\n')
예제 #2
0
def main_label(fileName, xi, preproc=False, evalFunc = Util.f1):
    data = np.loadtxt(fname=fileName, delimiter=",")
    scoreList = []
    clf = GLS()
    clf.setXi(xi)
    k = 10
    
    for _ in range(k):
        trainX, trainY, testX, testY = Util.readData(data, False, preproc)
        clf.fit(trainX, trainY)
        s = evalFunc(Util.probToLabel(clf.predict(testX)), testY)
        print("score = ", s)
        scoreList.append(s)
    print("mean score = ", sum(scoreList)/k)
예제 #3
0
def main_prob(fileName, xi, preproc=False, evalFunc = Util.brierScore):
    data = np.loadtxt(fname=fileName, delimiter=",")
    scoreList = []
    clf = GLS()
    clf.setXi(xi)
    k = 10
    
    for _ in range(k):
        trainX, trainY, testX, testY = Util.readData(data, False, preproc)
        clf.fit(trainX, trainY)
        s = evalFunc(clf.predict(testX), testY)
        print("score = ", s)
        scoreList.append(s)
    score = sum(scoreList)/k
    print("mean score = ", score)
    with open("log/GLS_test_log.txt", 'a') as f:
        log = ','.join([dt.now().strftime("%Y/%m/%d %H:%M"), str(fileName), \
                        str(preproc), evalFunc.__name__, str(score)])
        f.write(log + '\n')
예제 #4
0
for problema in problemas:
    for i in problema:
        s = []
        inicial_r = FLSol(i)
        if (inicial_r.M > 100):
            continue
        print(i.nome)
        print("N:", inicial_r.N, " M:", inicial_r.M)

        hc = HC()
        vnd = VND()
        rms = RMS()
        ils = ILS()
        vns = VNS()
        sa = SA()
        gls = GLS()
        ag = AG()
        grasp = GRASP()

        # Ponto inicial guloso
        inicial_g = FLSol(i)
        tempo = time.perf_counter()
        inicial_g.build_greedy()
        sb = cp.deepcopy(inicial_g)
        tempo = time.perf_counter() - tempo
        s.append(["PTG", sb.avaliacao(), tempo])

        # # Ponto inicial Randomico
        tempo = time.perf_counter()
        inicial_r.build_random()
        tempo = time.perf_counter() - tempo