예제 #1
0
	def test(self, queryData, vectorNormalize, vectorDifference, output):
		file = h5py.File(output, 'w')
		results = file.create_dataset('matches', (queryData.size, self.dataset.size), dtype=numpy.float64, compression='gzip', compression_opts=9)
		if queryData == self.dataset:
			# If self-testing, do not match an image with itself
			utility.iterate(self.representations, lambda representation, i: results.__setitem__(i, self.matchRepresentationOthers(representation, i, vectorNormalize, vectorDifference)), False)
		else:
			# Else, test every query image against the complete set
			utility.iterate(queryData.images(), lambda image, i: results.__setitem__(i, self.matchRepresentation(self.representImage(image), vectorNormalize, vectorDifference)), False)
		file.close()
예제 #2
0
 def zip(dx, dy):
     result = [[], []]
     for key, x in sorted(dx.iteritems()):
         for y in utility.iterate(dy.get(key)):
             result[0].append(x)
             result[1].append(y)
     return result
예제 #3
0
파일: scales.py 프로젝트: 4sp1r3/Melopy
def generateScale(scale, note, mode=1, rType="list", octaves=True): #scale, start, type
    """
    Generate a scale
    scale (string): major,  melodic_minor, harmonic_minor, chromatic, major_pentatonic
    note: start note
    """
    if scale in SCALE_STEPS:
        steps = _get_mode(SCALE_STEPS[scale], mode)
        return iterate(note, steps, rType, octaves)
    else:
        raise MelopyGenericError("Unknown scale type:" + str(scale))
예제 #4
0
def generateScale(scale, note, mode=1, rType="list", octaves=True): #scale, start, type
    """
    Generate a scale
    scale (string): major,  melodic_minor, harmonic_minor, chromatic, major_pentatonic
    note: start note
    """
    if scale in SCALE_STEPS:
        steps = _get_mode(SCALE_STEPS[scale], mode)
        return iterate(note, steps, rType, octaves)
    else:
        raise MelopyGenericError("Unknown scale type:" + str(scale))
예제 #5
0
def imageDifferences(matrix, image):
	# Return a sorted list of the differences between one image and the others in a given matrix
	if len(matrix) == len(matrix[0]):
		# Matrix is square, assume self-comparison
		differences = numpy.empty((len(matrix)-1, 2), dtype=numpy.float64)
		row = matrix[image]
		i = 0
		while i < image:
			# All similarities before the diagonal
			differences[i] = numpy.array([row[i], i])
			i += 1
		while i < differences.shape[0]:
			# All similarities beyond the diagonal
			differences[i] = numpy.array([row[i + 1], i + 1])
			i += 1
	else:
		# Non-square matrix, must be differing source and query
		differences = numpy.empty((len(matrix[0]), 2), dtype=numpy.float64)
		utility.iterate(matrix[image], lambda difference, i: differences.__setitem__(i, (difference, i)), False, None)

	return differences[differences[:,0].argsort()]
예제 #6
0
def generateChord(name, tonic, inversion=0, rType='list', octaves=True):
    if name in CHORD_INTERVALS:
        steps = CHORD_INTERVALS[name]
        return _get_inversion(iterate(tonic, steps, rType, octaves),inversion)
    else:
        raise MelopyGenericError("Unknown Chord:"+str(name))
예제 #7
0
 def test_iterate(self):
     start = 'D4'
     pattern = [2, 2, 1, 2, 2, 2]
     should_be = ['D4', 'E4', 'F#4', 'G4', 'A4', 'B4', 'C#5']
     self.assertEqual(should_be, utility.iterate(start, pattern))
예제 #8
0
def fileMetrics(result, sourceData, queryData, amounts):
	similarityMatrix = utility.duration(
		readSimilarities,
		sourceData.name,
		queryData.name,
		task="Read similarity matrix"
	)
	differenceFile, differenceMatrix = utility.duration(
		readDifferences,
		result,
		task="Read difference matrix"
	)
	sourcePoses = utility.duration(
		readPoses,
		sourceData.name,
		task="Read poses",
	)
	queryPoses = utility.duration(
		readPoses,
		queryData.name,
		task="Read poses",
	)

	totalMetrics = {
		'precision': {amount:numpy.empty(queryData.size, dtype=numpy.float64) for amount in amounts},
		'recall': {amount:numpy.empty(queryData.size, dtype=numpy.float64) for amount in amounts},
		'recallRate': {amount:numpy.empty(queryData.size, dtype=numpy.float64) for amount in amounts},
		'transform': numpy.empty(queryData.size, dtype=numpy.float64),
		'rotation': numpy.empty(queryData.size, dtype=numpy.float64)
	}

	utility.iterate(range(queryData.size), lambda _, i: registerMetrics(totalMetrics, imageMetrics(similarityMatrix, differenceMatrix, sourcePoses, queryPoses, i, amounts), i), False)

	differenceFile.close()

	return {
		'precision': {
			amount: {
				'mean': numpy.mean(totalMetrics['precision'][amount]),
				'variance': numpy.var(totalMetrics['precision'][amount]),
				'standardDeviation': numpy.std(totalMetrics['precision'][amount])
			} for amount in totalMetrics['precision']
		},
		'recall': {
			amount: {
				'mean': numpy.mean(totalMetrics['recall'][amount]),
				'variance': numpy.var(totalMetrics['recall'][amount]),
				'standardDeviation': numpy.std(totalMetrics['recall'][amount])
			} for amount in totalMetrics['recall']
		},
		'recallRate': {
			amount: {
				'mean': numpy.mean(totalMetrics['recallRate'][amount]),
				'variance': numpy.var(totalMetrics['recallRate'][amount]),
				'standardDeviation': numpy.std(totalMetrics['recallRate'][amount])
			} for amount in totalMetrics['recallRate']
		},
		'transform': {
			'mean': numpy.mean(totalMetrics['transform']),
			'variance': numpy.var(totalMetrics['transform']),
			'standardDeviation': numpy.std(totalMetrics['transform'])
		},
		'rotation': {
			'mean': numpy.mean(totalMetrics['rotation']),
			'variance': numpy.var(totalMetrics['rotation']),
			'standardDeviation': numpy.std(totalMetrics['rotation'])
		}
	}
예제 #9
0
	def matchRepresentation(self, query, vectorNormalize, vectorDifference):
		# Returns a list of the differences between the given representation and each representation in the dataset
		matches = numpy.empty(self.dataset.size, dtype=numpy.float64)
		utility.iterate(self.representations, lambda representation, i: (matches.__setitem__(i, self.compareRepresentation(query, representation, vectorNormalize, vectorDifference))), False, None)
		return matches
예제 #10
0
	def representDataset(self):
		representations = numpy.empty((self.dataset.size, self.representationSize()), dtype=numpy.int16)
		utility.iterate(self.dataset.images(), lambda image, i: (representations.__setitem__(i, self.representImage(image))), False)
		return representations