Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Gnuplot import Gnuplot
- from random import uniform
- from Gnuplot import PlotItems
- class PruebaSeries:
- def __init__(self, lista, n):
- self.lista = lista
- self.parejas = self.listaAParejas(lista)
- self.n = float(n)
- return
- def graficar(self, serie='Parejas'):
- gp = Gnuplot(persist=1)
- gp('set title "Prueba de Series (Aleatoriedad)"')
- plot = PlotItems.Data(self.parejas, with_="dots", title=serie)
- gp.plot(plot)
- return
- def listaAParejas(self,lista):
- parejas = []
- for i in range(len(lista)-1):
- parejas.append([lista[i], lista[i+1]])
- return parejas
- def frecuenciaEsperada(self):
- return((len(self.lista)-1)/(self.n**2))
- def rangos(self):
- intervalos = 1/self.n
- lista = [0]
- for i in range(1,int(self.n)+1):
- lista.append(lista[i-1]+intervalos)
- return lista
- def cantidadEnRangos(self):
- rangos = self.rangos()
- conteo = {}
- for x in range(len(rangos)):
- for y in range(len(rangos)):
- key = str(rangos[x-1])+','+str(rangos[y-1])
- conteo[key] = 0
- for i in self.parejas:
- for x in range(len(rangos)-1):
- for y in range(len(rangos)-1):
- if(i[0] > rangos[x] and i[0] <= rangos[x+1] and i[1] > rangos[y] and i[1] <= rangos[y+1]):
- key = str(rangos[x])+','+str(rangos[y])
- conteo[key] += 1
- for i in rangos: # par contabilizar correctamente los intervalos se usan valores de 0 a 1 donde as posiciones de 1 se eliminan para no afectar al calculo
- conteo.pop('1.0,'+str(i), 0) # se elimina todas las combinaciones de 1 con otro valor
- conteo.pop(str(i)+',1.0', 0)
- return conteo
- def estadisticoCalculado(self):
- cantidades = self.cantidadEnRangos()
- FE = self.frecuenciaEsperada()
- Xo2 = (self.n**2/float(len(self.lista)-1.0))
- sumatoria = 0.0
- print cantidades
- for i in cantidades.values():
- print (i-FE)**2
- sumatoria += (i - FE)**2
- print sumatoria
- return (Xo2*sumatoria)
- if __name__=="__main__":
- lista = [0.25163, 0.65251, 0.36815, 0.64397, 0.04515, 0.83751, 0.14387, 0.51321, 0.72472, 0.05466]
- series = PruebaSeries(lista, 2)
- print series.estadisticoCalculado()
- series.graficar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement