Changeset 9392
- Timestamp:
- 04/23/13 13:31:29 (12 years ago)
- Location:
- branches/LearningClassifierSystems
- Files:
-
- 11 added
- 3 deleted
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Algorithms.GAssist/3.3
- Property svn:ignore
-
old new 1 1 *.user 2 2 Plugin.cs 3 obj
-
- Property svn:ignore
-
branches/LearningClassifierSystems/HeuristicLab.Algorithms.GAssist/3.3/GAssist.cs
r9352 r9392 65 65 get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; } 66 66 } 67 public ValueParameter<MDLIterationOperator> MDLIterationOperatorParameter { 68 get { return (ValueParameter<MDLIterationOperator>)Parameters["MDLIterationOperator"]; } 69 } 67 70 public IConstrainedValueParameter<IDefaultRuleOperator> DefaultRuleParameter { 68 71 get { return (IConstrainedValueParameter<IDefaultRuleOperator>)Parameters["DefaultRule"]; } … … 121 124 private ValueParameter<ItemCollection<IDiscretizer>> DiscretizersParameter { 122 125 get { return (ValueParameter<ItemCollection<IDiscretizer>>)Parameters["Discretizers"]; } 126 } 127 public ValueParameter<IntValue> MDLActivationIterationParameter { 128 get { return (ValueParameter<IntValue>)Parameters["MDLActivationIteration"]; } 129 } 130 public ValueParameter<DoubleValue> InitialTheoryLengthRatioParameter { 131 get { return (ValueParameter<DoubleValue>)Parameters["InitialTheoryLengthRatio"]; } 132 } 133 public ValueParameter<DoubleValue> WeightRelaxFactorParameter { 134 get { return (ValueParameter<DoubleValue>)Parameters["WeightRelaxFactor"]; } 135 } 136 public ValueParameter<IntValue> WeightAdaptionIterationsParameter { 137 get { return (ValueParameter<IntValue>)Parameters["WeightAdaptionIterations"]; } 138 } 139 public ValueParameter<IntValue> NumberOfStrataParameter { 140 get { return (ValueParameter<IntValue>)Parameters["NumberOfStrata"]; } 123 141 } 124 142 #endregion … … 180 198 get { return (RandomCreator)OperatorGraph.InitialOperator; } 181 199 } 200 private VariableCreator VariableCreator { 201 get { return (VariableCreator)RandomCreator.Successor; } 202 } 203 private Placeholder MDLIterationPlaceholder { 204 get { return (Placeholder)VariableCreator.Successor; } 205 } 206 private ILASOperator ILASOperator { 207 get { return (ILASOperator)MDLIterationPlaceholder.Successor; } 208 } 209 private InitializeDiscretizersOperator InitializeDiscretizers { 210 get { return (InitializeDiscretizersOperator)ILASOperator.Successor; } 211 } 182 212 private SolutionsCreator SolutionsCreator { 183 get { return (SolutionsCreator) RandomCreator.Successor; }213 get { return (SolutionsCreator)InitializeDiscretizers.Successor; } 184 214 } 185 215 private GAssistMainLoop GeneticAlgorithmMainLoop { … … 204 234 Parameters.Add(new ValueParameter<GAssistSpecialStageMultiOperator>("SpecialStages", "", new GAssistSpecialStageMultiOperator())); 205 235 Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000))); 206 Parameters.Add(new FixedValueParameter<PercentValue>("SplitProbability", "", new PercentValue(0.05))); 207 Parameters.Add(new FixedValueParameter<PercentValue>("MergeProbability", "", new PercentValue(0.05))); 208 Parameters.Add(new FixedValueParameter<PercentValue>("StartReinitializeProbability", "", new PercentValue(0.05))); 209 Parameters.Add(new FixedValueParameter<PercentValue>("EndReinitializeProbability", "", new PercentValue(Double.Epsilon))); 210 Parameters.Add(new FixedValueParameter<PercentValue>("OneProbability", "", new PercentValue(0.75))); 211 Parameters.Add(new FixedValueParameter<IntValue>("MaximumNumberOfIntervals", "", new IntValue(5))); 212 Parameters.Add(new FixedValueParameter<IntValue>("InitialNumberOfRules", "", new IntValue(20))); 236 Parameters.Add(new ValueParameter<PercentValue>("SplitProbability", "", new PercentValue(0.05))); 237 Parameters.Add(new ValueParameter<PercentValue>("MergeProbability", "", new PercentValue(0.05))); 238 Parameters.Add(new ValueParameter<PercentValue>("StartReinitializeProbability", "", new PercentValue(0.05))); 239 Parameters.Add(new ValueParameter<PercentValue>("EndReinitializeProbability", "", new PercentValue(Double.Epsilon))); 240 Parameters.Add(new ValueParameter<PercentValue>("OneProbability", "", new PercentValue(0.75))); 241 Parameters.Add(new ValueParameter<IntValue>("MaximumNumberOfIntervals", "", new IntValue(5))); 242 Parameters.Add(new ValueParameter<IntValue>("InitialNumberOfRules", "", new IntValue(20))); 243 Parameters.Add(new ValueParameter<MDLIterationOperator>("MDLIterationOperator", "", new MDLIterationOperator())); 213 244 Parameters.Add(new ConstrainedValueParameter<IDefaultRuleOperator>("DefaultRule", "")); 214 245 Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("ReinitializeCurveOperator", "")); 215 246 Parameters.Add(new ValueParameter<ItemCollection<IDiscretizer>>("Discretizers", "", new ItemCollection<IDiscretizer>())); 216 247 248 Parameters.Add(new ValueParameter<IntValue>("MDLActivationIteration", "", new IntValue(25))); 249 Parameters.Add(new ValueParameter<DoubleValue>("InitialTheoryLengthRatio", "", new DoubleValue(0.075))); 250 Parameters.Add(new ValueParameter<DoubleValue>("WeightRelaxFactor", "", new DoubleValue(0.9))); 251 Parameters.Add(new ValueParameter<IntValue>("WeightAdaptionIterations", "", new IntValue(10))); 252 253 Parameters.Add(new ValueParameter<IntValue>("NumberOfStrata", "", new IntValue(2))); 254 217 255 RandomCreator randomCreator = new RandomCreator(); 256 VariableCreator variableCreator = new VariableCreator(); 257 Placeholder mdlIterationPlaceholder = new Placeholder(); 258 ILASOperator ilasOperator = new ILASOperator(); 259 InitializeDiscretizersOperator initializeDiscretizers = new InitializeDiscretizersOperator(); 218 260 SolutionsCreator solutionsCreator = new SolutionsCreator(); 219 261 SubScopesCounter subScopesCounter = new SubScopesCounter(); … … 227 269 randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name; 228 270 randomCreator.SetSeedRandomlyParameter.Value = null; 229 randomCreator.Successor = solutionsCreator; 271 randomCreator.Successor = variableCreator; 272 273 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class GAssistMainLoop expects this to be called Generations 274 variableCreator.Successor = mdlIterationPlaceholder; 275 276 mdlIterationPlaceholder.Name = "MDL Iteration Operator"; 277 mdlIterationPlaceholder.OperatorParameter.ActualName = MDLIterationOperatorParameter.Name; 278 mdlIterationPlaceholder.Successor = ilasOperator; 279 280 ilasOperator.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName; 281 ilasOperator.NumberOfStrataParameter.ActualName = NumberOfStrataParameter.Name; 282 ilasOperator.Successor = initializeDiscretizers; 283 284 initializeDiscretizers.DiscretizersParameter.ActualName = DiscretizersParameter.Name; 285 initializeDiscretizers.Successor = solutionsCreator; 230 286 231 287 solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; … … 240 296 resultsCollector.Successor = mainLoop; 241 297 298 mainLoop.MDLIterationParameter.ActualName = MDLIterationOperatorParameter.Name; 242 299 mainLoop.DefaultRuleParameter.ActualName = DefaultRuleParameter.Name; 243 300 mainLoop.SelectorParameter.ActualName = SelectorParameter.Name; … … 348 405 ParameterizeStochasticOperator(Problem.SolutionCreator); 349 406 ParameterizeStochasticOperator(Problem.Evaluator); 350 foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op); 407 ParameterizeMDLOperator(Problem.Evaluator); 408 ParameterizeIterationBasedOperators(Problem.Evaluator); 409 foreach (IOperator op in Problem.Operators.OfType<IOperator>()) { 410 ParameterizeStochasticOperator(op); 411 } 351 412 ParameterizeSolutionsCreator(); 352 413 ParameterizeGeneticAlgorithmMainLoop(); 414 ParameterizeMDL(); 353 415 ParameterizeSelectors(); 354 416 ParameterizeAnalyzers(); … … 359 421 UpdateAnalyzers(); 360 422 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 423 ILASOperator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; 424 InitializeDiscretizers.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; 361 425 base.OnProblemChanged(); 426 } 427 428 private void ParameterizeMDL() { 429 MDLIterationOperatorParameter.Value.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 430 //change 431 MDLIterationOperatorParameter.Value.IndividualParameter.ActualName = "DecisionList"; 432 MDLIterationOperatorParameter.Value.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; 433 MDLIterationOperatorParameter.Value.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 434 435 MDLIterationOperatorParameter.Value.InitialTheoryLengthRatioParameter.ActualName = InitialTheoryLengthRatioParameter.Name; 436 MDLIterationOperatorParameter.Value.MDLActivationIterationParameter.ActualName = MDLActivationIterationParameter.Name; 437 MDLIterationOperatorParameter.Value.WeightAdaptionIterationsParameter.ActualName = WeightAdaptionIterationsParameter.Name; 438 MDLIterationOperatorParameter.Value.WeightRelaxFactorParameter.ActualName = WeightRelaxFactorParameter.Name; 439 MDLIterationOperatorParameter.Value.IterationsParameter.ActualName = "Generations"; 362 440 } 363 441 … … 374 452 ParameterizeAnalyzers(); 375 453 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 454 Problem.Evaluator.StrataParameter.ActualName = ILASOperator.StrataParameter.ActualName; 376 455 base.Problem_EvaluatorChanged(sender, e); 377 456 } … … 433 512 stochasticOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 434 513 stochasticOp.RandomParameter.Hidden = true; 514 } 515 } 516 private void ParameterizeMDLOperator(IOperator op) { 517 IMDLCalculatorBasedOperator stochasticOp = op as IMDLCalculatorBasedOperator; 518 if (stochasticOp != null) { 519 stochasticOp.MDLCalculatorParameter.ActualName = MDLIterationOperatorParameter.Value.MDLCalculatorParameter.ActualName; 435 520 } 436 521 } … … 469 554 } 470 555 } 556 private void ParameterizeIterationBasedOperators(IOperator op) { 557 IIterationBasedOperator iterationOp = op as IIterationBasedOperator; 558 if (iterationOp != null) { 559 ParameterizeIterationBasedOperators(iterationOp); 560 } 561 } 562 private void ParameterizeIterationBasedOperators(IIterationBasedOperator op) { 563 op.IterationsParameter.ActualName = "Generations"; 564 op.IterationsParameter.Hidden = true; 565 op.MaximumIterationsParameter.ActualName = "MaximumGenerations"; 566 op.MaximumIterationsParameter.Hidden = true; 567 } 471 568 private void ParameterizeIterationBasedOperators() { 472 569 if (Problem != null) { 473 570 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 474 op.IterationsParameter.ActualName = "Generations"; 475 op.IterationsParameter.Hidden = true; 476 op.MaximumIterationsParameter.ActualName = "MaximumGenerations"; 477 op.MaximumIterationsParameter.Hidden = true; 571 ParameterizeIterationBasedOperators(op); 478 572 } 479 573 } -
branches/LearningClassifierSystems/HeuristicLab.Algorithms.GAssist/3.3/GAssistMainLoop.cs
r9352 r9392 61 61 public ValueLookupParameter<IOperator> MutatorParameter { 62 62 get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; } 63 } 64 public ValueLookupParameter<IOperator> MDLIterationParameter { 65 get { return (ValueLookupParameter<IOperator>)Parameters["MDLIteration"]; } 63 66 } 64 67 public ValueLookupParameter<IOperator> DefaultRuleParameter { … … 134 137 Parameters.Add(new ValueLookupParameter<IOperator>("ReinitializationProbabilityOperator", "")); 135 138 Parameters.Add(new ValueLookupParameter<IOperator>("DefaultRule", "")); 139 Parameters.Add(new ValueLookupParameter<IOperator>("MDLIteration", "")); 136 140 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied.")); 137 141 #endregion 138 142 139 143 #region Create operators 140 VariableCreator variableCreator = new VariableCreator();141 144 ResultsCollector resultsCollector1 = new ResultsCollector(); 142 145 Placeholder analyzer1 = new Placeholder(); 146 Placeholder mdlIterationOperator = new Placeholder(); 147 Placeholder defaultRuleOperator = new Placeholder(); 143 148 Placeholder reinitializationProbabilityOperator = new Placeholder(); 144 Placeholder defaultRuleOperator = new Placeholder();145 149 Placeholder selector = new Placeholder(); 146 150 SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor(); … … 167 171 ConditionalBranch conditionalBranch = new ConditionalBranch(); 168 172 169 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class GeneticAlgorithm expects this to be called Generations170 171 173 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); 172 174 resultsCollector1.ResultsParameter.ActualName = "Results"; … … 174 176 analyzer1.Name = "Analyzer"; 175 177 analyzer1.OperatorParameter.ActualName = "Analyzer"; 178 179 mdlIterationOperator.Name = "MDL Iteration Operator"; 180 mdlIterationOperator.OperatorParameter.ActualName = MDLIterationParameter.Name; 176 181 177 182 defaultRuleOperator.Name = "Default Rule Operator"; … … 234 239 235 240 #region Create operator graph 236 OperatorGraph.InitialOperator = variableCreator; 237 variableCreator.Successor = resultsCollector1; 241 OperatorGraph.InitialOperator = resultsCollector1; 238 242 resultsCollector1.Successor = analyzer1; 239 analyzer1.Successor = defaultRuleOperator; 243 analyzer1.Successor = mdlIterationOperator; 244 mdlIterationOperator.Successor = defaultRuleOperator; 240 245 defaultRuleOperator.Successor = reinitializationProbabilityOperator; 241 246 reinitializationProbabilityOperator.Successor = selector; … … 272 277 comparator.Successor = analyzer2; 273 278 analyzer2.Successor = conditionalBranch; 274 conditionalBranch.FalseBranch = defaultRuleOperator;279 conditionalBranch.FalseBranch = mdlIterationOperator; 275 280 conditionalBranch.TrueBranch = null; 276 281 conditionalBranch.Successor = null; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3
- Property svn:ignore
-
old new 1 1 *.user 2 2 Plugin.cs 3 obj
-
- Property svn:ignore
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionList.cs
r9352 r9392 80 80 81 81 // for convenience 82 public IEnumerable<IAction> Evaluate(IEnumerable< DecisionListInput> input) {83 int numberOfAliveRules;84 return Evaluate(input, out numberOfAliveRules);82 public IEnumerable<IAction> Evaluate(IEnumerable<IGAssistInput> input) { 83 ItemSet<Rule> aliveRules; 84 return Evaluate(input, out aliveRules); 85 85 } 86 86 // for convenience 87 public IEnumerable<IAction> Evaluate(IEnumerable< DecisionListInput> input, out int numberOfAliveRules) {87 public IEnumerable<IAction> Evaluate(IEnumerable<IGAssistInput> input, out ItemSet<Rule> aliveRules) { 88 88 double theoryLengtgh; 89 return Evaluate(input, out numberOfAliveRules, out theoryLengtgh);89 return Evaluate(input, out aliveRules, out theoryLengtgh); 90 90 } 91 public IEnumerable<IAction> Evaluate(IEnumerable< DecisionListInput> input, out int numberOfAliveRules, out double theoryLengtgh) {91 public IEnumerable<IAction> Evaluate(IEnumerable<IGAssistInput> input, out ItemSet<Rule> aliveRules, out double theoryLength) { 92 92 var estimated = new List<IAction>(); 93 var activatedRules = new HashSet<Rule>(); 93 var activatedRules = new ItemSet<Rule>(); 94 int count = 0; 94 95 foreach (var dli in input) { 96 count++; 95 97 foreach (var rule in rules) { 96 98 if (rule.MatchInput(dli)) { … … 100 102 } 101 103 } 104 if (count > estimated.Count) { 105 estimated.Add(defaultAction); 106 } 102 107 } 103 numberOfAliveRules = activatedRules.Count;104 theoryLengt gh = activatedRules.Sum(x => x.ComputeTheoryLength());108 aliveRules = activatedRules; 109 theoryLength = activatedRules.Sum(x => x.ComputeTheoryLength()); 105 110 106 111 return estimated; 112 } 113 114 public void RemoveRules(IEnumerable<Rule> deadRules) { 115 foreach (var deadRule in deadRules) { 116 Rules.Remove(deadRule); 117 } 107 118 } 108 119 … … 145 156 } 146 157 } 158 159 public IGAssistSolution CreateGAssistSolution(IGAssistNichesProblemData problemData) { 160 return new DecisionListSolution(this, problemData); 161 } 147 162 #endregion 148 163 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionListInput.cs
r9334 r9392 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Optimization.Operators.LCS; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 … … 31 32 [StorableClass] 32 33 [Item("DecisionListInput", "")] 33 public class DecisionListInput : Item {34 public class DecisionListInput : Item, IGAssistInput { 34 35 35 36 [Storable] … … 81 82 return sb.ToString(); 82 83 } 84 85 #region IGAssistInput Members 86 public IEnumerable<string> VariableNames { 87 get { return inputDictionary.Keys; } 88 } 89 public string GetVariableValue(string variableName) { 90 return inputDictionary[variableName]; 91 } 92 #endregion 83 93 } 84 94 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionListSolution.cs
r9334 r9392 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Optimization; 29 using HeuristicLab.Optimization.Operators.LCS; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 31 … … 38 39 private const string TestAccuracyResultName = "Accuracy (test)"; 39 40 private const string TrainingNumberOfAliveRulesName = "Number of alive rules (training)"; 41 private const string TrainingAliveRulesName = "Alive Rules (training)"; 40 42 //private const string TestNumberOfAliveRules = "Number of alive rules (test)"; 41 43 private const string TrainingTheoryLengthName = "Theory Length (training)"; … … 54 56 private set { ((IntValue)this[TrainingNumberOfAliveRulesName].Value).Value = value; } 55 57 } 58 public ItemSet<Rule> TrainingAliveRules { 59 get { return (ItemSet<Rule>)this[TrainingAliveRulesName].Value; } 60 private set { this[TrainingAliveRulesName].Value = value; } 61 } 56 62 public double TrainingTheoryLength { 57 63 get { return ((DoubleValue)this[TrainingTheoryLengthName].Value).Value; } … … 61 67 get { return ((DoubleValue)this[TrainingExceptionsLengthName].Value).Value; } 62 68 private set { ((DoubleValue)this[TrainingExceptionsLengthName].Value).Value = value; } 69 } 70 71 public int Classes { 72 get { return ProblemData.Classes; } 63 73 } 64 74 … … 79 89 } 80 90 81 public I DecisionListClassificationProblemData ProblemData {82 get { return (I DecisionListClassificationProblemData)this[ProblemDataResultName].Value; }91 public IGAssistNichesProblemData ProblemData { 92 get { return (IGAssistNichesProblemData)this[ProblemDataResultName].Value; } 83 93 set { 84 94 if (this[ProblemDataResultName].Value != value) { … … 100 110 description = original.Description; 101 111 } 102 public DecisionListSolution(DecisionList model, I DecisionListClassificationProblemData problemData)112 public DecisionListSolution(DecisionList model, IGAssistNichesProblemData problemData) 103 113 : base() { 104 114 name = ItemName; … … 109 119 Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue())); 110 120 Add(new Result(TrainingNumberOfAliveRulesName, "", new IntValue())); 121 Add(new Result(TrainingAliveRulesName, "", new ItemSet<Rule>())); 111 122 Add(new Result(TrainingTheoryLengthName, "", new DoubleValue())); 112 123 Add(new Result(TrainingExceptionsLengthName, "", new DoubleValue())); … … 123 134 var originalTrainingCondition = ProblemData.FetchInput(ProblemData.TrainingIndices); 124 135 var originalTestCondition = ProblemData.FetchInput(ProblemData.TestIndices); 125 int numberOfAliveRules;136 ItemSet<Rule> aliveRules; 126 137 double theoryLength; 127 var estimatedTraining = Model.Evaluate(originalTrainingCondition, out numberOfAliveRules, out theoryLength); 128 TrainingNumberOfAliveRules = numberOfAliveRules; 138 var estimatedTraining = Model.Evaluate(originalTrainingCondition, out aliveRules, out theoryLength); 139 TrainingNumberOfAliveRules = aliveRules.Count; 140 TrainingAliveRules = aliveRules; 129 141 TrainingTheoryLength = theoryLength; 130 142 var estimatedTest = Model.Evaluate(originalTestCondition); … … 139 151 } 140 152 141 p rivate double CalculateAccuracy(IEnumerable<IAction> original, IEnumerable<IAction> estimated) {153 public static double CalculateAccuracy(IEnumerable<IGAssistNiche> original, IEnumerable<IGAssistNiche> estimated) { 142 154 double correctClassified = 0; 143 155 … … 147 159 148 160 while (originalEnumerator.MoveNext() && estimatedActionEnumerator.MoveNext()) { 149 if (originalEnumerator.Current.Match(estimatedActionEnumerator.Current)) { 161 if (originalEnumerator.Current != null && estimatedActionEnumerator.Current != null 162 && originalEnumerator.Current.SameNiche(estimatedActionEnumerator.Current)) { 150 163 correctClassified++; 151 164 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Evaluator/MDLEvaluator.cs
r9334 r9392 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; 24 26 using HeuristicLab.Data; 27 using HeuristicLab.Operators; 28 using HeuristicLab.Optimization; 29 using HeuristicLab.Optimization.Operators.LCS; 25 30 using HeuristicLab.Parameters; 26 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 29 34 [Item("MDLEvaluator", "Description missing")] 30 35 [StorableClass] 31 public class MDLEvaluator : DecisionListEvaluator {36 public class MDLEvaluator : SingleSuccessorOperator, IDecisionListEvaluator, IDecisionListOperator, IMDLCalculatorBasedOperator, IIterationBasedOperator, IStochasticOperator { 32 37 33 public IValueLookupParameter<MDLCalculator> MDLCalculatorParameter { 34 get { return (IValueLookupParameter<MDLCalculator>)Parameters["MDLCalculator"]; } 38 #region Parameter Properties 39 public ILookupParameter<IRandom> RandomParameter { 40 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 41 } 42 public ILookupParameter<DecisionList> DecisionListParameter { 43 get { return (ILookupParameter<DecisionList>)Parameters["DecisionList"]; } 44 } 45 public IValueLookupParameter<IntValue> SizePenaltyMinRulesParameter { 46 get { return (IValueLookupParameter<IntValue>)Parameters["SizePenaltyMinRules"]; } 47 } 48 public ILookupParameter<DoubleValue> QualityParameter { 49 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 50 } 51 public IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter { 52 get { return (IValueLookupParameter<IDecisionListClassificationProblemData>)Parameters["ProblemData"]; } 53 } 54 55 public ILookupParameter<MDLCalculator> MDLCalculatorParameter { 56 get { return (ILookupParameter<MDLCalculator>)Parameters["MDLCalculator"]; } 57 } 58 public ILookupParameter<IntValue> IterationsParameter { 59 get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; } 60 } 61 public IValueLookupParameter<IntValue> MaximumIterationsParameter { 62 get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; } 63 } 64 65 public IValueLookupParameter<IntValue> IterationRuleDeletionParameter { 66 get { return (IValueLookupParameter<IntValue>)Parameters["IterationRuleDeletion"]; } 67 } 68 public IValueLookupParameter<IntValue> RuleDeletionMinRulesParameter { 69 get { return (IValueLookupParameter<IntValue>)Parameters["RuleDeletionMinRules"]; } 70 } 71 72 public ILookupParameter<ItemList<ItemList<IntValue>>> StrataParameter { 73 get { return (ILookupParameter<ItemList<ItemList<IntValue>>>)Parameters["Strata"]; } 74 } 75 #endregion 76 77 public IRandom Random { 78 get { return RandomParameter.ActualValue; } 35 79 } 36 80 … … 42 86 public MDLEvaluator() 43 87 : base() { 44 Parameters.Add(new ValueLookupParameter<MDLCalculator>("MDLCalculator", "")); 88 Parameters.Add(new LookupParameter<IRandom>("Random", "The random generator to use.")); 89 Parameters.Add(new LookupParameter<DecisionList>("DecisionList", "")); 90 Parameters.Add(new ValueLookupParameter<IntValue>("SizePenaltyMinRules", "")); 91 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "")); 92 Parameters.Add(new ValueLookupParameter<IDecisionListClassificationProblemData>("ProblemData", "")); 93 Parameters.Add(new LookupParameter<MDLCalculator>("MDLCalculator", "")); 94 Parameters.Add(new LookupParameter<IntValue>("Iterations", "")); 95 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "")); 96 Parameters.Add(new ValueLookupParameter<IntValue>("IterationRuleDeletion", "", new IntValue(5))); 97 Parameters.Add(new ValueLookupParameter<IntValue>("RuleDeletionMinRules", "", new IntValue(12))); 98 Parameters.Add(new ValueLookupParameter<ItemList<ItemList<IntValue>>>("Strata", "")); 45 99 } 46 100 public override IDeepCloneable Clone(Cloner cloner) { … … 51 105 double penalty = 1; 52 106 53 var dls = new DecisionListSolution(DecisionListParameter.ActualValue, ProblemDataParameter.ActualValue); 107 var strata = StrataParameter.ActualValue; 108 int iteration = IterationsParameter.ActualValue.Value; 109 int numberOfStrata = strata.Count; 110 var dl = DecisionListParameter.ActualValue; 111 var problemData = ProblemDataParameter.ActualValue; 112 bool lastIteration = iteration == MaximumIterationsParameter.ActualValue.Value - 1; 113 IEnumerable<int> rows; 114 if (lastIteration) { 115 rows = from s in strata 116 from row in s 117 select row.Value; 118 } else { 119 rows = strata[iteration % numberOfStrata].Select(x => x.Value); 120 } 121 var input = problemData.FetchInput(rows); 122 var actions = problemData.FetchAction(rows); 123 ItemSet<Rule> aliveRules; 124 double theoryLength; 125 var estimated = dl.Evaluate(input, out aliveRules, out theoryLength); 54 126 55 if ( dls.TrainingNumberOfAliveRules< SizePenaltyMinRulesParameter.ActualValue.Value) {56 penalty = (1 - 0.025 * (SizePenaltyMinRulesParameter.ActualValue.Value - dls.TrainingNumberOfAliveRules));127 if (aliveRules.Count < SizePenaltyMinRulesParameter.ActualValue.Value) { 128 penalty = (1 - 0.025 * (SizePenaltyMinRulesParameter.ActualValue.Value - aliveRules.Count)); 57 129 if (penalty <= 0) penalty = 0.01; 58 130 penalty *= penalty; 59 131 } 60 132 61 QualityParameter.ActualValue = new DoubleValue(MDLCalculatorParameter.ActualValue.CalculateFitness(dls) / penalty); 133 double accuracy = DecisionListSolution.CalculateAccuracy(actions, estimated); 134 QualityParameter.ActualValue = new DoubleValue(MDLCalculatorParameter.ActualValue.CalculateFitness(theoryLength, accuracy) / penalty); 135 136 if (iteration >= IterationRuleDeletionParameter.ActualValue.Value) { 137 if (lastIteration) { 138 DoRuleDeletion(dl, aliveRules, 1); 139 } else { 140 DoRuleDeletion(dl, aliveRules, RuleDeletionMinRulesParameter.ActualValue.Value); 141 } 142 } 62 143 return base.Apply(); 144 } 145 146 // default rule cannot be deleted, but it has to be considered in the rule set size 147 private void DoRuleDeletion(DecisionList dl, ItemSet<Rule> aliveRules, int minRules) { 148 int ruleSetSize = dl.RuleSetSize; 149 if (ruleSetSize <= minRules) { return; } 150 151 var deadRules = dl.Rules.Except(aliveRules).ToList(); 152 int numberOfDeadRules = deadRules.Count(); 153 154 int keepRules = minRules - (ruleSetSize - numberOfDeadRules); 155 156 if (keepRules > 0) { 157 for (int i = 0; i < keepRules; i++) { 158 int pos = Random.Next(deadRules.Count); 159 deadRules.RemoveAt(pos); 160 } 161 } 162 163 dl.RemoveRules(deadRules); 63 164 } 64 165 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/HeuristicLab.Encodings.DecisionList-3.3.csproj
r9352 r9392 100 100 <Compile Include="DecisionListNicheComparer.cs" /> 101 101 <Compile Include="DecisionListSolution.cs" /> 102 <Compile Include="Evaluator\DecisionListEvaluator.cs" />103 <Compile Include="Evaluator\MDLCalculator.cs" />104 102 <Compile Include="Evaluator\MDLEvaluator.cs" /> 105 <Compile Include="Evaluator\MDLIterationOperator.cs" />106 103 <Compile Include="Interfaces\IDecisionListClassificationProblem.cs" /> 107 104 <Compile Include="Interfaces\IDecisionListClassificationProblemData.cs" /> -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListClassificationProblemData.cs
r9352 r9392 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using HeuristicLab.Core; 25 using HeuristicLab.Data;26 23 using HeuristicLab.Optimization.Operators.LCS; 27 using HeuristicLab.Problems.DataAnalysis;28 24 29 25 namespace HeuristicLab.Encodings.DecisionList { 30 26 public interface IDecisionListClassificationProblemData : IGAssistNichesProblemData { 31 Dataset Dataset { get; }32 ICheckedItemList<StringValue> ConditionVariables { get; }33 StringValue TargetVariable { get; }34 IEnumerable<string> AllowedConditionVariables { get; }35 //IEnumerable<string> AllowedTargetVariables { get; }36 37 IntRange TrainingPartition { get; }38 IntRange TestPartition { get; }39 40 IEnumerable<int> TrainingIndices { get; }41 IEnumerable<int> TestIndices { get; }42 43 bool IsTrainingSample(int index);44 bool IsTestSample(int index);45 46 int Classes { get; }47 48 27 IValueParameter<Rule> SampleRuleParameter { get; } 49 50 DecisionListInput FetchInput(int row);51 IEnumerable<DecisionListInput> FetchInput(IEnumerable<int> row);52 53 IEnumerable<IAction> FetchAction(IEnumerable<int> rows);54 IAction FetchAction(int rows);55 56 event EventHandler Changed;57 28 } 58 29 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListEvaluator.cs
r9334 r9392 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using HeuristicLab.Optimization ;24 using HeuristicLab.Optimization.Operators.LCS; 25 25 26 26 namespace HeuristicLab.Encodings.DecisionList { 27 public interface IDecisionListEvaluator : IS ingleObjectiveEvaluator {27 public interface IDecisionListEvaluator : IStrataSingleObjectiveEvaluator { 28 28 ILookupParameter<DecisionList> DecisionListParameter { get; } 29 IValueLookupParameter<IntRange> EvaluationPartitionParameter { get; }30 IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; }31 29 IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter { get; } 32 30 IValueLookupParameter<IntValue> SizePenaltyMinRulesParameter { get; } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Interfaces/IDecisionListSolution.cs
r9334 r9392 20 20 #endregion 21 21 22 using System; 23 using HeuristicLab.Optimization.Operators.LCS; 22 24 23 using System;24 25 namespace HeuristicLab.Encodings.DecisionList { 25 public interface IDecisionListSolution {26 public interface IDecisionListSolution : IGAssistSolution { 26 27 DecisionList Model { get; } 27 IDecisionListClassificationProblemData ProblemData { get; set; }28 //IDecisionListClassificationProblemData ProblemData { get; set; } 28 29 29 30 event EventHandler ModelChanged; 30 31 event EventHandler ProblemDataChanged; 31 32 double TrainingAccuracy { get; }33 double TestAccuracy { get; }34 int TrainingNumberOfAliveRules { get; }35 double TrainingTheoryLength { get; }36 double TrainingExceptionsLength { get; }37 32 } 38 33 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Properties/AssemblyInfo.cs
r9352 r9392 55 55 // [assembly: AssemblyVersion("1.0.*")] 56 56 [assembly: AssemblyVersion("3.3.0.0")] 57 [assembly: AssemblyFileVersion("3.3.7.93 42")]57 [assembly: AssemblyFileVersion("3.3.7.9352")] -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Rule.cs
r9352 r9392 88 88 } 89 89 90 public bool MatchInput( DecisionListInput target) {90 public bool MatchInput(IGAssistInput target) { 91 91 foreach (var variable in variables) { 92 if (!target. InputDictionary.ContainsKey(variable.Key)) { throw new ArgumentException("Input doesn't contain variable"); }93 if (!variable.Value.Match(target. InputDictionary[variable.Key])) { return false; }92 if (!target.VariableNames.Contains(variable.Key)) { throw new ArgumentException("Input doesn't contain variable"); } 93 if (!variable.Value.Match(target.GetVariableValue(variable.Key))) { return false; } 94 94 } 95 95 return true; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/Variable/DoubleVariable.cs
r9342 r9392 46 46 protected DoubleVariable(DoubleVariable original, Cloner cloner) 47 47 : base(original, cloner) { 48 discretizer = (IDiscretizer)original.discretizer.Clone(); 49 curIntervals = new List<int>(original.curIntervals); 48 if (original.discretizer != null) { 49 discretizer = (IDiscretizer)original.discretizer.Clone(); 50 curIntervals = new List<int>(original.curIntervals); 51 } 50 52 maxIntervals = original.maxIntervals; 51 53 } … … 68 70 69 71 attributes = new List<bool>(numberOfIntervals); 70 varcurIntervals = new List<int>(numberOfIntervals);72 curIntervals = new List<int>(numberOfIntervals); 71 73 72 74 for (int i = 0; i < numberOfIntervals - 1; i++) { … … 74 76 microIntervals -= microInt; 75 77 curIntervals.Add(microInt); 76 attributes [i] = random.NextDouble() < onePercentage;78 attributes.Add(random.NextDouble() < onePercentage); 77 79 } 78 80 // add last interval 79 81 curIntervals.Add(microIntervals); 80 attributes [numberOfIntervals - 1] = random.NextDouble() < onePercentage;82 attributes.Add(random.NextDouble() < onePercentage); 81 83 } 82 84 … … 114 116 } 115 117 116 private IList<double> GetValuesToCutPoints(IEnumerable<double> cutpoints, I Enumerable<int> microIntervals) {118 private IList<double> GetValuesToCutPoints(IEnumerable<double> cutpoints, IList<int> microIntervals) { 117 119 var intervalValues = new List<double>(); 118 120 var cutpointList = cutpoints.ToList(); 119 int cur = 0;120 for each (var microInterval in microIntervals) {121 cur += microInterval ;121 int cur = -1; 122 for (int i = 0; i < microIntervals.Count - 1; i++) { 123 cur += microIntervals[i]; 122 124 intervalValues.Add(cutpointList[cur]); 123 125 } 126 intervalValues.Add(Double.PositiveInfinity); 124 127 return intervalValues; 125 128 } -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Crossover/SinglePointCrossover.cs
r9242 r9392 62 62 IList<IVariable> newCondition = new List<IVariable>(parent1Condition.VariableDictionary.Count); 63 63 64 var keyEnumerator = parent1Condition. Order.GetEnumerator();64 var keyEnumerator = parent1Condition.VariableDictionary.Keys.GetEnumerator(); 65 65 66 66 int index = 0; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Manipulator/UniformOnePositionInConditionManipulator.cs
r9242 r9392 54 54 throw new ArgumentOutOfRangeException(); 55 55 } 56 var keyEnumerator = condition. Order.GetEnumerator();56 var keyEnumerator = condition.VariableDictionary.Keys.GetEnumerator(); 57 57 int count = 0; 58 58 keyEnumerator.MoveNext(); -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/DoubleVariable.cs
r9242 r9392 130 130 var targetCast = target as DoubleVariable; 131 131 if (targetCast == null) { return false; } 132 if (variableName != targetCast.variableName || currentCenter.IsAlmost(targetCast.currentCenter)133 || currentSpread.IsAlmost(targetCast.currentSpread) ||max.IsAlmost(targetCast.max)134 || min.IsAlmost(targetCast.min)) { return false; }132 if (variableName != targetCast.variableName || !currentCenter.IsAlmost(targetCast.currentCenter) 133 || !currentSpread.IsAlmost(targetCast.currentSpread) || !max.IsAlmost(targetCast.max) 134 || !min.IsAlmost(targetCast.min)) { return false; } 135 135 136 136 return true; -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/IntVariable.cs
r9242 r9392 133 133 || currentValue != targetCast.currentValue) { return false; } 134 134 135 if (possibleFeatures.Except(targetCast.possibleFeatures).Count() != 0 136 || targetCast.possibleFeatures.Except(possibleFeatures).Count() != 0) { return false; } 135 var thisEnumerator = possibleFeatures.GetEnumerator(); 136 var castEnumerator = targetCast.possibleFeatures.GetEnumerator(); 137 while (thisEnumerator.MoveNext() && castEnumerator.MoveNext()) { 138 if (thisEnumerator.Current != castEnumerator.Current) 139 return false; 140 } 137 141 138 return true;142 return !thisEnumerator.MoveNext() && !castEnumerator.MoveNext(); 139 143 } 140 144 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Variable/StringVariable.cs
r9242 r9392 87 87 featureMapping = new Dictionary<int, string>(); 88 88 var distinctValuesEnumerator = variableValues.Distinct().GetEnumerator(); 89 possibleFeatures = Enumerable.Range(0, featureMapping.Count());89 possibleFeatures = Enumerable.Range(0, variableValues.Count()); 90 90 var possibleFeaturesEnumerator = possibleFeatures.GetEnumerator(); 91 91 while (possibleFeaturesEnumerator.MoveNext() && distinctValuesEnumerator.MoveNext()) { … … 178 178 || currentValue != targetCast.currentValue) { return false; } 179 179 180 if (featureMapping.Keys.Except(targetCast.featureMapping.Keys).Count() != 0 181 || targetCast.featureMapping.Keys.Except(featureMapping.Keys).Count() != 0) { return false; } 182 183 foreach (var keyValuePair in targetCast.featureMapping) { 184 if (!featureMapping[keyValuePair.Key].Equals(keyValuePair.Value)) { return false; } 185 } 186 187 return true; 180 var thisEnumerator = featureMapping.GetEnumerator(); 181 var castEnumerator = targetCast.featureMapping.GetEnumerator(); 182 while (thisEnumerator.MoveNext() && castEnumerator.MoveNext()) { 183 if (thisEnumerator.Current.Key != castEnumerator.Current.Key || 184 thisEnumerator.Current.Value != castEnumerator.Current.Value) 185 return false; 186 } 187 188 return !thisEnumerator.MoveNext() && !castEnumerator.MoveNext(); 188 189 } 189 190 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorActionComparer.cs
r9242 r9392 21 21 22 22 using System.Collections.Generic; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 43 42 44 43 public bool Equals(VariableVectorAction x, VariableVectorAction y) { 45 if (!x.Order.SequenceEqual(y.Order)) return false; 46 foreach (var key in x.VariableDictionary.Keys) { 47 if (!x.VariableDictionary[key].Identical(y.VariableDictionary[key])) { 48 return false; 44 //if (!x.Order.SequenceEqual(y.Order)) return false; 45 var xEnumerator = x.VariableDictionary.Keys.GetEnumerator(); 46 var yEnumerator = y.VariableDictionary.Keys.GetEnumerator(); 47 while (xEnumerator.MoveNext() && yEnumerator.MoveNext()) 48 foreach (var key in x.VariableDictionary.Keys) { 49 if (xEnumerator.Current != yEnumerator.Current || 50 !x.VariableDictionary[xEnumerator.Current].Identical(y.VariableDictionary[yEnumerator.Current])) { 51 return false; 52 } 49 53 } 50 } 51 return true; 54 return !xEnumerator.MoveNext() && !yEnumerator.MoveNext(); 52 55 } 53 56 -
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/VariableVectorCondition.cs
r9242 r9392 39 39 protected set { variableDictionary = value; } 40 40 } 41 42 public IOrderedEnumerable<string> Order { get { return VariableDictionary.Keys.OrderBy(x => x); } }43 41 44 42 public int VirtualLength { get { return VariableDictionary.Values.Sum(x => x.VirtualLength); } } … … 110 108 111 109 public bool Identical(VariableVectorCondition target) { 112 if (!this.Order.SequenceEqual(target.Order)) { return false; } 113 foreach (var keyValuePair in target.VariableDictionary) { 114 if (!VariableDictionary[keyValuePair.Key].Identical(keyValuePair.Value)) { 110 var thisEnumerator = VariableDictionary.GetEnumerator(); 111 var targetEnumerator = target.VariableDictionary.GetEnumerator(); 112 113 while (thisEnumerator.MoveNext() && targetEnumerator.MoveNext()) { 114 if (thisEnumerator.Current.Key != targetEnumerator.Current.Key || 115 !thisEnumerator.Current.Value.Identical(targetEnumerator.Current.Value)) { 115 116 return false; 116 117 } 117 118 } 118 return true; 119 120 return !thisEnumerator.MoveNext() && !targetEnumerator.MoveNext(); 119 121 } 120 122 } -
branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/Discretizer/IDiscretizer.cs
r9342 r9392 25 25 namespace HeuristicLab.Optimization.Operators.LCS { 26 26 public interface IDiscretizer : IItem { 27 IEnumerable<double> DiscretizeValues(string attribute, IEnumerable<double> values); 27 28 int NumberOfMicroIntervals(string attribute); 28 29 IEnumerable<double> GetCutPoints(string attribute); -
branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/Discretizer/UniformWidthDiscretizer.cs
r9342 r9392 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; … … 42 41 protected UniformWidthDiscretizer(UniformWidthDiscretizer original, Cloner cloner) 43 42 : base(original, cloner) { 43 this.bins = original.bins; 44 this.variableMicroItervals = new Dictionary<string, IList<double>>(original.variableMicroItervals); 44 45 } 45 46 public UniformWidthDiscretizer() 46 : base() { 47 bins = 5; 47 : this(5) { 48 48 } 49 49 public UniformWidthDiscretizer(int bins) … … 60 60 } 61 61 62 public IEnumerable<double> discretizeValues(string attribute, IEnumerable<double> values) { 63 if (variableMicroItervals.ContainsKey(attribute)) { 64 throw new ArgumentException("Values of attribute " + attribute + " are already set."); 65 } 66 62 public IEnumerable<double> DiscretizeValues(string attribute, IEnumerable<double> values) { 67 63 double min = values.Min(); 68 64 double max = values.Max(); -
branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/GAssist/IGAssistNichesProblemData.cs
r9352 r9392 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 26 using HeuristicLab.Problems.DataAnalysis; 24 27 25 28 namespace HeuristicLab.Optimization.Operators.LCS { 26 29 public interface IGAssistNichesProblemData : INamedItem { 30 Dataset Dataset { get; } 31 ICheckedItemList<StringValue> ConditionVariables { get; } 32 StringValue TargetVariable { get; } 33 IEnumerable<string> AllowedConditionVariables { get; } 34 //IEnumerable<string> AllowedTargetVariables { get; } 35 36 IntRange TrainingPartition { get; } 37 IntRange TestPartition { get; } 38 39 IEnumerable<int> TrainingIndices { get; } 40 IEnumerable<int> TestIndices { get; } 41 42 bool IsTrainingSample(int index); 43 bool IsTestSample(int index); 44 45 int Classes { get; } 46 47 IGAssistInput FetchInput(int row); 48 IEnumerable<IGAssistInput> FetchInput(IEnumerable<int> row); 49 50 IEnumerable<IGAssistNiche> FetchAction(IEnumerable<int> rows); 51 IGAssistNiche FetchAction(int rows); 52 53 event EventHandler Changed; 54 27 55 IEnumerable<IGAssistNiche> GetPossibleNiches(); 28 56 } -
branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/GAssist/IGAssistProblem.cs
r9352 r9392 21 21 22 22 using HeuristicLab.Core; 23 23 24 namespace HeuristicLab.Optimization.Operators.LCS { 24 25 public interface IGAssistProblem : ISingleObjectiveHeuristicOptimizationProblem { 26 new IStrataSingleObjectiveEvaluator Evaluator { get; } 27 25 28 IParameter ProblemDataParameter { get; } 26 29 string NichingParameterName { get; } -
branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/GAssist/Interfaces/IGAssistIndividual.cs
r9352 r9392 30 30 void ApplyMerge(IRandom random, double probability); 31 31 void ApplyReinitialize(IRandom random, double probability, double oneProbability, IEnumerable<IDiscretizer> discretizers); 32 33 IGAssistSolution CreateGAssistSolution(IGAssistNichesProblemData problemData); 32 34 } 33 35 } -
branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/HeuristicLab.Optimization.Operators.LCS-3.3.csproj
r9352 r9392 89 89 <ItemGroup> 90 90 <Compile Include="DefaultRule\AutoDefaultRule.cs" /> 91 <Compile Include="Discretizer\InitializeDiscretizersOperator.cs" /> 91 92 <Compile Include="GAssist\IGAssistNichesProblemData.cs" /> 92 93 <Compile Include="DefaultRule\MajorDefaultRule.cs" /> … … 98 99 <Compile Include="Discretizer\IDiscretizer.cs" /> 99 100 <Compile Include="GAssist\IGAssistProblem.cs" /> 101 <Compile Include="GAssist\ILAS\ILASOperator.cs" /> 100 102 <Compile Include="GAssist\Interfaces\IGAssistIndividual.cs" /> 101 103 <Compile Include="GAssist\Interfaces\IGAssistIndividualCreator.cs" /> 104 <Compile Include="GAssist\Interfaces\IGAssistInput.cs" /> 102 105 <Compile Include="GAssist\Interfaces\IGAssistNiche.cs" /> 103 106 <Compile Include="GAssist\Interfaces\IGAssistNicheEqualityComparer.cs" /> 107 <Compile Include="GAssist\Interfaces\IGAssistSolution.cs" /> 104 108 <Compile Include="GAssist\Interfaces\IGAssistSpecialStage.cs" /> 109 <Compile Include="GAssist\Interfaces\IStrataSingleObjectiveEvaluator.cs" /> 110 <Compile Include="GAssist\MDL\IMDLCalculatorBasedOperator.cs" /> 111 <Compile Include="GAssist\MDL\MDLCalculator.cs" /> 112 <Compile Include="GAssist\MDL\MDLIterationOperator.cs" /> 105 113 <Compile Include="GAssist\SpecialStage\GAssistSpecialStageMultiOperator.cs" /> 106 114 <Compile Include="GAssist\SpecialStage\GAssistSpecialStageOperator.cs" /> … … 124 132 <Name>HeuristicLab.Core-3.3</Name> 125 133 </ProjectReference> 134 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj"> 135 <Project>{df87c13e-a889-46ff-8153-66dcaa8c5674}</Project> 136 <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name> 137 </ProjectReference> 126 138 </ItemGroup> 127 139 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/Selection/NichingTournamentSelector.cs
r9352 r9392 88 88 89 89 int parentsPerChild = ParentsPerChildParameter.ActualValue.Value; 90 var possibleNiches = GAssistNichesProblemDataParameter.ActualValue.GetPossibleNiches().ToList(); 91 var selectPerNiche = new Dictionary<IGAssistNiche, int>(possibleNiches.First().Comparer); 90 var nicheComparer = GAssistNichesProblemDataParameter.ActualValue.GetPossibleNiches().First().Comparer; 91 var selectPerNiche = new Dictionary<IGAssistNiche, int>(nicheComparer); 92 var nicheScope = new Dictionary<IGAssistNiche, List<int>>(nicheComparer); 92 93 93 var nicheScope = new Dictionary<IGAssistNiche, List<int>>(possibleNiches.First().Comparer); 94 foreach (var niche in possibleNiches) { 95 nicheScope.Add(niche, new List<int>()); 96 selectPerNiche.Add(niche, count / possibleNiches.Count); 94 for (int i = 0; i < individuals.Count; i++) { 95 if (!nicheScope.ContainsKey(individuals[i].Niche)) { 96 nicheScope.Add(individuals[i].Niche, new List<int>()); 97 } 98 nicheScope[individuals[i].Niche].Add(i); 97 99 } 98 100 99 for (int i = 0; i < individuals.Count; i++) { 100 nicheScope[individuals[i].Niche].Add(i); 101 var possibleNiches = nicheScope.Keys.ToList(); 102 foreach (var niche in possibleNiches) { 103 selectPerNiche.Add(niche, count / possibleNiches.Count); 101 104 } 102 105 … … 144 147 } 145 148 146 private IGAssistNiche GetNiche(IRandom random, Dictionary<IGAssistNiche, int> nicheScope, List<IGAssistNiche> possibleNiches) {147 int sum = nicheScope.Values.Sum();149 private IGAssistNiche GetNiche(IRandom random, Dictionary<IGAssistNiche, int> selectPerNiche, List<IGAssistNiche> possibleNiches) { 150 int sum = selectPerNiche.Values.Sum(); 148 151 if (sum <= 0) { return possibleNiches[random.Next(possibleNiches.Count)]; } 149 152 int pos = random.Next(sum); 150 153 int total = 0; 151 IGAssistNiche niche = nicheScope.Keys.First();152 foreach (var item in nicheScope) {154 IGAssistNiche niche = selectPerNiche.Keys.First(); 155 foreach (var item in selectPerNiche) { 153 156 total += item.Value; 154 157 niche = item.Key; -
branches/LearningClassifierSystems/HeuristicLab.Problems.ConditionActionClassification/3.3/ConditionActionClassificationProblemData.cs
r9352 r9392 126 126 if (allowedConditionVariables == null) throw new ArgumentNullException("The allowedActionVariables must not be null."); 127 127 128 if (allowedActionVariables.Except(dataset.DoubleVariables).Any()) 129 throw new ArgumentException("All allowed action variables must be present in the dataset and of type double."); 130 if (allowedConditionVariables.Except(dataset.DoubleVariables).Any()) 131 throw new ArgumentException("All allowed condition variables must be present in the dataset and of type double."); 132 133 var actionVariables = new CheckedItemList<StringValue>(dataset.DoubleVariables.Select(x => new StringValue(x))); 128 var actionVariables = new CheckedItemList<StringValue>(dataset.VariableNames.Select(x => new StringValue(x))); 134 129 var conditionVariables = new CheckedItemList<StringValue>(actionVariables); 135 130 foreach (StringValue x in actionVariables) { -
branches/LearningClassifierSystems/HeuristicLab.Problems.DecisionListClassification/3.3/DecisionListClassificationProblem.cs
r9352 r9392 62 62 get { return (IFixedValueParameter<IntValue>)Parameters["SizePenaltyMinRules"]; } 63 63 } 64 public IFixedValueParameter<IntValue> ActivationIterationParameter {65 get { return (IFixedValueParameter<IntValue>)Parameters["ActivationIteration"]; }66 }67 64 public IFixedValueParameter<DoubleValue> InitialTheoryLengthRatioParameter { 68 65 get { return (IFixedValueParameter<DoubleValue>)Parameters["InitialTheoryLengthRatio"]; } … … 88 85 } 89 86 87 IStrataSingleObjectiveEvaluator IGAssistProblem.Evaluator { 88 get { return Evaluator; } 89 } 90 90 IDecisionListEvaluator IDecisionListClassificationProblem.Evaluator { 91 91 get { return Evaluator; } … … 101 101 : base(original, cloner) { 102 102 } 103 public override IDeepCloneable Clone(Cloner cloner) { 104 return new DecisionListClassificationProblem(this, cloner); 105 } 103 106 104 107 public DecisionListClassificationProblem() … … 113 116 Parameters.Add(new FixedValueParameter<DoubleValue>("BestKnownQuality", "", new DoubleValue(0.5))); 114 117 Parameters.Add(new FixedValueParameter<IntValue>("SizePenaltyMinRules", "", new IntValue(4))); 115 Parameters.Add(new FixedValueParameter<IntValue>("ActivationIteration", "", new IntValue(25)));116 Parameters.Add(new FixedValueParameter<DoubleValue>("InitialTheoryLengthRatio", "", new DoubleValue(0.075)));117 Parameters.Add(new FixedValueParameter<DoubleValue>("WeightRelaxFactor", "", new DoubleValue(0.9)));118 118 Parameters.Add(new FixedValueParameter<PercentValue>("ActionMutationProbability", "", new PercentValue(0.1))); 119 119 120 120 Evaluator.SizePenaltyMinRulesParameter.ActualName = "SizePenaltyMinRules"; 121 // do differently122 ((MDLEvaluator)Evaluator).MDLCalculatorParameter.Value = new MDLCalculator(ActivationIterationParameter.Value.Value, InitialTheoryLengthRatioParameter.Value.Value, WeightRelaxFactorParameter.Value.Value);123 121 124 122 InitializeOperators(); … … 169 167 } 170 168 } 171 public override IDeepCloneable Clone(Cloner cloner) {172 return new DecisionListClassificationProblem(this, cloner);173 }174 169 175 170 IParameter IGAssistProblem.ProblemDataParameter { -
branches/LearningClassifierSystems/HeuristicLab.Problems.DecisionListClassification/3.3/DecisionListClassificationProblemData.cs
r9352 r9392 214 214 } 215 215 216 public IEnumerable< DecisionListInput> FetchInput(IEnumerable<int> rows) {216 public IEnumerable<IGAssistInput> FetchInput(IEnumerable<int> rows) { 217 217 foreach (var row in rows) { 218 218 yield return FetchInput(row); … … 221 221 222 222 protected IDictionary<int, DecisionListInput> fetchInputCache = new Dictionary<int, DecisionListInput>(); 223 public DecisionListInput FetchInput(int row) {223 public IGAssistInput FetchInput(int row) { 224 224 if (!fetchInputCache.ContainsKey(row)) { 225 225 DecisionListInput input = new DecisionListInput(); … … 234 234 } 235 235 236 public IEnumerable<I Action> FetchAction(IEnumerable<int> rows) {236 public IEnumerable<IGAssistNiche> FetchAction(IEnumerable<int> rows) { 237 237 foreach (var row in rows) { 238 238 yield return FetchAction(row); … … 240 240 } 241 241 protected IDictionary<int, IAction> fetchActionCache = new Dictionary<int, IAction>(); 242 public I ActionFetchAction(int row) {242 public IGAssistNiche FetchAction(int row) { 243 243 if (!fetchActionCache.ContainsKey(row)) { 244 244 var action = (IAction)SampleRuleParameter.Value.Action.Clone(); -
branches/LearningClassifierSystems/HeuristicLab.Problems.DecisionListClassification/3.3/Properties
-
Property
svn:ignore
set to
AssemblyInfo.cs
-
Property
svn:ignore
set to
-
branches/LearningClassifierSystems/HeuristicLab.Problems.VariableVectorClassification/3.3/VariableVectorClassificationProblemData.cs
r9352 r9392 89 89 } else if (variableValues is List<double>) { 90 90 var doubleValues = (variableValues as List<double>).Distinct(); 91 if (doubleValues.All(x => x % 1 == 0 )) {91 if (doubleValues.All(x => x % 1 == 0 || Double.IsNaN(x))) { 92 92 // ToList call is necessary, because otherwise it wouldn't be possible to serialize it 93 93 variable = new IntVariable(variableName, doubleValues.Select(x => Convert.ToInt32(x)).ToList()); -
branches/LearningClassifierSystems/LearningClassifierSystem.sln
r9352 r9392 184 184 HideSolutionNode = FALSE 185 185 EndGlobalSection 186 GlobalSection(Performance) = preSolution 187 HasPerformanceSessions = true 188 EndGlobalSection 186 189 EndGlobal
Note: See TracChangeset
for help on using the changeset viewer.