protected Solution iteration(LevinProblem problem, out bool done) { done = false; if (currentIteration > maxIterations) { done = true; return(null); } List <LevinProgram> currentLevinPrograms = new List <LevinProgram>(); if (currentIteration == 0) { // we have to seed the current levin programs for (uint instructionI = 0; instructionI < numberOfInstructions; instructionI++) { LevinProgram program = new LevinProgram(); program.instructions = new List <uint> { instructionI }; currentLevinPrograms.Add(program); } } else { // form new programs we haven't jet executed for (uint instructionI = 0; instructionI < numberOfInstructions; instructionI++) { currentLevinPrograms.AddRange(concatInstructionBeforePreviousLevinPrograms(instructionI)); } } // TODO< order programs by propability ? > // execute programs foreach (LevinProgram iterationProgram in currentLevinPrograms) { uint maxNumberOfStepsToExecute = (uint)((calcSolomonoffLevinMeasure(iterationProgram) * (double)phase) / c); bool hasHalted; executeProgram(iterationProgram, problem, maxNumberOfStepsToExecute, out hasHalted); if (hasHalted) { done = true; return(new Solution(iterationProgram)); } } previousLevinPrograms = currentLevinPrograms; phase *= 2; currentIteration++; return(null); }
public LevinProgram copy() { LevinProgram result = new LevinProgram(); foreach (uint iterationInstruction in instructions) { result.instructions.Add(iterationInstruction); } return(result); }
// [1] https://en.wikipedia.org/wiki/Algorithmic_probability // [2] http://wiki.opencog.org/w/OpenCogPrime:OccamsRazor // approximation for not computable "solomonoff levin measure" // see mainly [2] and secondary [1] protected double calcSolomonoffLevinMeasure(LevinProgram program) { double prod = 1.0; for (int instructionI = 0; instructionI < program.instructions.Count; instructionI++) { prod *= instructionPropabilityMatrix[instructionI, program.instructions[instructionI]]; } //sum += Math.Pow(2.0f, -(double)program.instructions.Count); return(prod); }
protected List <LevinProgram> concatInstructionBeforePreviousLevinPrograms(uint instruction) { List <LevinProgram> result = new List <LevinProgram>(); foreach (LevinProgram iterationPreviousLevinProgram in previousLevinPrograms) { LevinProgram modified = iterationPreviousLevinProgram.copy(); modified.instructions.Insert(0, instruction); result.Add(modified); } return(result); }
public override void executeProgram(LevinProgram program, uint maxNumberOfStepsToExecute, out bool hasHalted) { hasHalted = false; Console.WriteLine("program to execute is {0}", program.instructions); Console.WriteLine("number of steps to execute= {0}", maxNumberOfStepsToExecute); if (program.instructions.Count == 2 && program.instructions[0] == 1 && program.instructions[1] == 2) { Console.WriteLine("found solution"); hasHalted = true; } }
public override void executeProgram(LevinProgram program, uint maxNumberOfStepsToExecute, out bool hasHalted) { hasHalted = false; ExecutionContext executionContext = new ExecutionContext(); executionContext.reset(); bool executionFault = true; foreach (uint iterationInstruction in program.instructions) { switch (iterationInstruction) { case 0: executionContext.actionWriteAddAndIncrementIp(out executionFault); break; case 1: executionContext.actionWriteEnterBrace(out executionFault); break; case 2: executionContext.actionWriteExitBrace(out executionFault); break; case 3: executionContext.actionWriteNewBrace(out executionFault); break; case 4: executionContext.actionWriteOp1AndIncrementIp(out executionFault); break; case 5: executionContext.actionWriteOp2AndIncrementIp(out executionFault); break; case 6: executionContext.actionWriteRepeatAndIncrementIp(out executionFault); break; case 7: executionContext.actionIpGoBack(out executionFault); break; } if (executionFault) { return; } } // execute program // TODO TODO TODO // instead we just test for all valid combinations // TODO TODO TODO TODO TODO }
public abstract void executeProgram(LevinProgram program, uint maxNumberOfStepsToExecute, out bool hasHalted);
public Solution(LevinProgram program) { this.program = program; }
private void executeProgram(LevinProgram program, LevinProblem problem, uint maxNumberOfStepsToExecute, out bool hasHalted) { problem.executeProgram(program, maxNumberOfStepsToExecute, out hasHalted); }