Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class main{
  5. /**
  6. *
  7. */
  8.  
  9.  
  10. public static void main(String[] args) {
  11. indata();
  12.  
  13. }
  14.  
  15.  
  16. public static void indata()
  17. {
  18. int numlayers = 0;
  19. int numinit = 0;
  20. int numhid1 = 0;
  21. int numout = 0;
  22.  
  23. net mind = new net();
  24.  
  25. try
  26. {
  27. //Scanner i = new Scanner(new File("j:/cs/MLP1.txt"));
  28. Scanner i = new Scanner(new File("n:/MLP.txt"));
  29. numlayers = i.nextInt();
  30. numinit = i.nextInt();
  31. numhid1 = i.nextInt();
  32. numout = i.nextInt();
  33. i.close();
  34. }catch(IOException e){}
  35.  
  36. System.out.println("Layers: "+numlayers);
  37. System.out.println("Init: "+numinit);
  38. System.out.println("Hid1: "+numhid1);
  39. System.out.println("Out: "+numout);
  40. mind.start(numlayers,numinit,numhid1,numout);
  41. }
  42.  
  43. }
  44.  
  45.  
  46.  
  47. import java.util.*;
  48.  
  49. public class net {
  50. /**
  51. *
  52. */
  53. ArrayList<layer> layers = new ArrayList<layer>();
  54. public void start(int numlayers, int numinit, int numhid1, int numout)
  55. {
  56. net net = new net();
  57. //set this new object to the same list as above(layers) otherwise net has NOTHING
  58. double out = 0;
  59. layer l = new layer();
  60.  
  61. int c = 0;
  62. int cb4 = 0;
  63. createfirst(l,numlayers, numinit, c);
  64. createnet(l, numlayers, numinit, numhid1, numout, c);
  65. //WTF IS THIS SHIT
  66. for(int p = 0; p < 4; p++)
  67. net.layers.set(p,layers.get(p));
  68. result(l, out, cb4, net);
  69. }
  70.  
  71. public void createfirst(layer initL, int numlayers, int numinit, int c)
  72. {
  73. c = numinit;
  74. initL.createlayer(c);
  75. layers.add(initL);
  76. }
  77.  
  78. public void createnet(layer l,int numlayers, int numinit, int numhid1, int numout, int c)
  79. {
  80. c = numhid1;
  81. l.createlayer(c);
  82. layers.add(l);
  83.  
  84. c = numout;
  85. l.createlayer(c);
  86. layers.add(l);
  87.  
  88. }
  89.  
  90. public void result(layer l, double out, int cb4, net net)
  91. {
  92. System.out.print(net.layers.get(0));
  93. l.calclayer(out, cb4, net);
  94. }
  95. }
  96.  
  97.  
  98.  
  99. import java.util.*;
  100.  
  101. public class layer {
  102. /**
  103. *
  104. */
  105. ArrayList<neuron> neurons = new ArrayList<neuron>();
  106.  
  107. neuron n = new neuron();
  108. public void createlayer(int c)
  109. {
  110.  
  111. System.out.println(c + "LAYER CALL");
  112. n.inwgt(c);
  113. neurons.add(n);
  114. }
  115.  
  116. public void calclayer(double out, int cb4, net net)
  117. {
  118. //dies here
  119. System.out.print(net.layers.get(0));
  120. n.calcfirst(out, cb4, net);
  121. }
  122. }
  123.  
  124.  
  125.  
  126. import java.util.*;
  127. import java.io.*;
  128.  
  129. public class neuron{
  130. /**
  131. *
  132. */
  133. ArrayList<Double> wgt = new ArrayList<Double>();
  134. double thold=.5;
  135. double Tin;
  136. double Tout;
  137. int n = 0;
  138. int count = 0;
  139. public void inwgt(int c)
  140. {
  141. try
  142. {
  143. if(c == 9){
  144. Scanner j = new Scanner(new File("n:/MLP1.txt"));
  145. while(j.hasNext())
  146. {
  147. count++;
  148. System.out.println(c + "CALL NEURON " + count);
  149. wgt.add(j.nextDouble());
  150.  
  151. }
  152. j.close();
  153. }
  154.  
  155. count = 0;
  156. if(c == 8){
  157. Scanner j = new Scanner(new File("n:/MLP2.txt"));
  158. while(j.hasNext())
  159. {
  160. count++;
  161. System.out.println(c + "CALL NEURON " + count);
  162. wgt.add(j.nextDouble());
  163.  
  164. }
  165. j.close();
  166. }
  167. count = 0;
  168. if(c == 3){
  169. Scanner j = new Scanner(new File("n:/MLP3.txt"));
  170. while(j.hasNext())
  171. {
  172. count++;
  173. System.out.println(c + "CALL NEURON " + count);
  174. wgt.add(j.nextDouble());
  175.  
  176. }
  177. j.close();
  178. }
  179. }catch(IOException e){}
  180. }
  181.  
  182. public double getout(){
  183. return Tout;
  184. }
  185.  
  186. public void calcfirst(double out, int cb4, net net)
  187. {
  188. System.out.print(net.layers.get(0));
  189. for(int p = 0; p < 8; p++){
  190. out = net.layers.get(0).neurons.get(p).wgt.get(p);
  191. }
  192. Tin = out;
  193. Tout = out;
  194. calcIn(out, cb4, net);
  195. }
  196. public void calcIn(double out, int cb4, net net){
  197. double sum = 0, temp;
  198. int prev = 0;
  199. if(cb4 == 9){
  200. prev = 1;
  201. }
  202. else if(cb4 == 8){
  203. prev = 2;
  204. }
  205. for(int p = 0; p < cb4; p++){
  206. temp = ((net.layers.get(prev).neurons.get(p).getout())*(wgt.get(p)));
  207. sum += temp;
  208. }
  209. Tout = sum;
  210. calcOut(net);
  211. }
  212.  
  213. public void calcOut(net net){
  214.  
  215. Tout = 1/(1+ Math.exp(-(Tout-thold)/0.01));
  216. for(int i = 0; i < 2; i++)
  217. {
  218. if (net.layers.get(2).neurons.get(i).getout() >= 1){
  219. if(i == 0){
  220. System.out.print("T");
  221. }
  222. if(i == 1){
  223. System.out.print("U");
  224. }
  225. if(i == 2){
  226. System.out.print("N");
  227. }
  228. }
  229. }
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement