-
Notifications
You must be signed in to change notification settings - Fork 8
Deber de comparacion del tiempo de ordenamiento entre bubble sort e i… #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
30218e6
812911a
0673b0f
7b28925
539938e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,15 @@ | |
| def signo(net): | ||
| fsigno = [1. if elem >=0 else -1. for elem in net] | ||
| return fsigno | ||
|
|
||
| def paso(net): | ||
| fpaso = [1. if elem >= 0 else 0. for elem in net] | ||
| return fpaso | ||
| def sigmoide(net): | ||
| fsigmoide=1/(1+np.exp(elem) for elem in net) | ||
| return fsigmoide | ||
| def tanhip(net): | ||
| ftanhip=((np.exp(elem)-np.exp(-elem))/(np.exp(elem)+np.exp(-elem)) for elem in net ) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Estas devolviendo un vector? Tal vez la sintaxis debería ser |
||
| return ftanhip | ||
| def signo_escalar(net_escalar): | ||
| y_pred = 1 if net_escalar >=0 else -1 | ||
| return y_pred | ||
|
|
@@ -31,6 +39,11 @@ def funcion_error(y_verdadero, y_predicho): | |
| if y_i != y_verdadero[indice]: | ||
| cont = cont+1 | ||
| return cont | ||
| def predecir(x,w_new): | ||
| #Sacar la salida del perceptron para un x dado como deber | ||
| net_final=net(x_input=x,w=w_new) | ||
| y_final=signo_escalar(net_final) | ||
| return y_final | ||
|
|
||
| #%% programa | ||
| # Definiendo el dataset de entrada | ||
|
|
@@ -100,5 +113,7 @@ def funcion_error(y_verdadero, y_predicho): | |
| else: | ||
| epoca += 1 | ||
| continue | ||
|
|
||
| print('El modelo es: {}'.format(W_new)) | ||
| X_new=np.array([1,-1,-1],dtype=np.float) | ||
| print('El modelo es: {}'.format(W_new)) | ||
| y_predicha=predecir(X_new,W_new) | ||
| print('La y predicha es: {}'.format(y_predicha)) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| class perceptron: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Las clases por convención se declaran con Mayúsculas, esto es Perceptron |
||
|
|
||
| def insert_matriz(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recomendaría que no cargue elemento a elemento los datos. Esto esta bien para ejemplos tipo toy como AND y OR y XOR, pero si tengo cientos de datos? Preferible que cargue la matriz de datos X desde afuera y mas bien extraiga de la misma las filas y columnas para disponer del numero de muestras y del numero de componentes |
||
| # La mas sencilla e intuitiva | ||
| self.numero_filas=2 | ||
| numero_columnas=2 | ||
| matriz = [] | ||
| for i in range(numero_filas): | ||
| matriz.append([]) | ||
| for j in range(numero_columnas): | ||
| print("Ingrese elemento:") | ||
| matriz[i].append(input()) | ||
| print(matriz) | ||
|
|
||
| def insert_arreglo(self): | ||
| arr = [] | ||
| self.numero_filas = 2 | ||
| for i in range(self.numero_filas): | ||
| print("Ingrese elemento:") | ||
| arr.append(input()) | ||
| print(arr) | ||
| def learn1(self): | ||
| learn_rate = 0.1 | ||
| return learn_rate | ||
| def learn2(self): | ||
| learn_rate = 0.01 | ||
| return learn_rate | ||
| def learn3(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seguramente en esta parte Pycharm te pinta un warning, ya que este método al no utilizar self pasa a ser una funcion cualquiera y no es necesario que este dentro de la clase. Revisar |
||
| learn_rate = 0.001 | ||
| return learn_rate | ||
| def numbers_learn(self,argument): | ||
| switcher = { | ||
| 0: self.learn1, | ||
| 1: self.learn2, | ||
| 2: self.learn3, | ||
| } | ||
| return switcher.get(argument,lambda: "Invalid") | ||
|
|
||
| def signo(self,net): | ||
| fsigno = [1. if elem >=0 else -1. for elem in net] | ||
| return fsigno | ||
| def paso(self,net): | ||
| fpaso = [1. if elem >= 0 else 0. for elem in net] | ||
| return fpaso | ||
| def sigmoide(self,net): | ||
| fsigmoide=1/(1+np.exp(elem) for elem in net) | ||
| return fsigmoide | ||
| def tanhip(self,net): | ||
| ftanhip=((np.exp(elem)-np.exp(-elem))/(np.exp(elem)+np.exp(-elem)) for elem in net ) | ||
| return ftanhip | ||
|
|
||
| def funcion(self,argumento): | ||
| switcher = { | ||
| 1: self.signo(), | ||
| 2: self.paso(), | ||
| 3: self.sigmoide(), | ||
| 4: self.tanhip(), | ||
| } | ||
| # Get the function from switcher dictionary | ||
| return switcher.get(argumento, lambda: "Invalid") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import time | ||
| import random | ||
|
|
||
| def listaAleatorios(): | ||
| print("Ingrese cuantos numeros aleatorios desea obtener:") | ||
| n = int(input()) | ||
| lista= [] | ||
| for i in range(n): | ||
| lista.append(random.randint(1, 10000)) | ||
| return lista | ||
|
|
||
| def bubbleSort(arr): | ||
| time_ini=time.time() | ||
| n = len(arr) | ||
| # Traverse through all array elements | ||
| for i in range(n): | ||
|
|
||
| # Last i elements are already in place | ||
| for j in range(0, n - i - 1): | ||
|
|
||
| # traverse the array from 0 to n-i-1 | ||
| # Swap if the element found is greater | ||
| # than the next element | ||
| if arr[j] > arr[j + 1]: | ||
| arr[j], arr[j + 1] = arr[j + 1], arr[j] | ||
| time_fin=time.time() | ||
| time_dif=time_fin-time_ini | ||
| return arr,time_dif | ||
|
|
||
| def insertionSort(arr): | ||
| # Traverse through 1 to len(arr) | ||
| time_ini = time.time() | ||
| for i in range(1, len(arr)): | ||
|
|
||
| key = arr[i] | ||
|
|
||
| # Move elements of arr[0..i-1], that are | ||
| # greater than key, to one position ahead | ||
| # of their current position | ||
| j = i - 1 | ||
| while j >= 0 and key < arr[j]: | ||
| arr[j + 1] = arr[j] | ||
| j -= 1 | ||
| arr[j + 1] = key | ||
| time_fin = time.time() | ||
| time_dif = time_fin - time_ini | ||
| # Driver code to test above | ||
| return arr,time_dif | ||
|
|
||
| def main(): | ||
| arreglo=listaAleatorios() | ||
| print("El arreglo a ordenar es: {} ".format(arreglo)) | ||
| ordenamiento_bubble,time_bubble=bubbleSort(arreglo) | ||
| ordenamiento_insertion,time_insertion=insertionSort(arreglo) | ||
| print("El arreglo ordenado por bubblesort es: {}".format(ordenamiento_bubble)) | ||
| print("El tiempo_bubble es : {}".format(time_bubble)) | ||
| print("El arreglo ordenado por insertion sort es: {} ".format(ordenamiento_insertion)) | ||
| print("El tiempo_insertion es : {}".format(time_insertion)) | ||
| if __name__=='__main__': | ||
| main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me parece que la sigmoide eleva a la -x