elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  contribucion una red neuronal con algebra lineal
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: contribucion una red neuronal con algebra lineal  (Leído 3,915 veces)
sapito169


Desconectado Desconectado

Mensajes: 628



Ver Perfil
contribucion una red neuronal con algebra lineal
« en: 10 Agosto 2022, 19:07 pm »

hola este es un pequeño ejemplo de como se hace una red neuronal en java


Código
  1.  
  2. package matrix;
  3.  
  4. import java.util.function.BiFunction;
  5. import java.util.function.Function;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. double[][] training_set_inputs = new double[][] { { 0, 0, 1 }, { 1, 1, 1 }, { 1, 0, 1 }, { 0, 1, 0 } };
  10. double[][] training_set_outputs = t(new double[][] { { 0, 1, 1, 0 } });
  11. double[][] synaptic_weights = new double[][] { { -0.5 }, { -0.5}, { -0.5} };
  12.  
  13. for (int c = 0; c < 700_000; c++) {
  14. double[][] output = div(1, sum(1, exp(neg(dot(training_set_inputs, synaptic_weights)))));
  15. double[][] error = subtract(training_set_outputs,output);
  16. double[][] sigder = mul(output,min(1,output));
  17. double[][] adjustment = dot(t( training_set_inputs ),mul(error, sigder));
  18. synaptic_weights= sum(synaptic_weights,adjustment);
  19. }
  20.  
  21. print(div(1, sum(1, exp(neg(dot( new double[][] { {1 , 0 , 0 } }, synaptic_weights))))));
  22. }
  23.  
  24.  
  25. private static void println() {
  26. System.out.println();
  27. }
  28.  
  29. static double[][] dot(double[][] a, double[][] b) {
  30. double[][] result = zero(a.length, b[0].length);
  31.  
  32. for (int i = 0; i < a.length; i++) {
  33. for (int j = 0; j < a[0].length; j++) {
  34. for (int k = 0; k < b[0].length; k++) {
  35. result[i][k] += a[i][j] * b[j][k];
  36. }
  37. }
  38. }
  39.  
  40. return result;
  41. }
  42.  
  43. static double[][] operate(double[][] a, double[][] b, BiFunction<Double, Double, Double> call) {
  44. double[][] result = zero(a.length, b[0].length);
  45.  
  46. for (int i = 0; i < a.length; i++) {
  47. for (int j = 0; j < a[0].length; j++) {
  48. result[i][j] = call.apply(a[i][j], b[i][j]);
  49.  
  50. }
  51. }
  52.  
  53. return result;
  54. }
  55.  
  56. static double[][] operate(double a, double[][] b, BiFunction<Double, Double, Double> call) {
  57. double[][] result = zero(b.length, b[0].length);
  58.  
  59. for (int i = 0; i < b.length; i++) {
  60. for (int j = 0; j < b[0].length; j++) {
  61. result[i][j] = call.apply(a, b[i][j]);
  62.  
  63. }
  64. }
  65.  
  66. return result;
  67. }
  68.  
  69. static double[][] operate(double[][] a, Function<Double, Double> call) {
  70. double[][] result = zero(a.length, a[0].length);
  71.  
  72. for (int i = 0; i < a.length; i++) {
  73. for (int j = 0; j < a[0].length; j++) {
  74. result[i][j] = call.apply(a[i][j]);
  75.  
  76. }
  77. }
  78.  
  79. return result;
  80. }
  81.  
  82. static double[][] div(double a, double[][] b) {
  83.  
  84. return operate(a, b, (p, q) -> p / q);
  85. }
  86.  
  87. static double[][] sum(double a, double[][] b) {
  88.  
  89. return operate(a, b, (p, q) -> p + q);
  90. }
  91.  
  92. static double[][] min(double a, double[][] b) {
  93.  
  94. return  operate(a, b, (p, q) -> p - q);
  95. }
  96.  
  97.  
  98. static double[][] div(double[][] a, double[][] b) {
  99.  
  100. return operate(a, b, (p, q) -> p / q);
  101. }
  102.  
  103. static double[][] mul(double[][] a, double[][] b) {
  104.  
  105. return operate(a, b, (p, q) -> p * q);
  106. }
  107.  
  108. static double[][] mul(double a, double[][] b) {
  109.  
  110. return operate(a, b, (p, q) -> p * q);
  111. }
  112.  
  113. static double[][] sum(double[][] a, double[][] b) {
  114.  
  115. return operate(a, b, (p, q) -> p + q);
  116. }
  117.  
  118. static double[][] subtract(double[][] a, double[][] b) {
  119.  
  120. return operate(a, b, (p, q) -> p - q);
  121. }
  122.  
  123. static double[][] exp(double[][] a) {
  124. return operate(a, (p) -> Math.exp(p));
  125. }
  126.  
  127. static double[][] neg(double[][] a) {
  128. return mul(-1, a);
  129. }
  130.  
  131. private static double[][] zero(int rows, int cols) {
  132. return new double[rows][cols];
  133. }
  134.  
  135.  
  136.  
  137.  
  138. static double[][] expand(double[][] a, double value) {
  139. int firstDimension = a.length;
  140. int secondDimensio = a[0].length;
  141. double [][]result = zero(firstDimension, secondDimensio);
  142. for (int i = 0; i < firstDimension; i++) {
  143. for (int j = 0; j < secondDimensio; j++) {
  144.  
  145. result[i][j] = value;
  146. }
  147.  
  148. }
  149. return result;
  150. }
  151.  
  152. static double[][] t(double[][] a) {
  153. int firstDimension = a.length;
  154. int secondDimensio = a[0].length;
  155. double[][] result = new double[secondDimensio][firstDimension];
  156. for (int i = 0; i < firstDimension; i++) {
  157. for (int j = 0; j < secondDimensio; j++) {
  158.  
  159. result[j][i] = a[i][j];
  160. }
  161.  
  162. }
  163. return result;
  164. }
  165.  
  166. static void print(double[][] a) {
  167. int firstDimension = a.length;
  168. int secondDimensio = a[0].length;
  169.  
  170. for (int i = 0; i < firstDimension; i++) {
  171. for (int j = 0; j < secondDimensio; j++) {
  172. String coma = secondDimensio - 1 == j ? "" : " , ";
  173. System.out.print(a[i][j] + coma);
  174. }
  175. println();
  176. }
  177. }
  178. }
  179.  
  180.  
  181.  


