Skip to content

Learning

TakMashido edited this page Sep 8, 2017 · 3 revisions

Class for network learning is LNetwork.

Creating network

First you need to create this object. There are three option:

  1. Manually set up weights

  2. Read previus network from disc

  3. Use special constructor

  4. I described in Symulation page The only change is using new LNetwork() constructor and next invocing setWeights(float[][][] weights) method. Remember to set up function with setFunction(Function function) method.

  5. Also described in Symulation page but instead of FileS.readNetwork(String fileName) use FileL.readNetwork(String fileName)

  6. There is constructor creating "blank"(with random weights) network with given layers size, input numer and function: public LNetwork(int inputsNumber,int[] layersSize, Function function)

Sample code:

I skiped class and method declaration lines

1.

String fileName="yourNetwork"; LNetwork network=FileL.readNetwork(fileName); //Load your network from disc

2.

int inputNumber=2; float[][][] weights=new float[1][2][2]; float[0][0][0]=1; float[0][0][1]=2; float[0][1][0]=3; float[0][1][1]=4;

Function fuction=new Linear(); LNetwork network=new LNetwork();

network.setWeights(weights); network.setFunction(function);

3.

int inputNumber=2; int[] layersSize=new int[]{2}; Function function=new Linear(); LNetwork network=new LNetwork(inputNumber, layersSize, function);

Teaching network

To teach our LNetwork we need a teacher (Teacher class), and learning sequence(Array of LearningSequence object)

First we'll create teacher. We have Teacher(float N,float M,long cyclesNumber) constructor; N is param determining speed of learn, should be less then 1 M is momentum, should be less then 1 cyclesNumber is simply how much cycles numer teacher make

When we have teacher we must have data we want to teach our student-network. Data are storen in LearningSequence[] array. LearningSequece constains float[] input and float[] output. output constains the data we want have in output of network for specyfic input. we can use new LearningSequence(float[] input,float[] output); or ls.setInput(float[] input), ls.setOutput(float[] output);

We can also use FilesL.readLS(String fileName) to read full(not one LearningSequece object, but array of them) from disc

When we have our LearningSeqence array and teacher we call methods: network.setLS(LearningSequence ourLS); teacher.setNetwork(network);

after all we only need to invoke teach(); on our teacher and wait until it finished

If your resouls are NaN in network output decrease N and/or M.

Clone this wiki locally