// used for interactivly checking if the learning algorithm works correctly public static void interactiveCheckLearningAlgorithm() { SlimRnn rnn = new SlimRnn(); rnn.neurons.Add(SlimRnnNeuron.makeInputNeuron()); // [0] input rnn.neurons.Add(SlimRnnNeuron.makeInputNeuron()); // [1] input rnn.neurons.Add(SlimRnnNeuron.makeInputNeuron()); // [2] input rnn.neurons.Add(new SlimRnnNeuron(SlimRnnNeuron.EnumType.ADDITIVE)); // [3] termination/output rnn.neurons.Add(new SlimRnnNeuron(SlimRnnNeuron.EnumType.ADDITIVE)); // [4] output rnn.outputNeuronsStartIndex = 3; rnn.numberOfOutputNeurons = 2; rnn.terminatingNeuronIndex = 3; rnn.terminatingNeuronThreshold = 0.5f; rnn.numberOfInputNeurons = 3; rnn.t_lim = 5; // are actually less steps but fine for testing rnn.world = new TestWorld(); // insert unused neurons as possible neurons for learning rnn.neurons[0].outNeuronsWithWeights.Add(new SlimRnnNeuronWithWeight(rnn.neurons[0], rnn.neurons[3], 0.0f, 0, true)); rnn.neurons[0].outNeuronsWithWeights.Add(new SlimRnnNeuronWithWeight(rnn.neurons[0], rnn.neurons[4], 0.0f, 1, true)); rnn.neurons[1].outNeuronsWithWeights.Add(new SlimRnnNeuronWithWeight(rnn.neurons[1], rnn.neurons[3], 1.0f, 0)); rnn.neurons[1].outNeuronsWithWeights.Add(new SlimRnnNeuronWithWeight(rnn.neurons[1], rnn.neurons[4], 0.0f, 1, true)); rnn.neurons[2].outNeuronsWithWeights.Add(new SlimRnnNeuronWithWeight(rnn.neurons[2], rnn.neurons[3], 1.0f, 0)); rnn.initializeNeurons(); UniversalSlimRnnSearch learningAlgorithm = new UniversalSlimRnnSearch(rnn, new AlwaysSuccessfulTester()); learningAlgorithm.weightWithPropabilityTable = new List <UniversalSlimRnnSearch.WeightWithPropability> { /*new UniversalSlimRnnSearch.WeightWithPropability(-50.0f, 0.01), * new UniversalSlimRnnSearch.WeightWithPropability(-40.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-30.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-20.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-10.0f, 0.02), * * new UniversalSlimRnnSearch.WeightWithPropability(-9.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-8.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-7.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-6.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-5.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-4.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-3.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-2.0f, 0.02), * new UniversalSlimRnnSearch.WeightWithPropability(-1.5f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-1.0f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.99f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.98f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.95f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.92f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.9f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.85f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.8f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.75f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.7f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.65f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.6f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.55f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.5f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.45f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.4f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.35f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.3f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.25f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.2f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.15f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.1f, 0.03), * new UniversalSlimRnnSearch.WeightWithPropability(-0.05f, 0.01), * new UniversalSlimRnnSearch.WeightWithPropability(-0.02f, 0.01), * new UniversalSlimRnnSearch.WeightWithPropability(-0.01f, 0.01), * * // TODO< positive side > */ // just for testing new UniversalSlimRnnSearch.WeightWithPropability(1.0f, 0.4), new UniversalSlimRnnSearch.WeightWithPropability(-1.0f, 0.4), new UniversalSlimRnnSearch.WeightWithPropability(0.5f, 0.1), new UniversalSlimRnnSearch.WeightWithPropability(-0.5f, 0.1), }; // invoke learning algorithm bool wasSolved; SlimRnn solutionRnn; learningAlgorithm.search(1, true, out wasSolved, out solutionRnn); }
public void solverModificationAndCorrectnessDemonstration(ITaskAndSolverModification pParameter, ITask taskParameter, Solver previousS, IEnumerable <ITask> allExistingTasks, out Solver solver, out bool correctnessDemonstrationSuccess) { var p = (Environment2dTaskAndSolverModification)pParameter; var task = (Environment2dTask)taskParameter; correctnessDemonstrationSuccess = false; solver = null; UniversalSlimRnnSearch slimRnnSearch = new UniversalSlimRnnSearch(previousS.slimRnn, new Environment2dPowerplayNetworkTester(task, allExistingTasks)); slimRnnSearch.weightWithPropabilityTable = returnNormalizedPropabilitiesOfTable(); { // solver modification // hard coded modification // make a connection between the 1.0 input neuron and the neuron which causes a move to the right previousS.slimRnn.neurons[(int)neuronIndexConstantOne].outNeuronsWithWeights.Add( new SlimRnnNeuronWithWeight(previousS.slimRnn.neurons[(int)neuronIndexConstantOne], previousS.slimRnn.neurons[(int)previousS.slimRnn.outputNeuronsStartIndex], 0.0f, 0, true)); // TODO< not hardcoded modification > } // let the SLIM-RNN search-algorithm search for a network which solves the task the fastest way uint maximumIteration = 3; bool mustHalt = true; bool wasSolved; SlimRnn solutionRnn; // we have to set the world because UniversalSlimRnnSearch.search() uses the world ///slimRnnSearch.world = new TaskSlimRnnWorld(task); // the search is doing "solver modification" _and_ "correctness demonstration" slimRnnSearch.search(maximumIteration, mustHalt, out wasSolved, out solutionRnn); // rollback changes // if it was solved then keep used eligable weights if (wasSolved) { int breakpointHere = 1; // we have to rollback/remove eligable weights which didn't get used foreach (SlimRnnNeuron iNeuron in previousS.slimRnn.neurons) { iNeuron.outNeuronsWithWeights = new List <SlimRnnNeuronWithWeight>( iNeuron.outNeuronsWithWeights.Where(v => !v.isEligable || (v.isEligable && (v.weight != 0.0f))) ); } // set all used eligable connections to normal connections foreach (SlimRnnNeuron iNeuron in previousS.slimRnn.neurons) { foreach (var iConnection in iNeuron.outNeuronsWithWeights) { Debug.Assert(!iConnection.isEligable || (iConnection.isEligable && iConnection.weight != 0.0f)); iConnection.isEligable = false; } } } else { // we have to rollback/remove all eligable weights foreach (SlimRnnNeuron iNeuron in previousS.slimRnn.neurons) { iNeuron.outNeuronsWithWeights = new List <SlimRnnNeuronWithWeight>(iNeuron.outNeuronsWithWeights.Where(v => !v.isEligable)); } } // if we solved the task with the SLIM-RNN then we have to create a solver which represents our new problem solver // Solver has of course the SLIM-RNN which solved the problem if (wasSolved) { solver = new Solver(); solver.slimRnn = solutionRnn; } if (!wasSolved) { // if it was not solved we can't demonstrate the correctness correctnessDemonstrationSuccess = false; return; } correctnessDemonstrationSuccess = true; }