PageRenderTime 175ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/matbat/dep/banjo.2.2.0/src/edu/duke/cs/banjo/learner/SearcherSkip.java

https://code.google.com/p/matbat/
Java | 155 lines | 55 code | 33 blank | 67 comment | 3 complexity | 942ca9c6b1ae6661f8f8ed092a4a381b MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause
  1. /*
  2. * Created on Feb 27, 2006
  3. *
  4. * This file is part of Banjo (Bayesian Network Inference with Java Objects)
  5. * edu.duke.cs.banjo
  6. * Banjo is licensed from Duke University.
  7. * Copyright (c) 2005-2008 by Alexander J. Hartemink.
  8. * All rights reserved.
  9. *
  10. * License Info:
  11. *
  12. * For non-commercial use, may be licensed under a Non-Commercial Use License.
  13. * For commercial use, please contact Alexander J. Hartemink or the Office of
  14. * Science and Technology at Duke University. More information available at
  15. * http://www.cs.duke.edu/~amink/software/banjo
  16. *
  17. */
  18. package edu.duke.cs.banjo.learner;
  19. import java.util.TreeSet;
  20. import edu.duke.cs.banjo.bayesnet.BayesNetManager;
  21. import edu.duke.cs.banjo.bayesnet.BayesNetStructure;
  22. import edu.duke.cs.banjo.data.settings.Settings;
  23. import edu.duke.cs.banjo.learner.components.EvaluatorBDe;
  24. import edu.duke.cs.banjo.utility.BANJO;
  25. /**
  26. * This searcher is only setting up as much of the bayesnet structures as is
  27. * necessary to prepare for the post-processing, without actually having to go
  28. * through a search. Consequently, we suppress the display of the various
  29. * search parameters in the output.
  30. *
  31. * <p><strong>Details:</strong> <br>
  32. *
  33. * <p><strong>Change History:</strong> <br>
  34. * Created on Feb 27, 2006
  35. *
  36. * 8/6/2008 hjs Add evaluator to have network score computed.
  37. *
  38. * @author Jurgen Sladeczek (hjs) <br>
  39. * For the latest info, please visit www.cs.duke.edu.
  40. */
  41. public class SearcherSkip extends Searcher {
  42. public SearcherSkip( Settings _processData ) throws Exception {
  43. super( _processData );
  44. // Validate the required settings
  45. boolean isDataValid = validateRequiredData();
  46. // If crucial settings could ne be validated, we can't execute the remaining
  47. // code in this constructor
  48. if ( !isDataValid ) return;
  49. // Set up the required (subordinate) objects
  50. setupSearch();
  51. }
  52. // Compiles various pieces of info about the search, to be used by the recorder
  53. protected void setupSearch() throws Exception {
  54. // Set up the bayesnet infrastructure (in particular, the user likely has an
  55. // initial structure to be examined by the post-processor)
  56. this.bayesNetManager = new BayesNetManager( processData );
  57. // Set up the standard container for our network structure:
  58. highScoreStructureSinceRestart = new BayesNetStructure(
  59. bayesNetManager.getCurrentParents(),
  60. currentBestScoreSinceRestart, 0 );
  61. highScoreStructureSet = new TreeSet();
  62. highScoreStructureSet.add( new BayesNetStructure(
  63. highScoreStructureSinceRestart,
  64. currentBestScoreSinceRestart,
  65. networksVisitedGlobalCounter ) );
  66. // (v2.2) hjs
  67. // Add an evaluator, so we actually compute the network score of the initial network
  68. if ( processData.getValidatedProcessParameter(
  69. BANJO.SETTING_EVALUATORCHOICE )
  70. .equalsIgnoreCase( BANJO.UI_EVAL_BDE )) {
  71. this.evaluator = new EvaluatorBDe(bayesNetManager, processData);
  72. }
  73. else {
  74. this.evaluator = new EvaluatorBDe(bayesNetManager, processData);
  75. }
  76. // Compute the initial score for the network
  77. currentBestScoreSinceRestart = evaluator.computeInitialNetworkScore(
  78. bayesNetManager );
  79. // Set the initial network as the current best score, and add to the high score networks
  80. // highScoreStructureSinceRestart = new BayesNetStructure(
  81. // bayesNetManager.getCurrentParents(),
  82. // currentBestScoreSinceRestart, 0 );
  83. highScoreStructureSet = new TreeSet();
  84. highScoreStructureSet.add( new BayesNetStructure(
  85. bayesNetManager.getCurrentParents(),
  86. currentBestScoreSinceRestart, 0 ) );
  87. // highScoreStructureSinceRestart,
  88. // currentBestScoreSinceRestart,
  89. // networksVisitedGlobalCounter ) );
  90. // Finally, store the network and score given by the initial structure
  91. // for the post-processing
  92. processData.setHighScoreStructureSet( highScoreStructureSet );
  93. // Set the string buffer
  94. searcherStats = new StringBuffer( BANJO.BUFFERLENGTH_STAT_INTERNAL );
  95. // Is there something we want to pass along at this point?
  96. // Well, here we pass "it" along (nothing for now)
  97. processData.setDynamicProcessParameter( BANJO.DATA_SEARCHERINFO_SPECIFICSEARCHER,
  98. searcherStats.toString() );
  99. processData.setDynamicProcessParameter( BANJO.DATA_SEARCHERINFO_COREOBJECTS,
  100. searcherStats.toString() );
  101. }
  102. /* (non-Javadoc)
  103. * @see edu.duke.cs.banjo.learner.SearcherI#executeSearch()
  104. */
  105. public void executeSearch() throws Exception {
  106. // There's not much to do in this searcher:
  107. // Record the initial data
  108. searcherStatistics.recordInitialData(this);
  109. }
  110. /* (non-Javadoc)
  111. * @see edu.duke.cs.banjo.learner.SearcherI#updateProcessData(
  112. * edu.duke.cs.banjo.data.settings.Settings )
  113. */
  114. public void updateProcessData( Settings _processData ) throws Exception {
  115. // nothing to do
  116. }
  117. private boolean validateRequiredData() throws Exception {
  118. // There is nothing to validate:
  119. boolean isDataValid = true;
  120. return isDataValid;
  121. }
  122. }