RLPark 1.0.0
Reinforcement Learning Framework in Java

RandomNetworks.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.algorithms.representations.ltu.networks;
00002 
00003 import java.util.Random;
00004 
00005 import rlpark.plugin.rltoys.algorithms.representations.ltu.units.LTU;
00006 
00007 public class RandomNetworks {
00008   public static void fullyConnect(Random random, RandomNetwork randomNetwork, LTU prototype) {
00009     int outputSize = randomNetwork.outputSize;
00010     int inputSize = randomNetwork.inputSize;
00011     for (int i = 0; i < outputSize; i++) {
00012       byte[] weights = new byte[inputSize];
00013       int[] inputs = new int[inputSize];
00014       for (int j = 0; j < inputSize; j++) {
00015         inputs[j] = j;
00016         weights[j] = (byte) (random.nextBoolean() ? +1 : -1);
00017       }
00018       randomNetwork.addLTU(prototype.newLTU(i, inputs, weights));
00019     }
00020   }
00021 
00022   public static void connect(Random random, RandomNetwork randomNetwork, LTU prototype, int nbUnitInputs, int startPos,
00023       int endPos) {
00024     int inputSize = randomNetwork.inputSize;
00025     for (int i = startPos; i < endPos; i++)
00026       randomNetwork.addLTU(newRandomUnit(random, prototype, i, inputSize, nbUnitInputs));
00027   }
00028 
00029   public static LTU newRandomUnit(Random random, LTU prototype, int unitIndex, int inputSize, int nbUnitInputs) {
00030     byte[] weights = new byte[nbUnitInputs];
00031     int[] inputs = new int[nbUnitInputs];
00032     boolean[] choosen = new boolean[inputSize];
00033     for (int j = 0; j < nbUnitInputs; j++) {
00034       int inputIndex = chooseInput(random, choosen);
00035       assert !choosen[inputIndex];
00036       inputs[j] = inputIndex;
00037       choosen[inputIndex] = true;
00038       weights[j] = (byte) (random.nextBoolean() ? +1 : -1);
00039     }
00040     LTU ltu = prototype.newLTU(unitIndex, inputs, weights);
00041     return ltu;
00042   }
00043 
00044   private static int chooseInput(Random random, boolean[] choosen) {
00045     int result = random.nextInt(choosen.length);
00046     while (choosen[result])
00047       result = random.nextInt(choosen.length);
00048     return result;
00049   }
00050 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark