def Ftest_pvalue(d1, d2): df1 = len(d1) - 1 df2 = len(d2) - 1 F = stats.variance(d1) / stats.variance(d2) single_tailed_pval = ss.f.cdf(F, df1, df2) double_tailed_pval = single_tailed_pval * 2 return (single_tailed_pval, double_tailed_pval)
def Ftest_pvalue(d1,d2): df1 = len(d1) - 1 df2 = len(d2) - 1 F = stats.variance(d1) /stats.variance(d2) single_tailed_pval = ss.f.cdf(F,df1,df2) double_tailed_pval = single_tailed_pval * 2 return double_tailed_pval print("F-test value:",Ftest_pvalue( d1,d2))
def krige_old(xpt, ypt, zpt, rg, x, y, vtype='spher'): """ krige function to interpolate over a vector of points of x,y coords using the base points xpt ypt and the vario distance rg (range)""" #print 'geom kr l 522',len(xpt),rg n = len(x) z0 = zeros(n) vari = 0.5 * variance(zpt) #print 'vari',vari def gamma(vtype, d, rg): # OA 25/10/18 if vtype in ['spher', None]: gam = 3 / 2. * d / rg - 1 / 2. * (d / rg)**3. gam[d > rg] = 1 elif vtype == 'gauss': gam = exp(-(d / rg)**2) elif vtype == 'gauss3': gam = exp(-(d / rg)**3) return gam for i in range(n): x0 = x[i] y0 = y[i] d = sqrt((x0 - xpt)**2 + (y0 - ypt)**2) ind = argsort(d) x1, y1, z1 = xpt[ind[:16]], ypt[ind[:16]], zpt[ind[:16]] # select closest 16 points xm1, ym1 = meshgrid(x1, y1) d = sqrt((xm1 - transpose(xm1))**2. + (ym1 - transpose(ym1))**2.) gam = gamma(vtype, d, rg) # OA 25/10/18 l1 = len(x1) + 1 A = ones((l1, l1)) #starting the A matrix A[:-1, :-1] = gam * vari A[-1, -1] = 0. d = sqrt((x0 - x1)**2. + (y0 - y1)**2.) gam = gamma(vtype, d, rg) # OA 25/10/18 B = ones((l1, 1)) B[:-1, 0] = gam * vari lb = solve(A, B) z0[i] = sum(z1 * transpose(lb[:-1])) #z0 = clip(z0,min(zpt)*0.9,max(zpt)*1.1) return z0
import constante from funciones import normal_por_aceptacion_rechazo z = normal_por_aceptacion_rechazo(media=35, de=5) hist_data = [z] # ploteo data fig = ff.create_distplot(hist_data, [""], bin_size=.01, curve_type='normal') fig['layout'].update(title='Normal empirica vs Normal de python') py.plot(fig, filename='normal empirica vs normal de python') # Mostramos media, varianza y moda muestrales y teoricos media = st.mean(z) varianza = st.variance(z) moda = max(set(z), key=z.count) print("Media muestral: {0} Varianza muestral: {1} Moda muestral: {2}".format(media, varianza, moda)) print("Media teorica: {0} Varianza teorica: {1} Moda teorica: {2}".format(35, 5*5, 35)) # RESPUESTA 5 from funciones import gcl_uniforme import constante # genero numero aleatorios uniformes x_n = constante.SEMILLA uniformes = [] empiricos = [] for _ in range(constante.CANT_EXPERIMENTOS): x_n = gcl_uniforme(x_n)
def featurescalculator(sigbufs, n): Desface = 12000 x = 0 + Desface # desface en # de muestras donde inicia el examen aumento = 0 segundos = int( (len(sigbufs[3, :]) - Desface) / 200) # numero de segundos del examen Features = np.empty(((n - 5) * segundos, 32)) # matriz de caracteristicas for a in np.arange(segundos): for i in np.arange((n - 5)): #n-2 numero de canales warnings.filterwarnings("ignore") #TIEMPO minimo = scipy.stats.tmin(sigbufs[i, x:x + 200]) maximo = scipy.stats.tmax(sigbufs[i, x:x + 200]) kurto = scipy.stats.kurtosis(sigbufs[i, x:x + 200]) energ = energia(sigbufs[i, x:x + 200]) sha = shannon(sigbufs[i, x:x + 200]) #DWT cA5, cD4, cD3, cD2, cD1 = pywt.wavedec(sigbufs[i, x:x + 200], 'db4', level=4) varianzaA5 = stats.variance(cA5) energA5 = energia(cA5) shaA5 = shannon(cA5) actiA5 = hjorth(cA5) varianzaD4 = stats.variance(cD4) energD4 = energia(cD4) rD4 = renyi(cD4) shaD4 = shannon(cD4) EHD4 = hurst(cD4) actiA4 = hjorth(cD4) varianzaD3 = stats.variance(cD3) desviacionD3 = stats.stdev(cD3) energD3 = energia(cD3) rD3 = renyi(cD3) apenD3 = ApEn(cD3, 2, 3) shaD3 = shannon(cD3) minimoD2 = scipy.stats.tmin(cD2) maximoD2 = scipy.stats.tmax(cD2) desviacionD2 = stats.stdev(cD2) kurtoD2 = scipy.stats.kurtosis(cD2) energD2 = energia(cD2) rD2 = renyi(cD2) shaD2 = shannon(cD2) minimoD1 = scipy.stats.tmin(cD1) maximoD1 = scipy.stats.tmax(cD1) rD1 = renyi(cD1) #FFT nee = len(sigbufs[i, x:x + 200]) # tamaño Y = fft(sigbufs[i, x:x + 200]) / nee Yn = abs(Y) mediaf = stats.mean(Yn) #print (signal_labels[i]) Features[i + aumento] = [ minimo, maximo, kurto, energ, sha, varianzaA5, energA5, shaA5, actiA5, varianzaD4, energD4, rD4, shaD4, EHD4, actiA4, varianzaD3, desviacionD3, energD3, rD3, apenD3, shaD3, minimoD2, maximoD2, desviacionD2, kurtoD2, energD2, rD2, shaD2, minimoD1, maximoD1, rD1, mediaf ] #Labels=signal_labels[i] #print (Labels) x = x + 200 aumento = aumento + 18 ##16 -- n-2, 21 -- n-4, 15 -- n-3, 19 -- n-4, 43 ---- n-8 return Features