예제 #1
0
def learn_metal_cdtw(parentLabels, parent, childLabels, child, 
                     symmetric, squared, parameters=None):
    """learn optimal parameters for gem on metal data"""
    
    if parameters == None:
        parameters = np.array(range(21))*0.01
        
    errors = []
    

    for relative_window in parameters:
    
        window = int(np.round(len(parent[0])*relative_window))
    
        func = lambda query, subject: dist.cdtw(query, subject, window, squared)
        e, l = c.obtain_1NN_error(parentLabels, parent, 
                                  childLabels, child, func)
        errors.append((e, (relative_window, squared)))
        print errors[-1]
        
    errs = list(sorted(errors, key=lambda x: x[0][0]))
    
    # pick only the best and take parameter in the "middle"
    best = filter(lambda (x, y): x[0]==errs[0][0][0], errs)
    best.sort(key=lambda (x, y): y[0])
    best = best[len(best)/2]
   
    return best, errs
예제 #2
0
def learn_metal_cdtw(parentLabels,
                     parent,
                     childLabels,
                     child,
                     symmetric,
                     squared,
                     parameters=None):
    """learn optimal parameters for gem on metal data"""

    if parameters == None:
        parameters = np.array(range(21)) * 0.01

    errors = []

    for relative_window in parameters:

        window = int(np.round(len(parent[0]) * relative_window))

        func = lambda query, subject: dist.cdtw(query, subject, window, squared
                                                )
        e, l = c.obtain_1NN_error(parentLabels, parent, childLabels, child,
                                  func)
        errors.append((e, (relative_window, squared)))
        print errors[-1]

    errs = list(sorted(errors, key=lambda x: x[0][0]))

    # pick only the best and take parameter in the "middle"
    best = filter(lambda (x, y): x[0] == errs[0][0][0], errs)
    best.sort(key=lambda (x, y): y[0])
    best = best[len(best) / 2]

    return best, errs
예제 #3
0
def learn_metal_gem(parentLabels, parent, childLabels, child, 
                    symmetric, squared, parameters=None):
    """learn optimal parameters for gem on metal data"""
   
    if parameters == None:
        ST0 = [1, 2]
        ST1 = [1, 2]
        TAU = [0,0.00390625,0.0078125,0.015625,0.03125,0.0625,0.125,0.25,0.5]
    else:
        ST0, ST1, TAU = parameters
   
    errors = []
   
    for St0 in ST0:
        for St1 in ST1:
            for E in TAU :
                func = lambda query, subject: \
                       dist.gem(query, subject, St0, St1, E, symmetric, squared)
                e, l = c.obtain_1NN_error(parentLabels, parent, 
                                          childLabels, child, func)

                errors.append((e, (St0, St1, E, symmetric, squared)))
                print errors[-1]
                
    errs = list(sorted(errors, key=lambda x: x[0][0]))
    
    # pick only the best and take parameter in the "middle"
    best = filter(lambda (x, y): x[0]==errs[0][0][0], errs)
    best.sort(key=lambda (x, y): y[2])
    best = best[len(best)/2]
   
    return best, errs
예제 #4
0
def learn_metal_gem(parentLabels,
                    parent,
                    childLabels,
                    child,
                    symmetric,
                    squared,
                    parameters=None):
    """learn optimal parameters for gem on metal data"""

    if parameters == None:
        ST0 = [1, 2]
        ST1 = [1, 2]
        TAU = [
            0, 0.00390625, 0.0078125, 0.015625, 0.03125, 0.0625, 0.125, 0.25,
            0.5
        ]
    else:
        ST0, ST1, TAU = parameters

    errors = []

    for St0 in ST0:
        for St1 in ST1:
            for E in TAU:
                func = lambda query, subject: \
                       dist.gem(query, subject, St0, St1, E, symmetric, squared)
                e, l = c.obtain_1NN_error(parentLabels, parent, childLabels,
                                          child, func)

                errors.append((e, (St0, St1, E, symmetric, squared)))
                print errors[-1]

    errs = list(sorted(errors, key=lambda x: x[0][0]))

    # pick only the best and take parameter in the "middle"
    best = filter(lambda (x, y): x[0] == errs[0][0][0], errs)
    best.sort(key=lambda (x, y): y[2])
    best = best[len(best) / 2]

    return best, errs
예제 #5
0
 f.write("# gem ((error, size, error/size), (St0, St1, E, sym, sqr))\n")
 f.write("BESTLEARNCONSDTW=%s\n" % str(best_dtw))
 f.write("LISTLEARNCONSDTW=%s\n\n" % str(l_dtw))
 f.write("BESTLEARNGEM=%s\n" % str(best_gem))
 f.write("LISTLEARNGEM=%s\n\n" % str(l_gem))
 f.write("\n")
 
 print "######################### Calculate Errors ########################"
 
 # write error rates to logging file
 f.write("# error rates for different distance measures\n")
 f.write("# (error, size, error/size) and binary mask\n")
 
 # obtain error for lp-norm
 dist = ds.euc if squared else ds.man
 E, L = cl.obtain_1NN_error(testLabels, testSet, trainLabels, trainSet, dist)
 
 print "BESTLP=%s\n" % str(E)
 f.write("BESTLP=%s\n" % str(E))
 f.write("LISTLP=%s\n\n" % str(L))
 
 # obtain error for unconstrained dtw
 dist = lambda query, subject: ds.dtw(query, subject, squared)
 E, L = cl.obtain_1NN_error(testLabels, testSet, trainLabels, trainSet, dist)
 
 print "BESTFULLDTW=%s\n" % str(E)
 f.write("BESTFULLDTW=%s\n" % str(E))
 f.write("LISTFULLDTW=%s\n\n" % str(L))
 
 # obtain error for constrained dtw
 window = int(np.round(best_dtw[1][0]*len(trainSet[0])))
