Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Professor Snape has provided the young wizard Hermione with three magical batter

ID: 3804431 • Letter: P

Question

Professor Snape has provided the young wizard Hermione with three magical batteries whose sizes are 12, 7, and 6 morts, respectively. (A mort is a unit of wizard energy.) The 7-mort and 6-mort batteries are fully charged (containing 7 and 6 morts of energy, respectively), while the 12-mort battery is empty, with 0 morts. Snape says that Hermione is only allowed to use, repeatedly, if necessary, the mort transfer spell when working with these batteries. This spell transfers all the morts in one battery to another battery, and it halts the transfer either when the source battery has no morts remaining or when the destination battery is fully charged. Snape condescendingly challenges Hermione to determine whether there exists a sequence of mort-transfer spells that leaves exactly 2 morts either in the 7-mort or in the 6-mort battery. (a) Hermione knows this is actually a graph problem. Give a precise definition of how to model this problem as a graph, and state the specific question about this graph that must be answered. (b) What algorithm should Hermione apply to solve the graph problem? (c) Apply that algorithm to Snapes question. Report and justify your answer.

Explanation / Answer

data:
Xtrain knowledge - 350 rows, 7 Columns
Xtestdata - forty two Rows, 7 Colums
Ytrain knowledge - 350 rows, 1 Columns
Ytestdata - forty two Rows, 1 Colums
b = [5,7,9,11,13,15]:
sigma square = [.1,.2,.3,.4,.5,.6,.7,.8,.9,1]

Algo:
def KN(b):
rows = Xtraindata.shape[0]
#print (rows)
matrix = numpy.zeros((350,350))
#print(matrix.shape)
for i in range(rows):
for j in range(rows):
val = numpy.exp((-1/b)*(norm(Xtraindata[i]-Xtraindata[j])**2))
matrix[i][j]=val
come matrix

#calculating K(X, Dn)
def K(xTestEntry,b):
rows=len(Xtraindata)
#print (rows)
matrix = numpy.zeros((1,rows))
for i in range(rows):
val = numpy.exp((-1/b)*(norm(Xtraindata[i]-xTestEntry)**2))
matrix[0][i]=val
come matrix

# Loping KN over b and letter of the alphabet square.
n = len(Xtraindata)
for b in [5,7,9,11,13,15]:
for letter of the alphabet in [.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:
kn=KN(b)
ux=[]
for xTestEntry in Xtestdata:
kxdn =K(xTestEntry,b)
idMat = numpy.identity(n)*sigma
middle = numpy.linalg.inv(idMat + kn)
x1 = numpy.dot(kxdn,mid)
ypredict = numpy.dot(x1,Ytraindata)
ux.append(ypredict[0])
rms=sqrt(mean_squared_error(Ytestdata, ux))
print(b,sigma,rms)data:
Xtrain knowledge - 350 rows, 7 Columns
Xtestdata - forty two Rows, 7 Colums
Ytrain knowledge - 350 rows, 1 Columns
Ytestdata - forty two Rows, 1 Colums
b = [5,7,9,11,13,15]:
sigma square = [.1,.2,.3,.4,.5,.6,.7,.8,.9,1]

Algo:
def KN(b):
rows = Xtraindata.shape[0]
#print (rows)
matrix = numpy.zeros((350,350))
#print(matrix.shape)
for i in range(rows):
for j in range(rows):
val = numpy.exp((-1/b)*(norm(Xtraindata[i]-Xtraindata[j])**2))
matrix[i][j]=val
come matrix

#calculating K(X, Dn)
def K(xTestEntry,b):
rows=len(Xtraindata)
#print (rows)
matrix = numpy.zeros((1,rows))
for i in range(rows):
val = numpy.exp((-1/b)*(norm(Xtraindata[i]-xTestEntry)**2))
matrix[0][i]=val
come matrix

# Loping KN over b and letter of the alphabet square.
n = len(Xtraindata)
for b in [5,7,9,11,13,15]:
for letter of the alphabet in [.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:
kn=KN(b)
ux=[]
for xTestEntry in Xtestdata:
kxdn =K(xTestEntry,b)
idMat = numpy.identity(n)*sigma
middle = numpy.linalg.inv(idMat + kn)
x1 = numpy.dot(kxdn,mid)
ypredict = numpy.dot(x1,Ytraindata)
ux.append(ypredict[0])
rms=sqrt(mean_squared_error(Ytestdata, ux))
print(b,sigma,rms)data:
Xtrain knowledge - 350 rows, 7 Columns
Xtestdata - forty two Rows, 7 Colums
Ytrain knowledge - 350 rows, 1 Columns
Ytestdata - forty two Rows, 1 Colums
b = [5,7,9,11,13,15]:
sigma square = [.1,.2,.3,.4,.5,.6,.7,.8,.9,1]

Algo:
def KN(b):
rows = Xtraindata.shape[0]
#print (rows)
matrix = numpy.zeros((350,350))
#print(matrix.shape)
for i in range(rows):
for j in range(rows):
val = numpy.exp((-1/b)*(norm(Xtraindata[i]-Xtraindata[j])**2))
matrix[i][j]=val
come matrix

#calculating K(X, Dn)
def K(xTestEntry,b):
rows=len(Xtraindata)
#print (rows)
matrix = numpy.zeros((1,rows))
for i in range(rows):
val = numpy.exp((-1/b)*(norm(Xtraindata[i]-xTestEntry)**2))
matrix[0][i]=val
come matrix

# Loping KN over b and letter of the alphabet square.
n = len(Xtraindata)
for b in [5,7,9,11,13,15]:
for letter of the alphabet in [.1,.2,.3,.4,.5,.6,.7,.8,.9,1]:
kn=KN(b)
ux=[]
for xTestEntry in Xtestdata:
kxdn =K(xTestEntry,b)
idMat = numpy.identity(n)*sigma
middle = numpy.linalg.inv(idMat + kn)
x1 = numpy.dot(kxdn,mid)
ypredict = numpy.dot(x1,Ytraindata)
ux.append(ypredict[0])
rms=sqrt(mean_squared_error(Ytestdata, ux))
print(b,sigma,rms)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote