- Timestamp:
- 06/25/15 18:21:19 (10 years ago)
- Location:
- branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis
- Files:
-
- 33 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis (added) merged: 12485,12492,12504,12509,12511
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r12012 r12515 33 33 [Item("Dataset", "Represents a dataset containing data that should be analyzed.")] 34 34 [StorableClass] 35 public sealed class Dataset : NamedItem, IStringConvertibleMatrix{35 public class Dataset : NamedItem, IDataset { 36 36 [StorableConstructor] 37 pr ivateDataset(bool deserializing) : base(deserializing) { }38 pr ivateDataset(Dataset original, Cloner cloner)37 protected Dataset(bool deserializing) : base(deserializing) { } 38 protected Dataset(Dataset original, Cloner cloner) 39 39 : base(original, cloner) { 40 40 variableValues = new Dictionary<string, IList>(original.variableValues); … … 118 118 } 119 119 120 protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { } 121 120 122 #region Backwards compatible code, remove with 3.5 121 123 private double[,] storableData; … … 143 145 144 146 [Storable(Name = "VariableValues")] 145 pr ivateDictionary<string, IList> variableValues;146 147 pr ivateList<string> variableNames;147 protected Dictionary<string, IList> variableValues; 148 149 protected List<string> variableNames; 148 150 [Storable] 149 151 public IEnumerable<string> VariableNames { 150 152 get { return variableNames; } 151 pr ivateset {153 protected set { 152 154 if (variableNames != null) throw new InvalidOperationException(); 153 155 variableNames = new List<string>(value); 154 156 } 155 157 } 156 157 158 public IEnumerable<string> DoubleVariables { 158 159 get { return variableValues.Where(p => p.Value is List<double>).Select(p => p.Key); } 159 160 } 160 161 161 public IEnumerable<double> GetDoubleValues(string variableName) { 162 return GetValues<double>(variableName); 163 } 164 public IEnumerable<string> GetStringValues(string variableName) { 165 return GetValues<string>(variableName); 166 } 167 public IEnumerable<DateTime> GetDateTimeValues(string variableName) { 168 return GetValues<DateTime>(variableName); 169 } 170 171 public ReadOnlyCollection<double> GetReadOnlyDoubleValues(string variableName) { 172 var values = GetValues<double>(variableName); 173 return values.AsReadOnly(); 174 } 175 public double GetDoubleValue(string variableName, int row) { 176 var values = GetValues<double>(variableName); 177 return values[row]; 178 } 179 public IEnumerable<double> GetDoubleValues(string variableName, IEnumerable<int> rows) { 180 return GetValues<double>(variableName, rows); 181 } 182 private IEnumerable<T> GetValues<T>(string variableName, IEnumerable<int> rows) { 183 var values = GetValues<T>(variableName); 184 return rows.Select(x => values[x]); 185 } 186 private List<T> GetValues<T>(string variableName) { 162 187 IList list; 163 188 if (!variableValues.TryGetValue(variableName, out list)) 164 189 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 165 List<double> values = list as List<double>; 166 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable."); 167 168 //mkommend yield return used to enable lazy evaluation 169 foreach (double value in values) 170 yield return value; 171 } 172 173 public IEnumerable<string> GetStringValues(string variableName) { 174 IList list; 175 if (!variableValues.TryGetValue(variableName, out list)) 176 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 177 List<string> values = list as List<string>; 178 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a string variable."); 179 180 //mkommend yield return used to enable lazy evaluation 181 foreach (string value in values) 182 yield return value; 183 } 184 185 public IEnumerable<DateTime> GetDateTimeValues(string variableName) { 186 IList list; 187 if (!variableValues.TryGetValue(variableName, out list)) 188 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 189 List<DateTime> values = list as List<DateTime>; 190 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a datetime variable."); 191 192 //mkommend yield return used to enable lazy evaluation 193 foreach (DateTime value in values) 194 yield return value; 195 } 196 197 public ReadOnlyCollection<double> GetReadOnlyDoubleValues(string variableName) { 198 IList list; 199 if (!variableValues.TryGetValue(variableName, out list)) 200 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 201 List<double> values = list as List<double>; 202 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable."); 203 return values.AsReadOnly(); 204 } 205 public double GetDoubleValue(string variableName, int row) { 206 IList list; 207 if (!variableValues.TryGetValue(variableName, out list)) 208 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 209 List<double> values = list as List<double>; 210 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable."); 211 return values[row]; 212 } 213 public IEnumerable<double> GetDoubleValues(string variableName, IEnumerable<int> rows) { 214 IList list; 215 if (!variableValues.TryGetValue(variableName, out list)) 216 throw new ArgumentException("The variable " + variableName + " does not exist in the dataset."); 217 List<double> values = list as List<double>; 218 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable."); 219 220 return rows.Select(index => values[index]); 221 } 222 190 List<T> values = list as List<T>; 191 if (values == null) throw new ArgumentException("The variable " + variableName + " is not a " + typeof(T) + " variable."); 192 return values; 193 } 223 194 public bool VariableHasType<T>(string variableName) { 224 195 return variableValues[variableName] is IList<T>; … … 227 198 #region IStringConvertibleMatrix Members 228 199 [Storable] 229 pr ivateint rows;200 protected int rows; 230 201 public int Rows { 231 202 get { return rows; } … … 236 207 set { throw new NotSupportedException(); } 237 208 } 238 239 209 public bool SortableView { 240 210 get { return false; } … … 244 214 get { return true; } 245 215 } 246 247 216 IEnumerable<string> IStringConvertibleMatrix.ColumnNames { 248 217 get { return this.VariableNames; } … … 253 222 set { throw new NotSupportedException(); } 254 223 } 255 256 224 public string GetValue(int rowIndex, int columnIndex) { 257 225 return variableValues[variableNames[columnIndex]][rowIndex].ToString(); 258 226 } 259 public boolSetValue(string value, int rowIndex, int columnIndex) {227 bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) { 260 228 throw new NotSupportedException(); 261 229 } 262 public boolValidate(string value, out string errorMessage) {230 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) { 263 231 throw new NotSupportedException(); 264 232 } 265 233 266 public event EventHandler ColumnsChanged { add { } remove { } }267 public event EventHandler RowsChanged { add { } remove { } }268 public event EventHandler ColumnNamesChanged { add { } remove { } }269 public event EventHandler RowNamesChanged { add { } remove { } }270 public event EventHandler SortableViewChanged { add { } remove { } }271 public event EventHandler<EventArgs<int, int>> ItemChanged { add { } remove { } }272 public event EventHandler Reset { add { } remove { } }234 public virtual event EventHandler ColumnsChanged { add { } remove { } } 235 public virtual event EventHandler RowsChanged { add { } remove { } } 236 public virtual event EventHandler ColumnNamesChanged { add { } remove { } } 237 public virtual event EventHandler RowNamesChanged { add { } remove { } } 238 public virtual event EventHandler SortableViewChanged { add { } remove { } } 239 public virtual event EventHandler<EventArgs<int, int>> ItemChanged { add { } remove { } } 240 public virtual event EventHandler Reset { add { } remove { } } 273 241 #endregion 274 242 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r11763 r12515 165 165 <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" /> 166 166 <Compile Include="Interfaces\IDataAnalysisSolutionExporter.cs" /> 167 <Compile Include="Interfaces\IDataset.cs" /> 167 168 <Compile Include="Interfaces\IDependencyCalculator.cs" /> 168 169 <Compile Include="Interfaces\ITransformation.cs" /> … … 178 179 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblemData.cs" /> 179 180 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" /> 181 <Compile Include="ModifiableDataset.cs" /> 180 182 <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" /> 181 183 <Compile Include="OnlineCalculators\ClassificationPerformanceMeasuresCalculator.cs" /> … … 222 224 <Compile Include="OnlineCalculators\OnlineMeanSquaredErrorCalculator.cs" /> 223 225 <Compile Include="OnlineCalculators\OnlineNormalizedMeanSquaredErrorCalculator.cs" /> 226 <Compile Include="OnlineCalculators\OnlinePearsonsRCalculator.cs" /> 224 227 <Compile Include="OnlineCalculators\OnlinePearsonsRSquaredCalculator.cs" /> 225 228 <Compile Include="Implementation\Regression\RegressionSolution.cs" /> -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r12012 r12515 67 67 } 68 68 69 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors( Dataset dataset, IEnumerable<int> rows) {69 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows) { 70 70 var estimatedValuesEnumerators = (from model in models 71 71 select model.GetEstimatedClassValues(dataset, rows).GetEnumerator()) … … 82 82 #region IClassificationModel Members 83 83 84 public IEnumerable<double> GetEstimatedClassValues( Dataset dataset, IEnumerable<int> rows) {84 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 85 85 foreach (var estimatedValuesVector in GetEstimatedClassValueVectors(dataset, rows)) { 86 86 // return the class which is most often occuring -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r12012 r12515 35 35 [StorableClass] 36 36 [Item("Classification Ensemble Solution", "A classification solution that contains an ensemble of multiple classification models")] 37 [Creatable( "Data Analysis - Ensembles")]37 [Creatable(CreatableAttribute.Categories.DataAnalysisEnsembles, Priority = 110)] 38 38 public sealed class ClassificationEnsembleSolution : ClassificationSolutionBase, IClassificationEnsembleSolution { 39 39 private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>(); … … 231 231 } 232 232 233 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors( Dataset dataset, IEnumerable<int> rows) {233 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows) { 234 234 if (!Model.Models.Any()) yield break; 235 235 var estimatedValuesEnumerators = (from model in Model.Models -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs
r12012 r12515 27 27 [StorableClass] 28 28 [Item("Classification Problem", "A general classification problem.")] 29 [Creatable("Problems")]30 29 public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent { 31 30 public string Filename { get; set; } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r12067 r12515 324 324 } 325 325 326 public ClassificationProblemData( Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)326 public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 327 327 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 328 328 var validTargetVariableValues = CheckVariablesForPossibleTargetVariables(dataset).Select(x => new StringValue(x).AsReadOnly()).ToList(); … … 338 338 } 339 339 340 public static IEnumerable<string> CheckVariablesForPossibleTargetVariables( Dataset dataset) {340 public static IEnumerable<string> CheckVariablesForPossibleTargetVariables(IDataset dataset) { 341 341 int maxSamples = Math.Min(InspectedRowsToDetermineTargets, dataset.Rows); 342 342 var validTargetVariables = (from v in dataset.DoubleVariables -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs
r12012 r12515 30 30 /// </summary> 31 31 [StorableClass] 32 public abstractclass ClassificationSolution : ClassificationSolutionBase {32 public class ClassificationSolution : ClassificationSolutionBase { 33 33 protected readonly Dictionary<int, double> evaluationCache; 34 34 … … 46 46 evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows); 47 47 CalculateClassificationResults(); 48 } 49 50 public override IDeepCloneable Clone(Cloner cloner) { 51 return new ClassificationSolution(this, cloner); 48 52 } 49 53 -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs
r12012 r12515 111 111 112 112 113 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {113 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 114 114 return model.GetEstimatedValues(dataset, rows); 115 115 } 116 116 117 public IEnumerable<double> GetEstimatedClassValues( Dataset dataset, IEnumerable<int> rows) {117 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 118 118 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model."); 119 119 foreach (var x in GetEstimatedValues(dataset, rows)) { -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Clustering/ClusteringProblem.cs
r12012 r12515 27 27 [StorableClass] 28 28 [Item("Clustering Problem", "A general clustering problem.")] 29 [Creatable("Problems")]30 29 public class ClusteringProblem : DataAnalysisProblem<IClusteringProblemData>, IClusteringProblem { 31 30 [StorableConstructor] -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r12012 r12515 63 63 get { return isEmpty; } 64 64 } 65 public Dataset Dataset {65 public IDataset Dataset { 66 66 get { return DatasetParameter.Value; } 67 67 } … … 126 126 } 127 127 128 protected DataAnalysisProblemData( Dataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<ITransformation> transformations = null) {128 protected DataAnalysisProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<ITransformation> transformations = null) { 129 129 if (dataset == null) throw new ArgumentNullException("The dataset must not be null."); 130 130 if (allowedInputVariables == null) throw new ArgumentNullException("The allowedInputVariables must not be null."); … … 144 144 var transformationsList = new ItemList<ITransformation>(transformations ?? Enumerable.Empty<ITransformation>()); 145 145 146 Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", dataset));146 Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", (Dataset)dataset)); 147 147 Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, "", inputVariables.AsReadOnly())); 148 148 Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", new IntRange(trainingPartitionStart, trainingPartitionEnd))); -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r12012 r12515 51 51 } 52 52 53 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {53 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 54 54 return rows.Select(row => Constant); 55 55 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r12012 r12515 80 80 } 81 81 82 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors( Dataset dataset, IEnumerable<int> rows) {82 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows) { 83 83 var estimatedValuesEnumerators = (from model in models 84 84 select model.GetEstimatedValues(dataset, rows).GetEnumerator()) … … 95 95 #region IRegressionModel Members 96 96 97 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {97 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 98 98 foreach (var estimatedValuesVector in GetEstimatedValueVectors(dataset, rows)) { 99 99 yield return estimatedValuesVector.Average(); -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r12012 r12515 35 35 [StorableClass] 36 36 [Item("Regression Ensemble Solution", "A regression solution that contains an ensemble of multiple regression models")] 37 [Creatable( "Data Analysis - Ensembles")]37 [Creatable(CreatableAttribute.Categories.DataAnalysisEnsembles, Priority = 100)] 38 38 public sealed class RegressionEnsembleSolution : RegressionSolutionBase, IRegressionEnsembleSolution { 39 39 private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>(); … … 232 232 } 233 233 234 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors( Dataset dataset, IEnumerable<int> rows) {234 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows) { 235 235 if (!Model.Models.Any()) yield break; 236 236 var estimatedValuesEnumerators = (from model in Model.Models -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs
r12012 r12515 27 27 [StorableClass] 28 28 [Item("Regression Problem", "A general regression problem.")] 29 [Creatable("Problems")]30 29 public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent { 31 30 public string Filename { get; set; } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r12012 r12515 137 137 } 138 138 139 public RegressionProblemData( Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)139 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 140 140 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 141 141 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs
r12012 r12515 30 30 /// </summary> 31 31 [StorableClass] 32 public abstractclass RegressionSolution : RegressionSolutionBase {32 public class RegressionSolution : RegressionSolutionBase { 33 33 protected readonly Dictionary<int, double> evaluationCache; 34 34 … … 42 42 evaluationCache = new Dictionary<int, double>(original.evaluationCache); 43 43 } 44 p rotectedRegressionSolution(IRegressionModel model, IRegressionProblemData problemData)44 public RegressionSolution(IRegressionModel model, IRegressionProblemData problemData) 45 45 : base(model, problemData) { 46 46 evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows); … … 48 48 } 49 49 50 public override IDeepCloneable Clone(Cloner cloner) { 51 return new RegressionSolution(this, cloner); 52 } 50 53 51 54 public override IEnumerable<double> EstimatedValues { … … 60 63 61 64 public override IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 62 var rowsToEvaluate = rows. Except(evaluationCache.Keys);65 var rowsToEvaluate = rows.Where(row => !evaluationCache.ContainsKey(row)); 63 66 var rowsEnumerator = rowsToEvaluate.GetEnumerator(); 64 67 var valuesEnumerator = Model.GetEstimatedValues(ProblemData.Dataset, rowsToEvaluate).GetEnumerator(); -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/ConstantTimeSeriesPrognosisModel.cs
r12012 r12515 39 39 public ConstantTimeSeriesPrognosisModel(double constant) : base(constant) { } 40 40 41 public IEnumerable<IEnumerable<double>> GetPrognosedValues( Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {41 public IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { 42 42 return horizons.Select(horizon => Enumerable.Repeat(Constant, horizon)); 43 43 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r12012 r12515 58 58 } 59 59 60 public IEnumerable<IEnumerable<double>> GetPrognosedValues( Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {60 public IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { 61 61 var rowsEnumerator = rows.GetEnumerator(); 62 62 var horizonsEnumerator = horizons.GetEnumerator(); … … 91 91 } 92 92 93 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {93 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 94 94 var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable); 95 95 foreach (int row in rows) { -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblem.cs
r12012 r12515 27 27 [StorableClass] 28 28 [Item("Time-series Prognosis Problem", "A general time-series prognosis problem.")] 29 [Creatable("Problems")]30 29 public class TimeSeriesPrognosisProblem : DataAnalysisProblem<ITimeSeriesPrognosisProblemData>, ITimeSeriesPrognosisProblem { 31 30 [StorableConstructor] -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs
r12012 r12515 1582 1582 TrainingPartition.Start = 50; 1583 1583 } 1584 public TimeSeriesPrognosisProblemData( Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)1584 public TimeSeriesPrognosisProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 1585 1585 : base(dataset, allowedInputVariables, targetVariable, transformations ?? Enumerable.Empty<ITransformation>()) { 1586 1586 Parameters.Add(new FixedValueParameter<IntValue>(TrainingHorizonParameterName, "Specifies the horizon (how far the prognosis reaches in the future) for each training sample.", new IntValue(1))); -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationEnsembleModel.cs
r12012 r12515 26 26 void Remove(IClassificationModel model); 27 27 IEnumerable<IClassificationModel> Models { get; } 28 IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors( Dataset dataset, IEnumerable<int> rows);28 IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows); 29 29 } 30 30 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationEnsembleSolution.cs
r12012 r12515 26 26 new IClassificationEnsembleModel Model { get; } 27 27 IItemCollection<IClassificationSolution> ClassificationSolutions { get; } 28 IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors( Dataset dataset, IEnumerable<int> rows);28 IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows); 29 29 } 30 30 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs
r12012 r12515 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 24 public interface IClassificationModel : IDataAnalysisModel { 25 IEnumerable<double> GetEstimatedClassValues( Dataset dataset, IEnumerable<int> rows);25 IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows); 26 26 IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData); 27 27 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs
r12012 r12515 30 30 // class values and thresholds can only be assigned simultanously 31 31 void SetThresholdsAndClassValues(IEnumerable<double> thresholds, IEnumerable<double> classValues); 32 IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows);32 IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows); 33 33 34 34 event EventHandler ThresholdsChanged; -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Clustering/IClusteringModel.cs
r12012 r12515 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 24 public interface IClusteringModel : IDataAnalysisModel { 25 IEnumerable<int> GetClusterValues( Dataset dataset, IEnumerable<int> rows);25 IEnumerable<int> GetClusterValues(IDataset dataset, IEnumerable<int> rows); 26 26 } 27 27 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
r12012 r12515 29 29 bool IsEmpty { get; } 30 30 31 Dataset Dataset { get; }31 IDataset Dataset { get; } 32 32 ICheckedItemList<StringValue> InputVariables { get; } 33 33 IEnumerable<string> AllowedInputVariables { get; } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionEnsembleModel.cs
r12012 r12515 26 26 void Remove(IRegressionModel model); 27 27 IEnumerable<IRegressionModel> Models { get; } 28 IEnumerable<IEnumerable<double>> GetEstimatedValueVectors( Dataset dataset, IEnumerable<int> rows);28 IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows); 29 29 } 30 30 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionEnsembleSolution.cs
r12012 r12515 27 27 new RegressionEnsembleProblemData ProblemData { get; set; } 28 28 IItemCollection<IRegressionSolution> RegressionSolutions { get; } 29 IEnumerable<IEnumerable<double>> GetEstimatedValueVectors( Dataset dataset, IEnumerable<int> rows);29 IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows); 30 30 } 31 31 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs
r12012 r12515 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 24 public interface IRegressionModel : IDataAnalysisModel { 25 IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows);25 IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows); 26 26 IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData); 27 27 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisModel.cs
r12012 r12515 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 24 public interface ITimeSeriesPrognosisModel : IRegressionModel { 25 IEnumerable<IEnumerable<double>> GetPrognosedValues( Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons);25 IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons); 26 26 ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData); 27 27 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs
r12012 r12515 33 33 34 34 public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { 35 return Math.Sqrt(OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState));35 return OnlinePearsonsRCalculator.Calculate(originalValues, estimatedValues, out errorState); 36 36 } 37 37 } -
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs
r12012 r12515 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 [Obsolete("Use OnlinePearsonsRCalculator directly")] 27 28 public class OnlinePearsonsRSquaredCalculator : IOnlineCalculator { 28 private OnlineCovarianceCalculator covCalculator = new OnlineCovarianceCalculator(); 29 private OnlineMeanAndVarianceCalculator sxCalculator = new OnlineMeanAndVarianceCalculator(); 30 private OnlineMeanAndVarianceCalculator syCalculator = new OnlineMeanAndVarianceCalculator(); 29 private readonly OnlinePearsonsRCalculator rCalculator = new OnlinePearsonsRCalculator(); 31 30 32 31 public double RSquared { 33 32 get { 34 double xVar = sxCalculator.PopulationVariance; 35 double yVar = syCalculator.PopulationVariance; 36 if (xVar.IsAlmost(0.0) || yVar.IsAlmost(0.0)) { 37 return 0.0; 38 } else { 39 double r = covCalculator.Covariance / (Math.Sqrt(xVar) * Math.Sqrt(yVar)); 40 return r * r; 41 } 33 if (rCalculator.ErrorState != OnlineCalculatorError.None) return 0.0; 34 else return rCalculator.R * rCalculator.R; 42 35 } 43 36 } … … 47 40 #region IOnlineCalculator Members 48 41 public OnlineCalculatorError ErrorState { 49 get { return covCalculator.ErrorState | sxCalculator.PopulationVarianceErrorState | syCalculator.PopulationVarianceErrorState; }42 get { return rCalculator.ErrorState; } 50 43 } 51 44 public double Value { … … 53 46 } 54 47 public void Reset() { 55 covCalculator.Reset(); 56 sxCalculator.Reset(); 57 syCalculator.Reset(); 48 rCalculator.Reset(); 58 49 } 59 50 60 51 public void Add(double x, double y) { 61 // no need to check validity of values explicitly here as it is checked in all three evaluators 62 covCalculator.Add(x, y); 63 sxCalculator.Add(x); 64 syCalculator.Add(y); 52 rCalculator.Add(x, y); 65 53 } 66 54 … … 68 56 69 57 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 70 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 71 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 72 OnlinePearsonsRSquaredCalculator rSquaredCalculator = new OnlinePearsonsRSquaredCalculator(); 73 74 // always move forward both enumerators (do not use short-circuit evaluation!) 75 while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) { 76 double original = firstEnumerator.Current; 77 double estimated = secondEnumerator.Current; 78 rSquaredCalculator.Add(original, estimated); 79 if (rSquaredCalculator.ErrorState != OnlineCalculatorError.None) break; 80 } 81 82 // check if both enumerators are at the end to make sure both enumerations have the same length 83 if (rSquaredCalculator.ErrorState == OnlineCalculatorError.None && 84 (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) { 85 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 86 } else { 87 errorState = rSquaredCalculator.ErrorState; 88 return rSquaredCalculator.RSquared; 89 } 58 var r = OnlinePearsonsRCalculator.Calculate(first, second, out errorState); 59 return r * r; 90 60 } 91 61 }
Note: See TracChangeset
for help on using the changeset viewer.