예제 #6
0
    f.write("# gem ((error, size, error/size), (St0, St1, E, sym, sqr))\n")
    f.write("BESTLEARNCONSDTW=%s\n" % str(best_dtw))
    f.write("LISTLEARNCONSDTW=%s\n\n" % str(l_dtw))
    f.write("BESTLEARNGEM=%s\n" % str(best_gem))
    f.write("LISTLEARNGEM=%s\n\n" % str(l_gem))
    f.write("\n")

    print "######################### Calculate Errors ########################"

    # write error rates to logging file
    f.write("# error rates for different distance measures\n")
    f.write("# (error, size, error/size) and binary mask\n")

    # obtain error for lp-norm
    dist = ds.euc if squared else ds.man
    E, L = cl.obtain_1NN_error(testLabels, testSet, trainLabels, trainSet,
                               dist)

    print "BESTLP=%s\n" % str(E)
    f.write("BESTLP=%s\n" % str(E))
    f.write("LISTLP=%s\n\n" % str(L))

    # obtain error for unconstrained dtw
    dist = lambda query, subject: ds.dtw(query, subject, squared)
    E, L = cl.obtain_1NN_error(testLabels, testSet, trainLabels, trainSet,
                               dist)

    print "BESTFULLDTW=%s\n" % str(E)
    f.write("BESTFULLDTW=%s\n" % str(E))
    f.write("LISTFULLDTW=%s\n\n" % str(L))

    # obtain error for constrained dtw
예제 #7
0
    f.write("BESTLEARNCONSDTWTWO=%s\n" % str(best_dtw_two))
    f.write("LISTLEARNCONSDTWTWO=%s\n\n" % str(l_dtw_two))  
    f.write("BESTLEARNGEMTWO=%s\n" % str(best_gem_two))
    f.write("LISTLEARNGEMTWO=%s\n\n" % str(l_gem_two))
    f.write("\n")
   

    print "######################### Calculate Errors ########################"
    
    # write error rates to logging file
    f.write("# error rates for different distance measures\n")
    f.write("# (error, size, error/size) and binary mask\n")
    
    # obtain error for lp-norm
    dist = ds.euc if squared else ds.man
    e, l = cl.obtain_1NN_error(parentLabels_one, zparent_one, 
                               childLabels_one, zchild_one, dist)
    
    print "BESTLPONE=%s\n" % str(e)
    f.write("BESTLPONE=%s\n" % str(e))
    f.write("LISTLPONE=%s\n\n" % str(l))
    
    dist = ds.euc if squared else ds.man
    e, l = cl.obtain_1NN_error(parentLabels_two, zparent_two, 
                               childLabels_two, zchild_two, dist)
    
    print "BESTLPTWO=%s\n" % str(e)
    f.write("BESTLPTWO=%s\n" % str(e))
    f.write("LISTLPTWO=%s\n\n" % str(l))
    
    
    # obtain error for unconstrained dtw
예제 #8
0
    f.write("LISTLEARNGEMONE=%s\n\n" % str(l_gem_one))
    f.write("BESTLEARNCONSDTWTWO=%s\n" % str(best_dtw_two))
    f.write("LISTLEARNCONSDTWTWO=%s\n\n" % str(l_dtw_two))
    f.write("BESTLEARNGEMTWO=%s\n" % str(best_gem_two))
    f.write("LISTLEARNGEMTWO=%s\n\n" % str(l_gem_two))
    f.write("\n")

    print "######################### Calculate Errors ########################"

    # write error rates to logging file
    f.write("# error rates for different distance measures\n")
    f.write("# (error, size, error/size) and binary mask\n")

    # obtain error for lp-norm
    dist = ds.euc if squared else ds.man
    e, l = cl.obtain_1NN_error(parentLabels_one, zparent_one, childLabels_one,
                               zchild_one, dist)

    print "BESTLPONE=%s\n" % str(e)
    f.write("BESTLPONE=%s\n" % str(e))
    f.write("LISTLPONE=%s\n\n" % str(l))

    dist = ds.euc if squared else ds.man
    e, l = cl.obtain_1NN_error(parentLabels_two, zparent_two, childLabels_two,
                               zchild_two, dist)

    print "BESTLPTWO=%s\n" % str(e)
    f.write("BESTLPTWO=%s\n" % str(e))
    f.write("LISTLPTWO=%s\n\n" % str(l))

    # obtain error for unconstrained dtw
    dist = lambda query, subject: ds.dtw(query, subject, squared)