This repository has been archived by the owner on Apr 10, 2020. It is now read-only.
/
index.py
300 lines (214 loc) · 12.3 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import Normal as normalDistribution
import Weibull as weibullDistribution
import Exponential as exponDistribution
import Uniform as uniformDistribution
import Erlang as erlangDistribution
import Triangular as triangularDistribution
import ChiSquare as chiDistribution
import Binomial as binomialDistribution
import Poisson as poissonDistribution
import scipy.stats as st
import numpy as np
import math
import os
def returnToMenu():
print("\n:::::::::::::::::::::::::::::")
print("1) Regresar al menú principal")
print("2) Salir")
option = int(input("\n------>Opcion :"))
if option == 1:
return True
return False
#MENU PRINCIPAL DEL PROGRAMA
backToMenu = True
optionSelected = 0
while backToMenu:
os.system ("cls")
print("\n\t::::Simulación de variables aleatorias según una distribución propuesta::::")
print("\n--Opciones de Distribuciones--")
print("\n1) Distribución Normal.")
print("2) Distribución Weibull.")
print("3) Distribución Exponecial.")
print("4) Distribución Erlang.")
print("5) Distribución Uniforme Continua.")
print("6) Distribución Triangular.")
print("7) Distribución Chi cuadrado.")
print("8) Distribución Binomial.")
print("9) Distribución Poisson.")
print("\n0) Salir.")
optionSelected = int(input("\n------>Opcion :"))
# DISTRIBUCION NORMAL
if optionSelected == 1 :
os.system("cls")
nombreDistribucion = "Distribución Normal"
print("\t::",nombreDistribucion,"::")
#Parametros necesarios para la generació1n
media = float(input("\n->Ingrese la media :"))
desviacion = float(input("->Ingrese la desviación estandar :"))
numeroDatos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
tipoDistribucion = st.norm(media, desviacion)
objNormal = normalDistribution.Normal(numeroDatos, tipoDistribucion, nivelDeSignificacia, nombreDistribucion,
media, desviacion)
legendHistogram = r'$\mu$' + "=" + str(
"{0:.2f}".format(objNormal.meanGenerated)) + " ; " + r'$\sigma$' + "=" + str(
"{0:.2f}".format(objNormal.stdDesvGenerated))
legendDensity = r'$\mu$' + "=" + str(media) + " ; " + r'$\sigma$' + "=" + str(desviacion)
axisX = np.linspace((objNormal.mean - 3 * objNormal.stdDesvGenerated),
(objNormal.mean + 3 * objNormal.stdDesvGenerated), 100)
objNormal.chiSquareTest()
objNormal.graph(legendHistogram, legendDensity, axisX)
# DISTRIBUCION WEIBULL
elif optionSelected ==2:
os.system("cls")
nombreDistribucion = "Distribución Weibull"
print("\t::", nombreDistribucion, "::")
# Parametros necesarios para la generación
forma = float(input("\n->Ingrese párametro de forma:"))
escala= float(input("->Ingrese párametro de escala :"))
localizacion = float(input("->Ingrese párametro de localización :"))
numeroDatos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
tipoDistribucion = st.weibull_min(forma, localizacion, escala)
objWeibull = weibullDistribution.Weibull(numeroDatos, tipoDistribucion, nivelDeSignificacia, nombreDistribucion,
forma, escala, localizacion)
legendHistogram = r'Forma' + "=" + str(
"{0:.2f}".format(objWeibull.formGenerated)) + " ; " + r'Escala' + "=" + str(
"{0:.2f}".format(objWeibull.scaleGenerated)) + \
" ; " + r'Localización' + "=" + str("{0:.2f}".format(objWeibull.locationGenerated))
axisX = np.linspace(localizacion, objWeibull.mean + objWeibull.des * 6, 100)
legendDensity = r'Forma' + "=" + str(objWeibull.form) + " ; " + r'Escala' + "=" + str(
objWeibull.scale) + " ; " + r'Localizacion' + "=" + str(objWeibull.location)
objWeibull.chiSquareTest()
objWeibull.graph(legendHistogram, legendDensity, axisX)
# DISTRIBUCION EXPONENCIAL
elif optionSelected == 3:
os.system("cls")
nombreDistribucion = "Distribución Exponencial"
print("\t::", nombreDistribucion, "::")
# Parametros necesarios para la generació1n
media = float(input("->Ingrese la media :"))
numeroDatos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
tipoDistribucion = st.expon(1, media)
objExpon = exponDistribution.Exponential(numeroDatos, tipoDistribucion, nivelDeSignificacia, nombreDistribucion,
media)
legendHistogram = r'$\mu$' + "="+ str("{0:.2f}".format(objExpon.meanGenerated))
legendDensity = r'$\mu$' + "=" + str(objExpon.mean)
axisX = np.linspace(1, objExpon.mean + 6 * objExpon.des, 100)
objExpon.chiSquareTest()
objExpon.graph(legendHistogram, legendDensity, axisX)
# DISTRIBUCION ERLANG
elif optionSelected == 4:
os.system("cls")
nombreDistribucion = "Distribución Erlang"
print("\t::", nombreDistribucion, "::")
# Parametros necesarios para la generación
forma = float(input("->Ingrese la forma :"))
valorEsperado = float(input("->Ingrese el valor esperado :"))
numeroDatos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
tipoDistribucion = st.erlang(forma, 0, valorEsperado)
nombreDistribucion = "Distribución Erlang"
objErlang = erlangDistribution.Erlang(numeroDatos, tipoDistribucion, nivelDeSignificacia, nombreDistribucion,
forma, valorEsperado)
legendHistogram = r'$\kappa$' + "=" + str("{0:.2f}".format(objErlang.formGenerated)) + " ; " + r'$\theta$' + "=" + str("{0:.2f}".format(objErlang.expectedValueGenerated))
legendDensity = r'$\kappa$' + "=" + str(forma) + " ; " + r'$\theta$' + "=" + str(valorEsperado)
axisX = np.linspace(0, objErlang.median + 6 * objErlang.iqr, numeroDatos)
os.system('cls')
objErlang.chiSquareTest()
objErlang.graph(legendHistogram, legendDensity, axisX)
# DISTRIBUCION UNIFORME CONTINUA
elif optionSelected == 5:
os.system("cls")
nombreDistribucion = "Distribución Uniforme Continua"
print("\t::", nombreDistribucion, "::")
# Parametros necesarios para la generación
limiteInferior = float(input("->Ingrese el límite inferior :"))
limiteSuperior = float(input("->Ingrese el límite superior :"))
numeroDatos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
tipoDistribucion = st.uniform(limiteInferior, (limiteSuperior - limiteInferior))
nombreDistribucion = "Distribución General Uniforme"
objUniforme = uniformDistribution.Uniform(numeroDatos, tipoDistribucion, nivelDeSignificacia,
nombreDistribucion, limiteInferior, limiteSuperior)
legendDensity = 'a' + "=" + str(limiteInferior) + " ; " + 'b' + "=" + str(limiteSuperior)
legendHistogram = 'a' + "=" + str("{0:.2f}".format(objUniforme.loc)) + " ; " + 'b' + "=" + str("{0:.2f}".format(objUniforme.scale))
axisX = np.linspace(limiteInferior, limiteSuperior, 100)
objUniforme.chiSquareTest()
objUniforme.graph(legendHistogram, legendDensity, axisX)
# DISTRIBUCION TRIANGULAR
elif optionSelected == 6:
os.system("cls")
nombreDistribucion = "Distribución Triangular"
print("\t::", nombreDistribucion, "::")
# Parametros necesarios para la generación
limiteInferior = float(input("->Ingrese el límite inferior :"))
limiteSuperior = float(input("->Ingrese el límite superior :"))
moda = float(input("->Ingrese parametro de forma (entre 0 y 1):"))
numeroDatos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
tipoDistribucion = st.triang(moda, limiteInferior,limiteSuperior-limiteInferior)
objChi2 = triangularDistribution.Triangular(numeroDatos, tipoDistribucion, nivelDeSignificacia,
nombreDistribucion, moda, limiteInferior, limiteSuperior)
legendDensity = 'a' + "=" + str(limiteInferior) + " ; " + 'b' + "=" + str(limiteSuperior)+ " ; " + 'x' + "=" + str(moda)
legendHistogram = 'a' + "=" + str("{0:.2f}".format(objChi2.limInfGenerated)) + " ; " + 'b' + "=" + str("{0:.2f}".format(objChi2.limSupGenerated)) + " ; " + 'x' + "=" + str(
"{0:.2f}".format(objChi2.modaGenerated))
axisX = np.linspace(limiteInferior, limiteSuperior, 100)
objChi2.chiSquareTest()
objChi2.graph(legendHistogram, legendDensity, axisX)
# DISTRIBUCION CHICUADRADO
elif optionSelected == 7:
os.system("cls")
nombreDistribucion = "Distribución Chi Cuadrada"
print("\t::", nombreDistribucion, "::")
# Parametros necesarios para la generación
df = float(input("->Ingrese grados de libertad :"))
numeroDatos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
tipoDistribucion = st.chi2(df)
objChi2 = chiDistribution.ChiSquare(numeroDatos, tipoDistribucion, nivelDeSignificacia,
nombreDistribucion,df)
legendDensity = r'k' + "=" + str( "{0:.2f}".format(df))
legendHistogram = r'k' + "=" + str( "{0:.2f}".format(objChi2.dfGenerated))
axisX = np.linspace(0,objChi2.mean +6 * objChi2.std, numeroDatos)
objChi2.chiSquareTest()
objChi2.graph(legendHistogram, legendDensity, axisX)
#DISTRIBUICON BINOMIAL
elif optionSelected == 8:
os.system("cls")
nombreDistribucion = "Distribución Binomial"
print("\t::", nombreDistribucion, "::")
# Parametros necesarios para la generació1n
probabilitySuccess = float(input("->Ingrese la probabilidad de éxito :"))
numeroIntentos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
binomial = st.binom(numeroIntentos, probabilitySuccess)
objBinomial = binomialDistribution.Binomial(numeroIntentos, binomial, nivelDeSignificacia, nombreDistribucion,
probabilitySuccess)
objBinomial.chiSquareTest()
objBinomial.graph()
#DISTRIBUICON POISSON
elif optionSelected == 9:
os.system("cls")
nombreDistribucion = "Distribución de Poisson"
print("\t::", nombreDistribucion, "::")
# Parametros necesarios para la generació1n
media = float(input("->Ingrese la media:"))
numeroDatos = int(input("->Ingrese el número de variables aleatorias a generar :"))
#nivelDeSignificacia = float(input("->Ingrese el nivel de significancia para la prueba chi cuadrado :"))
nivelDeSignificacia = 0.05
distType = st.poisson(media)
objPoisson = poissonDistribution.Poisson(numeroDatos, distType, nivelDeSignificacia, nombreDistribucion, media)
objPoisson.chiSquareTest()
objPoisson.graph()
else:
backToMenu = False