Example #1
0
 def navigation_function(self, hh):
     """calculate navigation function"""
     Beta = [self.beta_for_sphereworld(hh[i]) for i in range(len(hh))]
     a = [self.distance_to_goal(hh[i]) for i in range(len(hh))]
     b = [
         pwr(a[i], self.k) + self.lambda_sp * Beta[i]
         for i in range(len(hh))
     ]
     phi = [a[i] / pwr(b[i], 1.0 / self.k) for i in range(len(hh))]
     phi = [i if i < 1 else 1.0 for i in phi]
     return phi
Example #2
0
 def nav_func(self, q):
     Beta, b0, b1, b2, b3, b4 = self.get_beta(q)
     dBeta_dq = -2*(q-self.q0)*b1*b2*b3*b4 + \
     2*b0*((q-self.q1)*b2*b3*b4 + (q-self.q2)*b3*b4*b1 + \
     (q-self.q3)*b4*b1*b2 + (q-self.q4)*b1*b2*b3)
     a = nrm(q - self.qd)**2
     b = nrm(q - self.qd)**(2 * self.k) + Beta
     c = pwr(b, 1.0 / self.k)
     phi0 = a / c
     dphi_dq = 2 * (q - self.qd) / c - (a / (self.k * b * c)) * (
         2 * self.k * pwr(sq(a), 2 * self.k - 2) * (q - self.qd) + dBeta_dq)
     return phi0, dphi_dq
    def navigation_function(self, hh): 
        """calculate navigation function"""
        phi0 = [];  betaa = []; aa = []; bb = []
        for i in range(len(hh)):
            #print i, hh[i]
            Beta, b0, b1, b2, b3, b4= self.beta_for_sphereworld(hh[i])
            betaa.append(Beta)

            a = self.distance_to_goal(hh[i])
            aa.append(b0)
            b = pwr(a, self.k)+ self.lambda_sp * Beta
            bb.append(b4)
            phi0.append(a / pwr(b, 1.0 / self.k))

        return phi0
 def distance_to_goal(self, q):
     """takes current position and returns the distance to goal function"""
     """TODO: Decide which function should be goal function"""
     dist_to_goal = pwr(nrm(q - self.goal), 2.0)
     #dist_to_goal = nrm(q - self.goal)**4
     #dist_to_goal = nrm(q - self.goal)**(2 * self.k)
     return dist_to_goal
Example #5
0
def mandelbrot(c, ν = 0x42):
    ω = complex() 
    for _ in range(ν):
        ω = pwr(ω, 2) + c        
        # Overflow prevention makes NaN-check superfluous...
        # ω[any([isnan(ω), abs(ω) > 0x2], axis = 0)] = 0x2
        ω[abs(ω) > 0x2] = 0x2 
    return abs(ω) < 2.0
Example #6
0
    def navigation_function(self, hh): 
        """calculate navigation function"""
        phi0 = [];  betaa = []
        #print 'hh', hh
        for i in range(len(hh)):
            #print i, hh[i]
            Beta, b0, b1 = self.beta_for_sphereworld(hh[i])
            betaa.append(Beta)
            
            a = self.distance_to_goal(hh[i])
            #print 'in nav func calcs', b0,b1,b2,b3, a
            b = pwr(a, self.k)+ self.lambda_sp * Beta
            #bb.append(b4)
            phi00 = a / pwr(b, 1.0 / self.k)
            if phi00 > 1: 
                phi00 = 1
            phi0.append(phi00)
            #phi0.append(a / pwr(b, 1.0 / self.k))

        return phi0
def Asym_err(P_L, P_R):
    '''Returns the error in the asymmetry data'''
    try:
        P_L_err = sqrt(P_L)
        P_R_err = sqrt(P_R)
        A0_err = 2.*(sqrt(((sqr(P_L)*sqr(P_L_err))+(sqr(P_R)*sqr(P_R_err)))/pwr((P_L+P_R),4)))
        return A0_err
    except:
        print 'There was a problem finding the error in the asymmetry between the two channels. '\
        'Make sure the data file is correctly formatted, if it is, the asym module may need maintainance'
        sys.exit()
    def navigation_function(self, hh):
        """calculate navigation function"""
        phi0 = []
        betaa = []
        aa = []
        bb = []
        for i in range(len(hh)):
            #print i, hh[i]
            #Beta, b0, b1, b2, b3 = self.beta_for_sphereworld(hh[i])
            Beta, b0, b1, b2, b3, b4 = self.beta_for_sphereworld(hh[i])
            if Beta < 0:
                Beta = 0  #print 'Beta Negative'
            betaa.append(Beta)

            a = self.distance_to_goal(hh[i])
            aa.append(a)
            b = pwr(a, self.k) + self.lambda_sp * Beta
            bb.append(betaa)
            phi00 = a / pwr(b, 1.0 / self.k)
            if phi00 > 1:
                phi00 = 1
            phi0.append(phi00)

        return phi0
Example #9
0
def mandelbrother(c, ν = 0x42):
    ω = complex() 
    for _ in range(ν):
        ω = pwr(ω, 2) + c        
        ω[abs(ω) > 0xfffffffff] = 0x0 # Face-lifting an old set...
    return abs(ω)
Example #10
0
    "1.10129029471023	0.934810775330613	0.613856388322994	0.165830871237402				-0.360598048360463	-0.902302529116542]"
    .split()))

y_deriv1 = num_deriv(x_1, y_1)

x_s, y_s = symbols('x y')
f1 = sin(x_s) + cos(2 * x_s)
y_an = [N(diff(f1, x_s).subs(x_s, x_v)) for x_v in x]
y_an1 = [N(diff(f1, x_s).subs(x_s, x_v)) for x_v in x_1]

# Create figure with 3d plot (ax1) and contour plot (ax2)
fig = plt.figure(figsize=plt.figaspect(1 / 2.))
fig.suptitle('Derivatives')
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(1, 2, 2)

print("Err 1:", (1 / len(x)) * sum(pwr(ar(y_an) - ar(y_deriv), 2)))
print("Err 2:", (1 / len(x)) * sum(pwr(ar(y_an1) - ar(y_deriv1), 2)))

blue_patch = mpatches.Patch(color='blue', label='Derivative')
orange_patch = mpatches.Patch(color='orange', label='Exact solution')
ax1.legend(handles=[blue_patch, orange_patch])
ax2.legend(handles=[blue_patch, orange_patch])

ax1.plot(x, y_deriv)
ax1.plot(x, y_an, 'orange')

ax2.plot(x_1, y_deriv1)
ax2.plot(x_1, y_an1, 'orange')

plt.show()
Example #11
0
def julia(ω, ν = 0x40, c = -.8 + .156j, p = 2):
    for _ in range(ν):
        ω = pwr(ω, p) + c
        # Julia's face-lifting...
        ω[any([isnan(ω), abs(ω) > 0xff], axis = 0)] = 0xf
    return log(e + abs(ω))  # Not exactly a set function (like it would've been with 'return abs(ω) > 2')