- Timestamp:
- 04/06/21 13:13:32 (4 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 1 deleted
- 18 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs
r17180 r17928 96 96 } 97 97 98 public static IntervalCollection GetIntervals(this IDataset dataset) { 99 IntervalCollection intervalCollection = new IntervalCollection(); 100 foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables 101 var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable)); 102 intervalCollection.AddInterval(variable, variableInterval); 103 } 104 105 return intervalCollection; 106 } 107 98 108 public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> GetFactorVariableValues( 99 109 this IDataset ds, IEnumerable<string> factorVariables, IEnumerable<int> rows) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r16788 r17928 140 140 <Compile Include="Implementation\ConstantModel.cs" /> 141 141 <Compile Include="Implementation\DataAnalysisModel.cs" /> 142 <Compile Include="Implementation\Interval.cs" /> 142 <Compile Include="Implementation\Interval\Interval.cs" /> 143 <Compile Include="Implementation\Interval\IntervalCollection.cs" /> 144 <Compile Include="Implementation\Interval\ShapeConstraint.cs" /> 145 <Compile Include="Implementation\Interval\ShapeConstraintsParser.cs" /> 143 146 <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" /> 144 147 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> 145 148 <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" /> 149 <Compile Include="Implementation\Regression\ShapeConstraints.cs" /> 146 150 <Compile Include="Implementation\Regression\RegressionEnsembleProblemData.cs" /> 147 151 <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs"> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs
r17180 r17928 73 73 74 74 public ClassificationEnsembleProblemData() : base() { } 75 75 76 public ClassificationEnsembleProblemData(IClassificationProblemData classificationProblemData) 76 : base(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) { 77 this.TrainingPartition.Start = classificationProblemData.TrainingPartition.Start; 78 this.TrainingPartition.End = classificationProblemData.TrainingPartition.End; 79 this.TestPartition.Start = classificationProblemData.TestPartition.Start; 80 this.TestPartition.End = classificationProblemData.TestPartition.End; 81 this.PositiveClass = classificationProblemData.PositiveClass; 77 : base(classificationProblemData) { 82 78 } 83 79 … … 85 81 : base(dataset, allowedInputVariables, targetVariable) { 86 82 } 83 84 public ClassificationEnsembleProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<string> classNames, string positiveClass = null) 85 : base(dataset, allowedInputVariables, targetVariable, classNames, positiveClass) { 86 } 87 87 } 88 88 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r17180 r17928 260 260 evaluationCache.Clear(); 261 261 262 IClassificationProblemData problemData = new ClassificationProblemData(ProblemData.Dataset, 263 ProblemData.AllowedInputVariables, 264 ProblemData.TargetVariable); 265 problemData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 266 problemData.TrainingPartition.End = ProblemData.TrainingPartition.End; 267 problemData.TestPartition.Start = ProblemData.TestPartition.Start; 268 problemData.TestPartition.End = ProblemData.TestPartition.End; 262 IClassificationProblemData problemData = new ClassificationProblemData(ProblemData); 269 263 270 264 foreach (var solution in ClassificationSolutions) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r17180 r17928 306 306 classNamesCache.Add(ClassNamesParameter.Value[i, 0]); 307 307 } 308 308 309 public override IDeepCloneable Clone(Cloner cloner) { 309 310 if (this == emptyProblemData) return emptyProblemData; … … 311 312 } 312 313 313 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable ) { }314 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable, Enumerable.Empty<string>()) { } 314 315 315 316 public ClassificationProblemData(IClassificationProblemData classificationProblemData) 316 : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) { 317 : this(classificationProblemData, classificationProblemData.Dataset) { 318 } 319 320 /// <summary> 321 /// This method satisfies a common use case: making a copy of the problem but providing a different dataset. 322 /// One must be careful here that the dataset passed is not modified, as that would invalidate the problem data internals. 323 /// Passing a ModifiableDataset to this constructor is therefore discouraged. 324 /// </summary> 325 /// <param name="classificationProblemData">The original instance of classification problem data.</param> 326 /// <param name="dataset">The new dataset.</param> 327 public ClassificationProblemData(IClassificationProblemData classificationProblemData, IDataset dataset) 328 : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable, classificationProblemData.ClassNames, classificationProblemData.PositiveClass) { 329 317 330 TrainingPartition.Start = classificationProblemData.TrainingPartition.Start; 318 331 TrainingPartition.End = classificationProblemData.TrainingPartition.End; … … 320 333 TestPartition.End = classificationProblemData.TestPartition.End; 321 334 322 for (int i = 0; i < classificationProblemData.ClassNames.Count(); i++)323 ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i);324 325 //mkommend: The positive class depends on the class names and as a result must only be set after the classe names parameter.326 PositiveClass = classificationProblemData.PositiveClass;327 328 335 for (int i = 0; i < Classes; i++) { 329 336 for (int j = 0; j < Classes; j++) { … … 333 340 } 334 341 335 public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 342 public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 343 IEnumerable<string> classNames = null, 344 string positiveClass = null, // can be null in which case it's set as the first class name 345 IEnumerable<ITransformation> transformations = null) 336 346 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 337 347 var validTargetVariableValues = CheckVariablesForPossibleTargetVariables(dataset).Select(x => new StringValue(x).AsReadOnly()).ToList(); … … 339 349 340 350 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(validTargetVariableValues), target)); 341 Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "" ));351 Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "", new StringMatrix())); 342 352 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)")); 343 353 Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "")); 344 354 345 355 RegisterParameterEvents(); 346 ResetTargetVariableDependentMembers(); 356 ResetTargetVariableDependentMembers(); // correctly set the values of the parameters added above 357 358 // set the class names 359 if (classNames != null && classNames.Any()) { 360 // better to allocate lists because we use these multiple times below 361 var names = classNames.ToList(); 362 var values = ClassValuesCache; 363 364 if (names.Count != values.Count) { 365 throw new ArgumentException(); 366 } 367 368 ((IStringConvertibleMatrix)ClassNamesParameter.Value).Columns = 1; 369 ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = names.Count; 370 371 for (int i = 0; i < names.Count; ++i) { 372 SetClassName(values[i], names[i]); 373 } 374 } 375 376 // set the positive class value 377 if (positiveClass != null) { 378 PositiveClass = positiveClass; 379 } 347 380 } 348 381 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs
r17180 r17928 26 26 using System.Collections.Generic; 27 27 using System.Linq; 28 using HEAL.Attic; 28 29 using HeuristicLab.Common; 29 30 using HeuristicLab.Core; 30 31 using HeuristicLab.Data; 31 32 using HeuristicLab.Parameters; 32 using HEAL.Attic;33 33 using HeuristicLab.Random; 34 34 … … 173 173 174 174 IList originalValues = null; 175 IList replacementValues = GetReplacementValues(modifiableDataset, variableName, model, rows, targetValues, out originalValues, replacementMethod, factorReplacementMethod);176 177 double newValue = CalculateQualityForReplacement(model, modifiableDataset, variableName, originalValues, rows, replacementValues, targetValues);175 IList replacementValues = GetReplacementValues(modifiableDataset, variableName, model, problemData.AllowedInputVariables, rows, targetValues, out originalValues, replacementMethod, factorReplacementMethod); 176 177 double newValue = CalculateQualityForReplacement(model, modifiableDataset, problemData.AllowedInputVariables, variableName, originalValues, rows, replacementValues, targetValues); 178 178 double impact = quality - newValue; 179 179 … … 184 184 string variableName, 185 185 IClassificationModel model, 186 IEnumerable<string> allowedInputVariables, 186 187 IEnumerable<int> rows, 187 188 IEnumerable<double> targetValues, … … 196 197 } else if (modifiableDataset.VariableHasType<string>(variableName)) { 197 198 originalValues = modifiableDataset.GetReadOnlyStringValues(variableName).ToList(); 198 replacementValues = GetReplacementValuesForString(model, modifiableDataset, variableName, rows, (List<string>)originalValues, targetValues, factorReplacementMethod);199 replacementValues = GetReplacementValuesForString(model, modifiableDataset, allowedInputVariables, variableName, rows, (List<string>)originalValues, targetValues, factorReplacementMethod); 199 200 } else { 200 201 throw new NotSupportedException("Variable not supported"); … … 254 255 private static IList GetReplacementValuesForString(IClassificationModel model, 255 256 ModifiableDataset modifiableDataset, 257 IEnumerable<string> allowedInputVariables, 256 258 string variableName, 257 259 IEnumerable<int> rows, … … 270 272 List<string> curReplacementValues = Enumerable.Repeat(repl, modifiableDataset.Rows).ToList(); 271 273 //fholzing: this result could be used later on (theoretically), but is neglected for better readability/method consistency 272 var newValue = CalculateQualityForReplacement(model, modifiableDataset, variableName, originalValues, rows, curReplacementValues, targetValues);274 var newValue = CalculateQualityForReplacement(model, modifiableDataset, allowedInputVariables, variableName, originalValues, rows, curReplacementValues, targetValues); 273 275 var curQuality = newValue; 274 276 … … 308 310 IClassificationModel model, 309 311 ModifiableDataset modifiableDataset, 312 IEnumerable<string> allowedInputVariables, 310 313 string variableName, 311 314 IList originalValues, … … 317 320 var discModel = model as IDiscriminantFunctionClassificationModel; 318 321 if (discModel != null) { 319 var problemData = new ClassificationProblemData(modifiableDataset, modifiableDataset.VariableNames, model.TargetVariable);322 var problemData = new ClassificationProblemData(modifiableDataset, allowedInputVariables, model.TargetVariable); 320 323 discModel.RecalculateModelParameters(problemData, rows); 321 324 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs
r17180 r17928 74 74 classValues = (double[])original.classValues.Clone(); 75 75 thresholds = (double[])original.thresholds.Clone(); 76 thresholdCalculator = (IDiscriminantFunctionThresholdCalculator)original.thresholdCalculator.Clone(); 76 77 } 77 78 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17180 r17928 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 29 using HeuristicLab.Parameters; 29 using HEAL.Attic;30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis { … … 34 34 public class RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData, IStorableContent { 35 35 protected const string TargetVariableParameterName = "TargetVariable"; 36 protected const string VariableRangesParameterName = "VariableRanges"; 37 protected const string ShapeConstraintsParameterName = "ShapeConstraints"; 36 38 public string Filename { get; set; } 37 39 … … 91 93 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 92 94 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 95 problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection())); 96 problemData.Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, "", new ShapeConstraints())); 93 97 emptyProblemData = problemData; 94 98 } 95 99 #endregion 96 100 97 public IConstrainedValueParameter<StringValue> TargetVariableParameter { 98 get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; } 99 } 101 #region parameter properties 102 public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; 103 public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => (IFixedValueParameter<ShapeConstraints>)Parameters[ShapeConstraintsParameterName]; 104 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 105 #endregion 106 107 #region properties 108 public IntervalCollection VariableRanges { 109 get => VariableRangesParameter.Value; 110 } 111 112 113 public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value; 114 115 100 116 public string TargetVariable { 101 117 get { return TargetVariableParameter.Value.Value; } … … 109 125 } 110 126 } 111 112 public IEnumerable<double> TargetVariableValues { 113 get { return Dataset.GetDoubleValues(TargetVariable); } 114 } 115 public IEnumerable<double> TargetVariableTrainingValues { 116 get { return Dataset.GetDoubleValues(TargetVariable, TrainingIndices); } 117 } 118 public IEnumerable<double> TargetVariableTestValues { 119 get { return Dataset.GetDoubleValues(TargetVariable, TestIndices); } 120 } 127 public IEnumerable<double> TargetVariableValues => Dataset.GetDoubleValues(TargetVariable); 128 public IEnumerable<double> TargetVariableTrainingValues => Dataset.GetDoubleValues(TargetVariable, TrainingIndices); 129 public IEnumerable<double> TargetVariableTestValues => Dataset.GetDoubleValues(TargetVariable, TestIndices); 130 #endregion 131 121 132 122 133 … … 125 136 [StorableHook(HookType.AfterDeserialization)] 126 137 private void AfterDeserialization() { 138 if (!Parameters.ContainsKey(VariableRangesParameterName)) { 139 var intervalCollection = Dataset.GetIntervals(); 140 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection)); 141 } 142 if (Parameters.ContainsKey("IntervalConstraints")) { 143 var param = (IFixedValueParameter<ShapeConstraints>)Parameters["IntervalConstraints"]; 144 Parameters.Remove(param); 145 Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, param.Value)); 146 } 147 if (!Parameters.ContainsKey(ShapeConstraintsParameterName)) { 148 Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, new ShapeConstraints())); 149 } 150 127 151 RegisterParameterEvents(); 128 152 } … … 148 172 } 149 173 150 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 174 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 175 IEnumerable<ITransformation> transformations = null, 176 IntervalCollection variableRanges = null, 177 ShapeConstraints shapeConstraints = null) 151 178 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 152 179 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 153 180 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First())); 181 if (variableRanges == null) { 182 variableRanges = Dataset.GetIntervals(); 183 } 184 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges)); 185 186 if (shapeConstraints == null) { 187 shapeConstraints = new ShapeConstraints(); 188 } 189 Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, shapeConstraints)); 154 190 RegisterParameterEvents(); 155 191 } 156 157 192 private void RegisterParameterEvents() { 158 TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged); 159 } 160 private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) { 193 TargetVariableParameter.ValueChanged += new EventHandler(Parameter_ValueChanged); 194 // VariableRanges and ShapeConstraints are fixed parameters 195 } 196 private void Parameter_ValueChanged(object sender, EventArgs e) { 161 197 OnChanged(); 162 198 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs
r17180 r17928 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 [StorableType("f85ccf7a-7df5-431e-bc4d-be6f3c4c2338")]28 27 /// <summary> 29 28 /// Interface for all data-analysis models (regression/classification/clustering). 30 29 /// <remarks>All methods and properties in in this interface must be implemented thread safely</remarks> 31 30 /// </summary> 31 [StorableType("f85ccf7a-7df5-431e-bc4d-be6f3c4c2338")] 32 32 public interface IDataAnalysisModel : INamedItem { 33 33 IEnumerable<string> VariablesUsedForPrediction { get; } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblem.cs
r17180 r17928 35 35 [StorableType("c2f6fcdd-ab62-4423-be75-01aa694df411")] 36 36 public interface IDataAnalysisProblem<T> : IDataAnalysisProblem 37 where T : class, IDataAnalysisProblemData {37 where T : class, IDataAnalysisProblemData { 38 38 new IValueParameter<T> ProblemDataParameter { get; } 39 39 new T ProblemData { get; set; } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs
r17180 r17928 22 22 using System; 23 23 using System.Collections.Generic; 24 using HEAL.Attic; 24 25 25 26 namespace HeuristicLab.Problems.DataAnalysis { 27 [StorableType("3283B3FB-8467-4B99-9B6E-23BF3D1B8505")] 26 28 public interface IDependencyCalculator { 27 29 double Maximum { get; } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IOnlineCalculator.cs
r17180 r17928 22 22 23 23 using System; 24 using HEAL.Attic; 25 24 26 namespace HeuristicLab.Problems.DataAnalysis { 25 27 [Flags] 28 [StorableType("8A28DDA1-4814-4B77-9457-0EE930BE9C73")] 26 29 public enum OnlineCalculatorError { 27 30 /// <summary> … … 38 41 InsufficientElementsAdded = 2 39 42 } 43 44 [StorableType("119C8242-3EE7-4C34-A7AC-68ABF76EB11B")] 40 45 public interface IOnlineCalculator { 41 46 OnlineCalculatorError ErrorState { get; } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs
r17180 r17928 1 1 #region License Information 2 2 3 /* HeuristicLab 3 4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 18 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 20 */ 21 20 22 #endregion 21 23 … … 28 30 string TargetVariable { get; set; } 29 31 32 IntervalCollection VariableRanges { get; } 33 ShapeConstraints ShapeConstraints { get; } 34 30 35 IEnumerable<double> TargetVariableValues { get; } 31 36 IEnumerable<double> TargetVariableTrainingValues { get; } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/IOnlineTimeSeriesCalculator.cs
r17180 r17928 22 22 23 23 using System.Collections.Generic; 24 using HEAL.Attic; 24 25 25 26 namespace HeuristicLab.Problems.DataAnalysis { 27 [StorableType("7461AC5D-9D9A-4DCD-B32F-602260E58FFC")] 26 28 public interface IOnlineTimeSeriesCalculator { 27 29 OnlineCalculatorError ErrorState { get; }
Note: See TracChangeset
for help on using the changeset viewer.