« Última modificación: 11 Agosto 2022, 21:49 pm por sapito169 » En línea

Tachikomaia


Desconectado Desconectado

Mensajes: 1.180


Superhacker (es broma xD )


Ver Perfil
Re: contribucion una red neural con algebra lineal
« Respuesta #1 en: 11 Agosto 2022, 21:28 pm »

¿Es algo diferente a una red neuronal? Tuve que googlear entre comillas red neural para que me apareciera algo que no tuviera que ver con redes neuronales, aunque aún así parece lo mismo. ¿Es una nueva forma de referirse a eso o tienen mala memoria auditiva/visual?


En línea

sapito169


Desconectado Desconectado

Mensajes: 628



Ver Perfil
Re: contribucion una red neuronal con algebra lineal
« Respuesta #2 en: 11 Agosto 2022, 21:51 pm »

estaba mal escrito ya lo corregi
En línea

sapito169


Desconectado Desconectado

Mensajes: 628



Ver Perfil
Re: contribucion una red neuronal con algebra lineal
« Respuesta #3 en: 12 Agosto 2022, 21:23 pm »

se viene ejemplo de mnist

con posibilidad de escribir numero con un pincel echo en javafx
En línea

Tachikomaia


Desconectado Desconectado

Mensajes: 1.180


Superhacker (es broma xD )


Ver Perfil
Re: contribucion una red neuronal con algebra lineal
« Respuesta #4 en: 12 Agosto 2022, 21:36 pm »

Tras haber investigado un poco más noté que neural es neuronal en inglés, así que no es del todo que estuviera mal escrito, solo que mezclaba dos idiomas. Yo es que nunca había visto escrito eso en inglés o no recuerdo haberlo hecho.

Saludos!
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Red Neuronal (BackPropagation)
Programación C/C++
brians444 2 11,988 Último mensaje 26 Enero 2012, 14:31 pm
por brians444
[Vbs] Calculo de un determinante Algebra Lineal
Scripting
.:: KsV ::. 0 2,062 Último mensaje 11 Julio 2015, 23:20 pm
por .:: KsV ::.
Ayuda - ¿Estará correcta esta solución de ejercicio de álgebra lineal?
Foro Libre
JADP 0 1,164 Último mensaje 9 Septiembre 2018, 04:50 am
por JADP
red neuronal
Foro Libre
AndreaSol 2 1,592 Último mensaje 6 Noviembre 2019, 01:09 am
por Markks
Entrenamiento de red Neuronal
.NET (C#, VB.NET, ASP)
rigorvzla 1 2,470 Último mensaje 30 Mayo 2020, 01:32 am
por Emertech
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines