Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class main{
- /**
- *
- */
- public static void main(String[] args) {
- indata();
- }
- public static void indata()
- {
- int numlayers = 0;
- int numinit = 0;
- int numhid1 = 0;
- int numout = 0;
- net mind = new net();
- try
- {
- //Scanner i = new Scanner(new File("j:/cs/MLP1.txt"));
- Scanner i = new Scanner(new File("n:/MLP.txt"));
- numlayers = i.nextInt();
- numinit = i.nextInt();
- numhid1 = i.nextInt();
- numout = i.nextInt();
- i.close();
- }catch(IOException e){}
- System.out.println("Layers: "+numlayers);
- System.out.println("Init: "+numinit);
- System.out.println("Hid1: "+numhid1);
- System.out.println("Out: "+numout);
- mind.start(numlayers,numinit,numhid1,numout);
- }
- }
- import java.util.*;
- public class net {
- /**
- *
- */
- ArrayList<layer> layers = new ArrayList<layer>();
- public void start(int numlayers, int numinit, int numhid1, int numout)
- {
- net net = new net();
- //set this new object to the same list as above(layers) otherwise net has NOTHING
- double out = 0;
- layer l = new layer();
- int c = 0;
- int cb4 = 0;
- createfirst(l,numlayers, numinit, c);
- createnet(l, numlayers, numinit, numhid1, numout, c);
- //WTF IS THIS SHIT
- for(int p = 0; p < 4; p++)
- net.layers.set(p,layers.get(p));
- result(l, out, cb4, net);
- }
- public void createfirst(layer initL, int numlayers, int numinit, int c)
- {
- c = numinit;
- initL.createlayer(c);
- layers.add(initL);
- }
- public void createnet(layer l,int numlayers, int numinit, int numhid1, int numout, int c)
- {
- c = numhid1;
- l.createlayer(c);
- layers.add(l);
- c = numout;
- l.createlayer(c);
- layers.add(l);
- }
- public void result(layer l, double out, int cb4, net net)
- {
- System.out.print(net.layers.get(0));
- l.calclayer(out, cb4, net);
- }
- }
- import java.util.*;
- public class layer {
- /**
- *
- */
- ArrayList<neuron> neurons = new ArrayList<neuron>();
- neuron n = new neuron();
- public void createlayer(int c)
- {
- System.out.println(c + "LAYER CALL");
- n.inwgt(c);
- neurons.add(n);
- }
- public void calclayer(double out, int cb4, net net)
- {
- //dies here
- System.out.print(net.layers.get(0));
- n.calcfirst(out, cb4, net);
- }
- }
- import java.util.*;
- import java.io.*;
- public class neuron{
- /**
- *
- */
- ArrayList<Double> wgt = new ArrayList<Double>();
- double thold=.5;
- double Tin;
- double Tout;
- int n = 0;
- int count = 0;
- public void inwgt(int c)
- {
- try
- {
- if(c == 9){
- Scanner j = new Scanner(new File("n:/MLP1.txt"));
- while(j.hasNext())
- {
- count++;
- System.out.println(c + "CALL NEURON " + count);
- wgt.add(j.nextDouble());
- }
- j.close();
- }
- count = 0;
- if(c == 8){
- Scanner j = new Scanner(new File("n:/MLP2.txt"));
- while(j.hasNext())
- {
- count++;
- System.out.println(c + "CALL NEURON " + count);
- wgt.add(j.nextDouble());
- }
- j.close();
- }
- count = 0;
- if(c == 3){
- Scanner j = new Scanner(new File("n:/MLP3.txt"));
- while(j.hasNext())
- {
- count++;
- System.out.println(c + "CALL NEURON " + count);
- wgt.add(j.nextDouble());
- }
- j.close();
- }
- }catch(IOException e){}
- }
- public double getout(){
- return Tout;
- }
- public void calcfirst(double out, int cb4, net net)
- {
- System.out.print(net.layers.get(0));
- for(int p = 0; p < 8; p++){
- out = net.layers.get(0).neurons.get(p).wgt.get(p);
- }
- Tin = out;
- Tout = out;
- calcIn(out, cb4, net);
- }
- public void calcIn(double out, int cb4, net net){
- double sum = 0, temp;
- int prev = 0;
- if(cb4 == 9){
- prev = 1;
- }
- else if(cb4 == 8){
- prev = 2;
- }
- for(int p = 0; p < cb4; p++){
- temp = ((net.layers.get(prev).neurons.get(p).getout())*(wgt.get(p)));
- sum += temp;
- }
- Tout = sum;
- calcOut(net);
- }
- public void calcOut(net net){
- Tout = 1/(1+ Math.exp(-(Tout-thold)/0.01));
- for(int i = 0; i < 2; i++)
- {
- if (net.layers.get(2).neurons.get(i).getout() >= 1){
- if(i == 0){
- System.out.print("T");
- }
- if(i == 1){
- System.out.print("U");
- }
- if(i == 2){
- System.out.print("N");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement