예제 #1
0
def compare(args):
    print "Inside compare with args:"
    print 'First: {0}'.format(args.first)
    print 'Second: {0}'.format(args.second)
    compr = Comparator(args.first, args.second)
    return compr.compare()
    pass
예제 #2
0
파일: main.py 프로젝트: artem-sokolov/bio
def compare():
    t0 = time.clock()
    print("Beginning comparison...")
    comparator = Comparator("/home/arts/Documents/originalReads", "/home/arts/Documents/alignedReads", "/home/arts/Documents/correctedReads.gz",
                            "/home/arts/Documents/failedToAlignReads", "/home/arts/Documents/report")
    comparator.compare()
    print("Comparison finished. Took: %s." % (time.clock() - t0))
    return None
예제 #3
0
def runGenerator(args):

	generator = Generator(args.n, args.l, args.d)

	profiles = generator.generate_profiles()

	comparator = Comparator(profiles)
	
	print 'Prim:'
	print comparator.goeBURST('prim')
	print 'Kruskal:'
	print comparator.goeBURST('kruskal')
예제 #4
0
def main():
    start_state = State([
        0, 2, 3,
        4, 6, 1,
        7, 5, 8
    ])
    goal_state = State([
        1, 2, 3,
        4, 5, 6,
        7, 8, 0
    ])
    comparator = Comparator(goal_state)
    start = time.time()
    result = ids(start_state, goal_state)
    # result = a_star(start_state, goal_state, comparator)
    end = time.time()
    totaltime = end - start
    if result is None:
        print("No solution found")
    elif result == []:
        print("Start node was the goal!")
    else:
        print("The number of nodes visited", result.get("number_of_nodes_visited"))
        print("Max number of nodes stored in memory:", result.get("max_number_of_nodes"))
        print("including:")
        print("  ", result.get('number_of_explored'), "explored nodes")
        print("  ", result.get('number_of_nodes'), "nodes that have to be explored")
        print(f"Number of moves: {len(result.get('path_from_start'))}")
        print("States of moves are as follows:", result.get("path_from_start"))
    print(f"Total searching time: {round(totaltime, 5)} seconds")
예제 #5
0
 def run(self):
     futils = FileUtils(filename="./data/normalized_training_data_2.csv",
                        skip_header=True,
                        whitespace_delim=True)
     comp = Comparator(reference_dict=futils.get_arrays_from_csv(),
                       start_comparison_col=2)
     predictions = []
     test_file = FileUtils(filename="./data/normalized_test_data_2.csv",
                           skip_header=True,
                           whitespace_delim=True)
     for test_record in test_file.get_arrays_from_csv():
         match = comp.get_closes_match(test_record)
         print("Closes match for {0} is {1}".format(test_record, match))
         predictions.append("{0},{1}".format(int(test_record[0]),
                                             int(match[1])))
     for p in predictions:
         print(p)
예제 #6
0
    def Solve(self, problem):

        print("Starting Solver for problem %s\n" % problem.name)

        processor = VisualProcessor(problem.figures, problem.problemType)
        compare = Comparator(processor)
        compare.CreateGraphNodes()
        proposedAnswers = compare.GetSolutions()

        if proposedAnswers == None or len(proposedAnswers) <= 0:
            return -1

        answers = []
        for answer in proposedAnswers:
            ans = proposedAnswers[answer][0]
            val = proposedAnswers[answer][1]
            print "\tAnswer for " + answer + " method: [" + str(
                ans) + ", " + str(val) + "]"
            answers.append(proposedAnswers[answer][0])

        answerCounts = []
        for i in range(0, processor.numAnswers):
            answerCounts.append(answers.count(i))
        #solver.OutputImageCombinations(problem.name)

        if np.all(np.array(answerCounts) <= 1):
            return -1

        maxCounts = np.max(answerCounts)
        indexes = np.argwhere(answerCounts == maxCounts)
        indexes = list(indexes.flatten())

        if len(indexes) > 1:
            return -1
            #bestAns = -1
            #bestDist = float('inf')
            #for answer in proposedAnswers:
            #    for i in indexes:
            #        if proposedAnswers[answer][0]==i and proposedAnswers[answer][1] < bestDist:
            #            bestDist = proposedAnswers[answer][1]
            #            bestAns = proposedAnswers[answer][0]
            #agreedAnswer = bestAns
        else:
            agreedAnswer = indexes[0]

        return agreedAnswer + 1
예제 #7
0
    def test_best_match_non_trivial(self):
        a = [[870, 1, 3, 0.134684136, 1, 1, 0.021730754, 0],
             [871, 0, 3, 0.875446884, 0, 0, 0.015411575, 0],
             [872, 1, 1, 1.582538598, 1, 1, 0.102578967, 0],
             [873, 0, 1, 1.111144122, 0, 0, 0.00975935, 0],
             [874, 0, 3, 1.582538598, 0, 0, 0.01756683, 0],
             [875, 1, 2, 0.942788952, 1, 0, 0.04684488, 1],
             [876, 1, 3, 0.50506551, 0, 0, 0.014102261, 1],
             [877, 0, 3, 0.67342068, 0, 0, 0.019217722, 0],
             [878, 0, 3, 0.639749646, 0, 0, 0.015411575, 0]]

        comp = Comparator(a, 2)
        a1 = comp.get_closes_match(
            [0, 0, 1, 1.582538598, 1, 1, 0.102578967, 0])
        print("Match ID: {0}".format(int(a1[0])))
        self.assertTrue(int(a1[0]) == 872)
        a2 = comp.get_closes_match([0, 0, 3, 0.50506559, 0, 0, 0.014102261, 1])
        print("Match ID: {0}".format(int(a2[0])))
        self.assertTrue(int(a2[0]) == 876)
예제 #8
0
    def __init__(self, algorithm, stop_event, options, compare=None):
        self.stopEvent = stop_event

        self.numLines = options.numLines
        self.width = options.width

        self.compare = compare

        self.stop = False
        self.cstop = compare == None

        self.items = Orderable(self.numLines)
        self.cmp = Comparator(self.items)
        self.markers = Markers()

        algorithm.initialize(self.cmp, self.items, self.markers)

        self.gen = algorithm.sort()

        if compare != None:
            self.citems = copy.deepcopy(self.items)
            self.ccmp = Comparator(self.citems)
            self.cmarkers = Markers()
            compare.initialize(self.ccmp, self.citems, self.cmarkers)

            self.cgen = compare.sort()

        pygame.init()

        if compare == None:
            self.window = pygame.display.set_mode(
                (self.width, 6 * (self.numLines + 1)))
        else:
            self.window = pygame.display.set_mode(
                (self.width * 2 + 5, 6 * (self.numLines + 1)))

        self.i = 0
        self.update()
예제 #9
0
 def test_001_t(self):
     """
     Defined source data for three incoming port
     For one port src_data0 
     For N port src_data0,src_data1,src_data2,.......,src_dataN.
     """
     src_data0 = (10, 9, 15)
     expected_result = (20, 20, 20)
     src0 = gr.vector_source_f(src_data0)
     cam_ref = Comparator(2, 20, 4)
     dst = gr.vector_sink_f()
     self.tb.connect(src0, cam_ref)
     self.tb.connect(cam_ref, dst)
     self.tb.run()
     result_data = dst.data()
     print "Result data is : ", result_data
     self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
예제 #10
0
    def __init__(self, algorithm, stop_event, options):
        self.stopEvent = stop_event

        self.numLines = options.numLines
        self.width = options.width

        self.items = Orderable(self.numLines)
        self.cmp = Comparator(self.items)
        self.markers = Markers()

        algorithm.initialize(self.cmp, self.items, self.markers)

        self.gen = algorithm.sort()

        pygame.init()
        self.window = pygame.display.set_mode(
            (self.width, 6 * (self.numLines + 1)))

        self.i = 0
        self.update()
예제 #11
0
from Mesh import Mesh
from Shape import Circle
from Comparator import Comparator

import matplotlib.pyplot as plt

base = Mesh( '/home/tristan/box/adcirc/runs/scaled20-noutgs/200' )
comp = Mesh( '/home/tristan/box/adcirc/runs/scaled20-noutgs/3200' )

circle = Circle( -77.9199990000, 33.8721240000, 0.05 )

