示例#1
0
    lambda a: sfbe.Sy(r1, r2, a, r4, t1, hx, hy, Ox, Oy, sig, t2), r3,
    0.01 * abs(r3))
print "4:", derivative(
    lambda a: sfbe.Sy(r1, r2, r3, a, t1, hx, hy, Ox, Oy, sig, t2), r4,
    0.01 * abs(r4))
print "5:", derivative(
    lambda a: sfbe.Sy(r1, r2, r3, r4, a, hx, hy, Ox, Oy, sig, t2), t1, 0.02)
print "6:", derivative(
    lambda a: sfbe.Sy(r1, r2, r3, r4, t1, a, hy, Ox, Oy, sig, t2), hx,
    0.01 * abs(hx))
print "7:", derivative(
    lambda a: sfbe.Sy(r1, r2, r3, r4, t1, hx, a, Ox, Oy, sig, t2), hy,
    0.01 * abs(hy))
print "8:", 0.0
print "9:", 1.0

print "\nthe derivatives wrt t2:"
print "Sx:", derivative(
    lambda a: sfbe.Sx(r1, r2, r3, r4, t1, hx, hy, Ox, Oy, sig, a), t2, 0.02)
print "Sy:", derivative(
    lambda a: sfbe.Sy(r1, r2, r3, r4, t1, hx, hy, Ox, Oy, sig, a), t2, 0.02)

print "\nAnd now for cool shit:"
print "r=", sfbe.residuals(x, y, v, sig, thetas)
print "J=", sfbe.jacobian(v, sig, thetas)

print "\nThey're the right sizes, right?"
print "residual:", sfbe.residuals(x, y, v, sig,
                                  thetas).shape[0] == 2 * x.shape[0]
print "Jacobian:", sfbe.jacobian(v, sig, thetas).shape == (2 * x.shape[0],
                                                           9 + x.shape[0])
thetas=(pi/180.0)*array([-179.82,-160.16,-140.05,-119.44,-99.54,-80.05,-60.08,-40.12,-20.62,0.10,19.70,39.79,59.93,79.60,100.27,119.48,140.49,159.74,179.64])

(vnew,sigma,tnew)=sfbe.linkagefit(points,startingpt,thetas)
print "The output of sfbe.linkagefit for the \"close\" problem is:\n"
print "r_1: ", vnew[0]
print "r_2: ", vnew[1]
print "r_3: ", vnew[2]
print "r_4: ", vnew[3]
print "t_1: ", vnew[4]
print "h_x: ", vnew[5]
print "h_y: ", vnew[6]
print "O_x: ", vnew[7]
print "O_y: ", vnew[8]

oldr=sfbe.residuals(points[:,0],points[:,1],startingpt,-1,thetas)
newr=sfbe.residuals(points[:,0],points[:,1],vnew,-1,tnew)

print "\nThe sum of the squares of the original residuals was: ", dot(oldr,oldr)
print "\nThe sum of the squares of the new residuals is: ", dot(newr,newr)



"""A modification of the base problem, where I changed a the parameters around a little.
It converged nicely enough."""
    
startingpt=array([18.0,7.0,17.0,18.0,15.0*(pi/180),0.5,0.5,0.0,0.0])

(vnew,sigma,tnew)=sfbe.linkagefit(points,startingpt,thetas)
print "\nThe output of sfbe.linkagefit for a mid-range starting point is:\n"
print "r_1: ", vnew[0]
示例#3
0
    0.10, 19.70, 39.79, 59.93, 79.60, 100.27, 119.48, 140.49, 159.74, 179.64
])

(vnew, sigma, tnew) = sfbe.linkagefit(points, startingpt, thetas)
print "The output of sfbe.linkagefit for the \"close\" problem is:\n"
print "r_1: ", vnew[0]
print "r_2: ", vnew[1]
print "r_3: ", vnew[2]
print "r_4: ", vnew[3]
print "t_1: ", vnew[4]
print "h_x: ", vnew[5]
print "h_y: ", vnew[6]
print "O_x: ", vnew[7]
print "O_y: ", vnew[8]

oldr = sfbe.residuals(points[:, 0], points[:, 1], startingpt, -1, thetas)
newr = sfbe.residuals(points[:, 0], points[:, 1], vnew, -1, tnew)

print "\nThe sum of the squares of the original residuals was: ", dot(
    oldr, oldr)
print "\nThe sum of the squares of the new residuals is: ", dot(newr, newr)
"""A modification of the base problem, where I changed a the parameters around a little.
It converged nicely enough."""

startingpt = array(
    [18.0, 7.0, 17.0, 18.0, 15.0 * (pi / 180), 0.5, 0.5, 0.0, 0.0])

(vnew, sigma, tnew) = sfbe.linkagefit(points, startingpt, thetas)
print "\nThe output of sfbe.linkagefit for a mid-range starting point is:\n"
print "r_1: ", vnew[0]
print "r_2: ", vnew[1]
示例#4
0
#! /usr/bin/env python
"""
residuals() wasn't working so I worked on this part separately.
At this point in time, it at least create output that makes sense
at a glance, but I haven't checked it to make sure it's actually
doing what I expect it to.
"""

from numpy import *
import sfbe

#These vectors are the size that I want them, dammit.
x = array([1.0, 2.0, 3.0, 4.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0])
y = array([1.0, 2.0, 3.0, 4.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0])
v = array([16.0, 8.0, 17.0, 19.0, pi * (15.0 / 180.0), 0.75, 0.3, -3.0, -5.0])
sig = 1
thetas = (pi / 180.0) * array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

print "Are x, y and thetas the same size? Here are their lengths:"
print x.shape[0]
print y.shape[0]
print thetas.shape[0]
print "Is v nine long?:"
print(v.shape[0] == 9)
print "So what's the residual vector?"
arrgh = sfbe.residuals(x, y, v, sig, thetas)
print arrgh
print "How big is arrgh? It should be twice as long as x or y:"
print arrgh.shape[0]
print "2:",derivative(lambda a: sfbe.Sx(r1,a,r3,r4,t1,hx,hy,Ox,Oy,sig,t2),r2,0.01*abs(r2))
print "3:",derivative(lambda a: sfbe.Sx(r1,r2,a,r4,t1,hx,hy,Ox,Oy,sig,t2),r3,0.01*abs(r3))
print "4:",derivative(lambda a: sfbe.Sx(r1,r2,r3,a,t1,hx,hy,Ox,Oy,sig,t2),r4,0.01*abs(r4))
print "5:",derivative(lambda a: sfbe.Sx(r1,r2,r3,r4,a,hx,hy,Ox,Oy,sig,t2),t1,0.02)
print "6:",derivative(lambda a: sfbe.Sx(r1,r2,r3,r4,t1,a,hy,Ox,Oy,sig,t2),hx,0.01*abs(hx))
print "7:",derivative(lambda a: sfbe.Sx(r1,r2,r3,r4,t1,hx,a,Ox,Oy,sig,t2),hy,0.01*abs(hy))
print "8:",1.0
print "9:",0.0

print "\nthe gradient bits for Sy:"
print "1:", derivative(lambda a: sfbe.Sy(a,r2,r3,r4,t1,hx,hy,Ox,Oy,sig,t2),r1,0.01*abs(r1))
print "2:", derivative(lambda a: sfbe.Sy(r1,a,r3,r4,t1,hx,hy,Ox,Oy,sig,t2),r2,0.01*abs(r2))
print "3:", derivative(lambda a: sfbe.Sy(r1,r2,a,r4,t1,hx,hy,Ox,Oy,sig,t2),r3,0.01*abs(r3))
print "4:", derivative(lambda a: sfbe.Sy(r1,r2,r3,a,t1,hx,hy,Ox,Oy,sig,t2),r4,0.01*abs(r4))
print "5:", derivative(lambda a: sfbe.Sy(r1,r2,r3,r4,a,hx,hy,Ox,Oy,sig,t2),t1,0.02)
print "6:", derivative(lambda a: sfbe.Sy(r1,r2,r3,r4,t1,a,hy,Ox,Oy,sig,t2),hx,0.01*abs(hx))
print "7:", derivative(lambda a: sfbe.Sy(r1,r2,r3,r4,t1,hx,a,Ox,Oy,sig,t2),hy,0.01*abs(hy))
print "8:", 0.0
print "9:", 1.0

print "\nthe derivatives wrt t2:"
print "Sx:", derivative(lambda a: sfbe.Sx(r1,r2,r3,r4,t1,hx,hy,Ox,Oy,sig,a),t2,0.02)
print "Sy:", derivative(lambda a: sfbe.Sy(r1,r2,r3,r4,t1,hx,hy,Ox,Oy,sig,a),t2,0.02)

print "\nAnd now for cool shit:"
print "r=",sfbe.residuals(x,y,v,sig,thetas)
print "J=",sfbe.jacobian(v,sig,thetas)

print "\nThey're the right sizes, right?"
print "residual:", sfbe.residuals(x,y,v,sig,thetas).shape[0]==2*x.shape[0]
print "Jacobian:", sfbe.jacobian(v,sig,thetas).shape==(2*x.shape[0],9+x.shape[0])
#! /usr/bin/env python
"""
residuals() wasn't working so I worked on this part separately.
At this point in time, it at least create output that makes sense
at a glance, but I haven't checked it to make sure it's actually
doing what I expect it to.
"""


from numpy import *
import sfbe
    
#These vectors are the size that I want them, dammit.
x=array([1.0,2.0,3.0,4.0,5.0,4.0,3.0,2.0,1.0,0.0])
y=array([1.0,2.0,3.0,4.0,5.0,4.0,3.0,2.0,1.0,0.0])
v=array([16.0,8.0,17.0,19.0,pi*(15.0/180.0),0.75,0.3,-3.0,-5.0])
sig=1
thetas=(pi/180.0)*array([1,2,3,4,5,6,7,8,9,10])

print "Are x, y and thetas the same size? Here are their lengths:"
print x.shape[0]
print y.shape[0]
print thetas.shape[0]
print "Is v nine long?:"
print (v.shape[0]==9)
print "So what's the residual vector?"
arrgh=sfbe.residuals(x,y,v,sig,thetas)
print arrgh
print "How big is arrgh? It should be twice as long as x or y:"
print arrgh.shape[0]