def set_activation(self,
                       method,
                       sig=None,
                       d_sig=None,
                       sig_0=None,
                       d_sig_0=None):
        """
		This method sets activation functions. 

		Parameters
		----------
		method : str
			One of 'logistic', 'htangent', or 'custom'.
		sig : function object
			Pass only when method == 'custom'.
		d_sig : function object
			Pass only when method == 'custom'.
		sig_0 : function object
			Pass only when method == 'custom' (output layer activation function).
		d_sig_0 : function object
			Pass only when method == 'custom' (output layer activation function).

		TODO:
			add multilogit?
		"""
        method = method.lower()
        self.activation = method

        if method == 'logistic':
            self.sig = lambda z: 2 * 1 / (1 + e(-z.astype(np.float64))) - 1
            self.d_sig = lambda z: 2 * e(-z) / np.power(1 + e(-z), 2)
            self.sig_0 = lambda z: z
            self.d_sig_0 = lambda z: 1 + 0 * z

        elif method == 'htangent':
            self.sig = lambda z: np.tanh(z)
            self.d_sig = lambda z: 1 - np.power(np.tanh(z), 2)
            self.sig_0 = lambda z: z
            self.d_sig_0 = lambda z: 1 + 0 * z

        elif method == 'custom':
            self.sig = sig
            self.d_sig = d_sig
            self.sig_0 = sig_0
            self.d_sig_0 = d_sig_0

        else:
            raise ValueError('NNetRegress.set_activation: \'' + method +
                             '\' is not a valid argument for method')
def softmax(logit, t):
    summer = []
    answer = []
    for l in range(0, len(logit)):
        summer.append(0)
        for j in range(0, len(logit[l])):
            summer[l] = summer[l] + e(logit[l][j] / t)
    for z in range(0, len(logit)):
        answer.append([])
        for j in range(0, len(logit[z])):
            answer[z].append(e(logit[z][j] / t) / summer[z])
    answer = ar(answer)
    for i in range(0, len(answer)):
        answer[i] = ar(answer[i])
    return answer
Beispiel #3
0
def dist(p1, p2):
	'''
	uses the distance squared metric
	'''
	J = 0
	for i in range(len(p1)):
		J += (p1[i] - p2[i]) ** 2
	return np.e(-J/4)
Beispiel #4
0
def dist(p1, p2):
    '''
	uses the distance squared metric
	'''
    J = 0
    for i in range(len(p1)):
        J += (p1[i] - p2[i])**2
    return np.e(-J / 4)
Beispiel #5
0
def mollifier(x, y):
    """
    Evaluate the mollifier rho with support within a ball at the point x,y
    """
    d = np.sqrt(x**2 + y**2)
    in_ball = np.zeros(x.shape, dtype=np.bool)
    in_ball[d < 1] = 1
    z = np.zeros(x.shape)
    z[in_ball] = e(-1 / (1 - d[in_ball]**2))
    return z
	def set_activation(self, method, sig=None, d_sig=None, sig_0=None, d_sig_0=None):
		"""
		This method sets activation functions. 

		Parameters
		----------
		method : str
			One of 'logistic', 'htangent', or 'custom'.
		sig : function object
			Pass only when method == 'custom'.
		d_sig : function object
			Pass only when method == 'custom'.
		sig_0 : function object
			Pass only when method == 'custom' (output layer activation function).
		d_sig_0 : function object
			Pass only when method == 'custom' (output layer activation function).

		TODO:
			add multilogit?
		"""
		method = method.lower()
		self.activation = method

		if method == 'logistic':
			self.sig = lambda z: 2 * 1 / (1 + e(-z.astype(np.float64))) - 1
			self.d_sig = lambda z: 2 * e(-z) / np.power(1 + e(-z), 2)
			self.sig_0 = lambda z: z
			self.d_sig_0 = lambda z: 1 + 0 * z

		elif method == 'htangent':
			self.sig = lambda z: np.tanh(z)
			self.d_sig = lambda z: 1 - np.power(np.tanh(z), 2)
			self.sig_0 = lambda z: z
			self.d_sig_0 = lambda z: 1 + 0 * z

		elif method == 'custom':
			self.sig = sig
			self.d_sig = d_sig
			self.sig_0 = sig_0
			self.d_sig_0 = d_sig_0

		else:
			raise ValueError('NNetRegress.set_activation: \'' + method + '\' is not a valid argument for method')
Beispiel #7
0
def adaboost(points, hyp , r):
    set_of_hyp=[]
    for x in points:
        x.weight= 1/len(points)
    for t in range(r):
        h_t,eps_t=hyp(points)
        if eps_t>0.5:
            print("eps too big:",eps_t)
            break
        alpha_t=0.5*ln((1-eps_t)/eps_t)
        Z_t=0
        for x in points:
            #Set the weight of the points
            x.weight= x.weight*e(-alpha_t*h_t.include(x,h_t.gender_classifier)*x.gender)
            Z_t+=x.weight
        for x in points:
            # normalization
            x.weight=x.weight/Z_t 
        set_of_hyp.append((h_t,alpha_t))
    return set_of_hyp
Beispiel #8
0
def w_exp(i, j, gi, gj, sigma_s, sigma_r):
    imj = i - j
    gimgj = gi - gj
    return np.e**(-np.dot(imj, imj) /
                  (2 * sigma_s**2)) * np.e(-np.dot(gimgj, gimgj) /
                                           (2 * sigma_r**2))
def model():
    return 1 / 1 + np.e(-x)
Beispiel #10
0
 def sigmoid(x):
     return 1 / (1 + np.e(-x))
Beispiel #11
0
def fit_func(x, a, b):
    return e(b * (ln(x / a)))
def power_law_exponent(graph):
	in_degrees = nx.degree(graph) # dictionary node:degree
	in_values = sorted(set(in_degrees.values()))
	in_hist = [in_degrees.values().count(x) for x in in_values]
	plt.loglog(in_values,in_hist, basex=np.e, basey=np.e(-2))
	plt.show(block=False)
Beispiel #13
0
def example_2():
    """
    Oden et al
    """
    u = lambda x, y: 5 * x**2 * (1 - x)**2 * (e(10 * x**2) - 1) * y**2 * (
        1 - y)**2 * (e(10 * y**2) - 1)
    f = lambda x,y: 10*((e(10*x**2)-1)*(x-1)**2*x**2* (e(10*y**2)-1)*(y-1)**2\
                        + (e(10*x**2)-1)*(x-1)**2*x**2*(e(10*y**2)-1)*y**2\
                        + 50*(e(10*x**2)-1)*(x-1)**2*x**2*e(10*y**2)*(y-1)**2*y**2
                        + 50*e(10*x**2)*(x-1)**2*x**2*(e(10*y**2)-1)*(y-1)**2*y**2\
                        + (e(10*x**2)-1)*x**2*(e(10*y**2)-1)*(y-1)**2*y**2\
                        + 4*(e(10*x**2)-1)*(x-1)**2*x**2*(e(10*y**2)-1)*(y-1)*y\
                        + 4*(e(10*x**2)-1)*(x-1)*x*(e(10*y**2)-1)*(y-1)**2*y**2\
                        + (e(10*x**2)-1)*(x-1)**2*(e(10*y**2)-1)*(y-1)**2*y**2\
                        + 200*(e(10*x**2)-1)*(x-1)**2*x**2*e(10*y**2)*(y-1)**2*y**4\
                        + 40*(e(10*x**2)-1)*(x-1)**2*x**2*e(10*y**2)*(y-1)*y**3\
                        + 200*e(10*x**2)*(x-1)**2*x**4*(e(10*y**2)-1)*(y-1)**2*y**2\
                        + 40*e(10*x**2)*(x-1)*x**3*(e(10*y**2)-1)*(y-1)**2*y**2)

    mesh = Mesh.newmesh(grid_size=(30, 30))
    mesh.refine()
    element = QuadFE(2, 'Q2')
    system = System(mesh, element)
    linear_forms = [(f, 'v')]
    bilinear_forms = [(1, 'ux', 'vx')]
    dir_bnd = lambda x, y: np.abs(y) < 1e-10
    dir_fun = u
    boundary_conditions = {
        'dirichlet': [(dir_bnd, dir_fun)],
        'neumann': None,
        'robin': None
    }
    A, b = system.assemble(bilinear_forms, linear_forms, boundary_conditions)

    #A,b = system.extract_hanging_nodes(A, b, compress=True)
    ua = spla.spsolve(A.tocsc(), b)
    x = system.dof_vertices()
    ue = u(x[:, 0], x[:, 1])
Beispiel #14
0
from astropy.cosmology import Planck15 as p15

from scipy.integrate import quad
from scipy.misc import derivative
from scipy.integrate import odeint

n = 6.2 * 10 ** -10
m_e = 511 * 10 ** 3 # in eV/c^2
Q = 13.57 # in eV
k = 8.617 * 10 ** -5 #in ev/K
T = np.linspace(0, 1e4, 1000)


#Part 1a

S = 3.84 * n * ((k*T/m_e))**(3/2)*(e(Q/(k*T)))

def saha(T):
    X = (-1+np.sqrt(1+4*S))/(2*S)
    return X

def test(T):
    return np.sin(T)

'''
fig = plt.figure(figsize=(7,7))
axis = fig.add_subplot(1,1,1)

axis.plot(T, saha(T), 'g', linewidth = 1.5)
axis.set_xlabel('Temperature (K)', fontsize = 10)
axis.set_ylabel('Saha Equation', fontsize = 10)
def func(a , b):
    return np.log(a) * np.e(b) % a/b
Beispiel #16
0
def sigmoid(z, function_type=1):
    if function_type == 1:
        return 1.0 / (1.0 + e(-z))  # logistic function
    else:
        return np.arctan(z)
Beispiel #17
0
 def update(self):
     self.phi = e(self.tick)
     self.tick = self.tick - 0.001 * e(0.5 * self.tick)
Beispiel #18
0
meanf = np.mean(frecuency)
for k in frecuency:
    suma = (k - meanf)**2
errorf = (suma / (43 * 42))**(1 / 2) * 100
fig, bx = plt.subplots()
plt.plot(frecuency, uncertainty, color='g', label='Incertidumbre')
bx.errorbar(frecuency, FIRAS, yerr=errorf)
plt.xlabel('$Frecuencia[1/cm]$', fontsize=15)
plt.ylabel('$Intensidad[MJy/sr]$', fontsize=15)
plt.show()
#parte 2
frecuency = (frecuency / 100) * c  #(1/m)*(m/s) = 1/s
#metodo simpson 1/3
n = 100
eps = 43 / 100
#sumatorias
a = 0
b = 0
for i in range(n // 2 - 1):
    a = a + ((np.tan(2 * i + 1)**3) *
             (np.tan(2 * i + 1)**2 + 1)) / (np.e(np.tan(2 * i + 1)) - 1)
for j in range(n // 2 - 1):
    b = b + ((np.tan(2 * j)**3) *
             (np.tan(2 * j)**2 + 1)) / (np.e(np.tan(2 * j)) - 1)
#integral
I = (eps / 3) * (((np.tan(np.pi / 2)**3) * (np.tan(np.pi / 2)**2 + 1)) /
                 (np.e(np.tan(np.pi / 2)) - 1) + 4 * a + 2 * b)

print(I, (np.pi**4) / 15)
#fig, ax = plt.subplots()
#ax.errorbar(x, y)