public NNPreTrainedHeuristic(MyNN nnSolve, IRepresentation representationSolve, double?confLevel, bool l2Loss) { this.nnSolve = nnSolve; this.representationSolve = representationSolve; this.confLevel = confLevel; this.l2Loss = l2Loss; }
public NNBayesHeuristic(IRepresentation representationSolve, IRepresentation representationUncert, int numHiddenSolve, int numOutputSolve, int?numHiddenUncert, float dropout, bool l2Loss) : base() { this.l2Loss = l2Loss; this.beta = 0.05F; float minBeta = 0.00001F; this.q = 0.95; this.representationSolve = representationSolve; this.representationUncert = representationUncert; nnSolve = new MyNN(new int[] { representationSolve.NumInputs, numHiddenSolve, numOutputSolve }, memoryBufferMaxRecords, l2Loss, dropout); nnUncert = null; if (numHiddenUncert != null) { nnUncert = new NNBayes(new int[] { representationUncert.NumInputs, (int)numHiddenUncert, 1 }); } this.confLevel = null; this.updateBeta = true; this.betaDiscountFactor = (float)Math.Pow(minBeta / beta, 1F / Global.NITER); this.reduceUncertFactor = 0.8; }
public static void TestAdmissibility(int run, string runType, int nnIndex, double?confLevel) { string nnFileName = string.Format(Global.NNFN, nnIndex); string outputFileName = string.Format(Global.TESTADMISFN, confLevel == null ? "" : confLevel.ToString()); string nnLoadPath = string.Format(Global.RUNPATH, run, runType, nnFileName); string csvWritePath = string.Format(Global.RUNPATH, run, runType, outputFileName); CSVWriter csvWriter = new CSVWriter(csvWritePath, ','); MyNN nnSolve = MyNN.Load(nnLoadPath); TestDomainData[] data = ReadTestDomainData(Global.TESTTASKPATH); IHeuristic heuristic = new NNPreTrainedHeuristic(nnSolve, representationSolve, confLevel, true); SolveTestData(heuristic, data, csvWriter, null); double sumExpanded = 0; double sumGenerated = 0; double sumOptimal = 0; double sumCost = 0; double sumSubOpt = 0; for (int i = 0; i < data.Length; i++) { TestDomainData testDomainData = data[i]; sumExpanded += testDomainData.SolvedExpanded; sumGenerated += testDomainData.SolvedGenerated; sumOptimal += testDomainData.OptimalCost; sumCost += testDomainData.SolvedCost; sumSubOpt += testDomainData.SolvedCost / (double)testDomainData.OptimalCost; } Console.WriteLine("-----"); Console.WriteLine(sumExpanded / data.Length); Console.WriteLine(sumGenerated / data.Length); Console.WriteLine(sumOptimal / data.Length); Console.WriteLine(sumCost / data.Length); Console.WriteLine((sumSubOpt / data.Length) - 1); csvWriter.Write(); }
public static void TestEfficiency(int run, string runType, int nnIndex, TestDomainData[][] testData) { string csvWritePath = string.Format(Global.RUNPATH, run, runType, Global.TESTEFFICFN); string csvSummWritePath = string.Format(Global.RUNPATH, run, runType, Global.TESTEFFICFNSUMM); CSVWriter csvWriter = new CSVWriter(csvWritePath, ','); CSVWriter csvSummWriter = new CSVWriter(csvSummWritePath, ','); int timeout = 60000; string nnFileName = string.Format(Global.NNFN, nnIndex); string nnLoadPath = string.Format(Global.RUNPATH, run, runType, nnFileName); MyNN nnSolve = MyNN.Load(nnLoadPath); for (int i = 0; i < testData.GetLength(0); i++) { csvWriter.Add(i.ToString()); csvWriter.EndLine(); csvWriter.Write(); csvWriter.Clear(); IHeuristic heuristic = new NNPreTrainedHeuristic(nnSolve, representationSolve, null, true); int numSolved = SolveTestData(heuristic, testData[i], csvWriter, timeout); csvSummWriter.Add(i.ToString()); csvSummWriter.Add(numSolved.ToString()); csvSummWriter.EndLine(); csvSummWriter.Write(); csvSummWriter.Clear(); } }