comparator = Comparator( base, comp, circle )
comparator.compare_meshes()
rmse = comparator.compare_elevation_timeseries()

# with open( '/home/tristan/box/adcirc/runs/scaled20-noutgs/rmse.txt', 'w' ) as f:
#
#     for ( x, y ), e in rmse.items():
#
#         f.write( str( x ) + ',' + str( y ) + ',' + str( e ) + '\n' )

xvals = []
yvals = []
evals = []
for ( x, y ), e in rmse.items():

    xvals.append( x )
    yvals.append( y )
    evals.append( e )
    # print( x, y, e )
예제 #12
0
 def test_record_size_mismatch(self):
     c = Comparator("blah", 1)
     self.assertRaises(Exception, c.compute_error, [1, 2, 3, 4],
                       [1, 2, 3, 4, 5])
     self.assertRaises(Exception, c.compute_error, [1, 2, 3, 4, 5],
                       [1, 2, 3, 4])
예제 #13
0
def btnStartPars(file1, file2):
    dict = FileWorkClass.ReadFile(file1)
    d = sorted(dict.items(),
               key=cmp_to_key(Comparator.make_comparator(Comparator.cmpValue)),
               reverse=False)
    FileWorkClass.WriteFile(file2, d)
예제 #14
0
 def test_compute_error(self):
     c = Comparator([[]], 1)
     err = c.compute_error([1, 2, 3, 4], [1, 2, 3, 4])
     print("ERROR: {0}".format(err))
     self.assertTrue(err == 0.0)
예제 #15
0
 def test_get_best_match(self):
     fu = FileUtils(filename="test_file.csv", skip_header=True)
     reference_rows = fu.get_arrays_from_csv()
     comp = Comparator(reference_rows, 1)
     match = comp.get_closes_match([1, 10.0, 20.0, 30.0])
     self.assertTrue(match[0] == 3.0)
from Generator import Generator

if __name__ == '__main__':
	s1 = Searcher(CONSTS.O_DIR1)
	s2 = Searcher(CONSTS.D_DIR1)
	
	orig_files = s1.search()
	dev_files = s2.search()
	
	for f1 in orig_files:
		f2 = [item for item in dev_files if item['filename'] == f1['filename']]
		if len(f2) <= 0:
			continue
		f2 = f2[0]
		c = Comparator(
			"%s/%s" % (f1['dir'], f1['filename']),
			"%s/%s" % (f2['dir'], f2['filename'])
		)
		c.compare()

		modified = c.get_modified_method()
		if len(modified) <= 0:
			continue
		#print f1['filename']
		#for methodinfo in modified:
		#	print "\t%s" % methodinfo
		g = Generator(f1['filename'], modified)
		g.generate()


	#c.dump_method_content()
	#c.pick_same_method_name()"""
"""	Main: Archivo que muestra el uso basico de la clase Comparator	    """

# Se utiliza el modulo py_midicsv para extraer las notas desde un archivo MIDI.
import py_midicsv as pm
# Sin embargo, lo unico necesario para utilizar esta clase es tener un lista de notas con la notacion en numero de las notas musicales.
from Comparator import Comparator

# Se cambia el formato del archivo de MIDI a CSV
OnRepeat = pm.midi_to_csv(r"dummy.mid")

# Extraccion de Notas de Archivo MIDI
notes = []
for l in OnRepeat:
    line = l.split(",")
    if len(line) >= 5:
        if line[2] == " Note_on_c":
            m = int(line[4])
            notes.append(m)

# Se inicializa el objeto de la clase Comparator con los intervalos de la Escala Mayor
majorComp = Comparator([0, 2, 4, 5, 7, 9, 11])
notesStr = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]

indiceMayor = majorComp.analyze(notes)
print("Indices Escala Mayor", indiceMayor)
print("\nEscala:", notesStr[indiceMayor.index(max(indiceMayor))], "mayor\n")
예제 #18
0
 def test_compute_with_different_start_col(self):
     c = Comparator([[]], 2)
     err = c.compute_error([1, 2, 3, 4], [50, 60, 3, 4])
     print("ERROR: {0}".format(err))
     self.assertTrue(err == 0.0)