コード例 #1
0
 def _initializeProjection(self):
     if self.dim <= self.lowerDimensionBound:
         # We only need to reduce the dimension if it's bigger than
         # lowerDimensionBound; otherwise, chose identity
         self.projection = 1
     else:
         projection_shape = self.dim, self.lowerDimensionBound
         self.projection = random.standard_normal(projection_shape)
         self.projection /= sqrt(self.lowerDimensionBound)
コード例 #2
0
ファイル: nearoptimal.py プロジェクト: Boblogic07/pybrain
 def _initializeProjection(self):
     if self.dim <= self.lowerDimensionBound:
         # We only need to reduce the dimension if it's bigger than
         # lowerDimensionBound; otherwise, chose identity
         self.projection = 1
     else:
         projection_shape = self.dim, self.lowerDimensionBound
         self.projection = random.standard_normal(projection_shape)
         self.projection /= sqrt(self.lowerDimensionBound)
コード例 #3
0
ファイル: kmeans.py プロジェクト: Huskyeder/semantictweets
 def __init__(self, tag, dimensions):
     self.index = tag
     self.centroid = array(10 * random.standard_normal(dimensions))
コード例 #4
0
ファイル: temp.py プロジェクト: viswajithiii/analyze-this
from sklearn import metrics
from scipy import random

c = []
d = []
e = []

for i in range(10000):
    a = random.random_integers(0,1)
    b = random.standard_normal()
    c.append(a)
    d.append(b)
    e.append(a)
print metrics.normalized_mutual_info_score(c,d)
print metrics.adjusted_mutual_info_score(c,d)
print metrics.mutual_info_score(c,d)
print metrics.normalized_mutual_info_score(c,e)
print metrics.adjusted_mutual_info_score(c,e)
print metrics.mutual_info_score(c,e)
print c[:10]
print d[:10]
コード例 #5
0
plot2D(fx,fy,Z,"f_rectangulo")

z = (fft.fftshift(fft.ifft2(Z))).real
zoom1 = 3*N/8
zoom2 = 5*N/8
plot2D (x[zoom1:zoom2,zoom1:zoom2], y[zoom1:zoom2,zoom1:zoom2],z[zoom1:zoom2,zoom1:zoom2], "sinc_zoom")

# Gaussiana + ruido + recorte en frecuencias
sigma_x = 5.
sigma_y = 5.
s = 0.01/(2*np.pi*sigma_x*sigma_y)
x_zero = N/2
y_zero = N/2

gaussian = np.exp(-((x-x_zero)**2.0/(2*sigma_x**2.0)+(y-y_zero)**2.0/(2*sigma_y**2.0)))/(2*np.pi*sigma_x*sigma_y)
z = gaussian + random.standard_normal((N,N)) * s

plot2D (x, y, z, "Gaussiana_ruido")

Z = fft.fft2(z)
plot2D (fx, fy, np.abs(Z), "f_Gaussiana_ruido")

N_corte  = 10
for i in range(N):
    for j in range(N):
	if ((i+N/2)%N - N/2)**2 + ((j+N/2)%N - N/2)**2 > (N_corte)**2:
	   Z[i][j] = 0.0

plot2D (fx, fy, np.abs(Z), "f_Gaussiana_ruido_recorte")
z1 = fft.ifft2 (Z).real
plot2D (x, y, z1, "Gaussiana_ruido_recorte")
コード例 #6
0
ファイル: threshold.py プロジェクト: matpardo/astr-t2
    data = signal[:]
    while True:
       noise = []
       sigma = np.std(data)
       for val in data:
           if val < 3 * sigma:
              noise.append(val)
       if len(noise) == len(data): break
       data = noise[:]
    
    return np.mean(data),np.std(data)

def gaussian(x,stdev=1.0,mean=0.0):

    return np.exp(-1.0*(x-mean)**2.0/(2*stdev**2.0))/(stdev*np.sqrt(2*np.pi))

# Señal: se tiene una gaussiana y dos deltas como fuentes

N = 250
signal = np.zeros(N)
for i in range(65,136):
    signal[i] = 250.0 * gaussian(i,10.0,100.0) # Fuente (intensa) entre pixeles 65 y 135
signal[180] = 10.0 # Fuente (intensa) en pixel 180
signal[220] = 1.5  # Fuente (débil) en pixel 220
n_signal = signal + random.standard_normal(N) # Ruido con media 0 y desviación estándar 1

# Ejemplos: se usa thresholding con k = {2.0,2.5,3.0}

k = [2.0,2.5,3.0]
for i in range(len(k)):
    pos_sources,threshold = thresholding(n_signal,k[i])
コード例 #7
0
f = fft.fftfreq (N)

# Corte de frecuencias: funcion rectangular
Y = np.zeros(N)
Y[N/4:3*N/4] = 1
Y = fft.ifftshift(Y)
plot (f, Y, "f_rectangulo")

y = (fft.fftshift(fft.ifft(Y))).real
plot (x, y, "sinc")
plot (x[3*N/8:5*N/8], y[3*N/8:5*N/8], "sinc_zoom")

# Gaussiana + ruido + recorte en frecuencias
sigma = 50.
s = 0.1 / np.sqrt(2*np.pi*sigma**2)
y = np.exp (-(x-N/2)**2/(2*sigma**2))/np.sqrt(2*np.pi*sigma**2)
y += random.standard_normal(N) * s

plot (x, y, "Gaussiana_ruido")

Y = abs(fft.fft(y))
plot (f, Y, "f_Gaussiana_ruido")

N_corte = 10.
Y[N_corte : N - N_corte] = 0.
plot (f, Y, "f_Gaussiana_ruido_recorte")

y1 = fft.fftshift(fft.ifft (Y)).real
plot (x, y1, "Gaussiana_ruido_recorte")
plot (x, np.exp (-(x-N/2)**2/(2*sigma**2))/np.sqrt(2*np.pi*sigma**2), "Gaussiana_ruido_recorte", clear = False)
コード例 #8
0
import numpy as np
from scipy import random, optimize, interpolate
import matplotlib.pyplot as plt

# Generate oscillating signal on -2pi,2pi with noise
x = np.arange(-np.pi*2,np.pi*2,0.5)
x += random.standard_normal(np.shape(x))*0.1
y = np.sin(x) + random.standard_normal(np.shape(x))*0.1

# Model signal with spline interp (smoothing set to 0.5)
interp_function = interpolate.UnivariateSpline(x,y,s=0.5)

# New x range for data
newx = np.arange(-np.pi*2, np.pi*2, 0.1)
newy = interp_function(newx)

# Plot Data
plt.figure()
plt.plot(newx, newy,'b-',label='interp')
plt.plot(x, y, 'ko',label='raw data')
plt.legend()
plt.show()

# ... or fit the data
fitfunc = lambda p, x: p[0]*np.sin(2*np.pi/p[1]*x+p[2])
errfunc = lambda p, x, y: fitfunc(p, x) - y

p0 = [1., 5., 0.] # Initial guess for the parameters
p1, success = optimize.leastsq(errfunc, p0[:], args=(x, y))

plt.figure()
コード例 #9
0
ファイル: temp.py プロジェクト: viswajithiii/analyze-this
from sklearn import metrics
from scipy import random

c = []
d = []
e = []

for i in range(10000):
    a = random.random_integers(0, 1)
    b = random.standard_normal()
    c.append(a)
    d.append(b)
    e.append(a)
print metrics.normalized_mutual_info_score(c, d)
print metrics.adjusted_mutual_info_score(c, d)
print metrics.mutual_info_score(c, d)
print metrics.normalized_mutual_info_score(c, e)
print metrics.adjusted_mutual_info_score(c, e)
print metrics.mutual_info_score(c, e)
print c[:10]
print d[:10]
コード例 #10
0
ファイル: metodos_t1.py プロジェクト: kiel-cristian/Astro1
def addNoise (hdu, sigma):
    # Agrega ruido Gaussiano de desviacion estandard sigma a hdu.
    hdu += random.standard_normal((maxROW,maxCOL))*sigma