Esempio n. 1
0
def learn_loop(dataset, answers, target):		### Just the digits from main dataset
	"""Takes a dataset with expected values
	returns proper weights for each element of the vector space
	"""

	# set initial guess, initial weights, threshold, and learning rate
	binary_dataset = convert_dataset(dataset)
	[vector.append(1) for vector in binary_dataset] 
	expected = [1 if answers[idx] == target else 0 for idx, x in enumerate(binary_dataset)] 
	weights = [0 for elem in binary_dataset[0]]  
	guesses = [0 for vector in binary_dataset]
	threshold = .5
	l_rate = .05

	### Check each vector against expect and loop over again until 0 errors
	counter = 0
	while True:
		for idy, vector in enumerate(binary_dataset):
			error = expected[idy] - guesses[idy]
			if dot_product(vector, weights) > threshold:   	#if true, set output to 1
				guesses[idy] = 1 
			else:
				guesses[idy] = 0
			weights = update_weights(weights, error, l_rate, vector)
		if expected != guesses and counter < 500:
			counter += 1
			continue
		else:
			break
	return weights
Esempio n. 2
0
    def test_dot_product(self):
        a = [0, 0, 0, 0, 4, 0, 0, 0]
        b = [0, 0, 5, 0, 1, 0, 0, 0]

        result = dp.dot_product(a, b)

        self.assertEqual(result, 4)
Esempio n. 3
0
def check_new_iris(vector, weights):
	""" Takes in a vector (representing a picture of a number) and weights
	Returns a guess as to it's value
	"""
	threshold = .5
	computer_guesses = []
	dot_product_list = []
	for x in range(3):
		dot_product_list.append(dot_product(vector, weights[x]))
		if dot_product_list[x] > threshold:
			computer_guesses.append(x)
	if dot_product_list:
		return dot_product_list.index(max(dot_product_list))
	else:
		return None