Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/25/15 18:21:19 (10 years ago)
Author:
dglaser
Message:

#2388: Merged trunk into HiveStatistics branch

Location:
branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis
Files:
33 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis

  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r12012 r12515  
    3333  [Item("Dataset", "Represents a dataset containing data that should be analyzed.")]
    3434  [StorableClass]
    35   public sealed class Dataset : NamedItem, IStringConvertibleMatrix {
     35  public class Dataset : NamedItem, IDataset {
    3636    [StorableConstructor]
    37     private Dataset(bool deserializing) : base(deserializing) { }
    38     private Dataset(Dataset original, Cloner cloner)
     37    protected Dataset(bool deserializing) : base(deserializing) { }
     38    protected Dataset(Dataset original, Cloner cloner)
    3939      : base(original, cloner) {
    4040      variableValues = new Dictionary<string, IList>(original.variableValues);
     
    118118    }
    119119
     120    protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { }
     121
    120122    #region Backwards compatible code, remove with 3.5
    121123    private double[,] storableData;
     
    143145
    144146    [Storable(Name = "VariableValues")]
    145     private Dictionary<string, IList> variableValues;
    146 
    147     private List<string> variableNames;
     147    protected Dictionary<string, IList> variableValues;
     148
     149    protected List<string> variableNames;
    148150    [Storable]
    149151    public IEnumerable<string> VariableNames {
    150152      get { return variableNames; }
    151       private set {
     153      protected set {
    152154        if (variableNames != null) throw new InvalidOperationException();
    153155        variableNames = new List<string>(value);
    154156      }
    155157    }
    156 
    157158    public IEnumerable<string> DoubleVariables {
    158159      get { return variableValues.Where(p => p.Value is List<double>).Select(p => p.Key); }
    159160    }
    160 
    161161    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) {
    162187      IList list;
    163188      if (!variableValues.TryGetValue(variableName, out list))
    164189        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    }
    223194    public bool VariableHasType<T>(string variableName) {
    224195      return variableValues[variableName] is IList<T>;
     
    227198    #region IStringConvertibleMatrix Members
    228199    [Storable]
    229     private int rows;
     200    protected int rows;
    230201    public int Rows {
    231202      get { return rows; }
     
    236207      set { throw new NotSupportedException(); }
    237208    }
    238 
    239209    public bool SortableView {
    240210      get { return false; }
     
    244214      get { return true; }
    245215    }
    246 
    247216    IEnumerable<string> IStringConvertibleMatrix.ColumnNames {
    248217      get { return this.VariableNames; }
     
    253222      set { throw new NotSupportedException(); }
    254223    }
    255 
    256224    public string GetValue(int rowIndex, int columnIndex) {
    257225      return variableValues[variableNames[columnIndex]][rowIndex].ToString();
    258226    }
    259     public bool SetValue(string value, int rowIndex, int columnIndex) {
     227    bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) {
    260228      throw new NotSupportedException();
    261229    }
    262     public bool Validate(string value, out string errorMessage) {
     230    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
    263231      throw new NotSupportedException();
    264232    }
    265233
    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 { } }
    273241    #endregion
    274242  }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r11763 r12515  
    165165    <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" />
    166166    <Compile Include="Interfaces\IDataAnalysisSolutionExporter.cs" />
     167    <Compile Include="Interfaces\IDataset.cs" />
    167168    <Compile Include="Interfaces\IDependencyCalculator.cs" />
    168169    <Compile Include="Interfaces\ITransformation.cs" />
     
    178179    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblemData.cs" />
    179180    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" />
     181    <Compile Include="ModifiableDataset.cs" />
    180182    <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" />
    181183    <Compile Include="OnlineCalculators\ClassificationPerformanceMeasuresCalculator.cs" />
     
    222224    <Compile Include="OnlineCalculators\OnlineMeanSquaredErrorCalculator.cs" />
    223225    <Compile Include="OnlineCalculators\OnlineNormalizedMeanSquaredErrorCalculator.cs" />
     226    <Compile Include="OnlineCalculators\OnlinePearsonsRCalculator.cs" />
    224227    <Compile Include="OnlineCalculators\OnlinePearsonsRSquaredCalculator.cs" />
    225228    <Compile Include="Implementation\Regression\RegressionSolution.cs" />
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r12012 r12515  
    6767    }
    6868
    69     public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows) {
     69    public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows) {
    7070      var estimatedValuesEnumerators = (from model in models
    7171                                        select model.GetEstimatedClassValues(dataset, rows).GetEnumerator())
     
    8282    #region IClassificationModel Members
    8383
    84     public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) {
     84    public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    8585      foreach (var estimatedValuesVector in GetEstimatedClassValueVectors(dataset, rows)) {
    8686        // return the class which is most often occuring
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r12012 r12515  
    3535  [StorableClass]
    3636  [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)]
    3838  public sealed class ClassificationEnsembleSolution : ClassificationSolutionBase, IClassificationEnsembleSolution {
    3939    private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>();
     
    231231    }
    232232
    233     public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows) {
     233    public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows) {
    234234      if (!Model.Models.Any()) yield break;
    235235      var estimatedValuesEnumerators = (from model in Model.Models
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs

    r12012 r12515  
    2727  [StorableClass]
    2828  [Item("Classification Problem", "A general classification problem.")]
    29   [Creatable("Problems")]
    3029  public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent {
    3130    public string Filename { get; set; }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r12067 r12515  
    324324    }
    325325
    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)
    327327      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    328328      var validTargetVariableValues = CheckVariablesForPossibleTargetVariables(dataset).Select(x => new StringValue(x).AsReadOnly()).ToList();
     
    338338    }
    339339
    340     public static IEnumerable<string> CheckVariablesForPossibleTargetVariables(Dataset dataset) {
     340    public static IEnumerable<string> CheckVariablesForPossibleTargetVariables(IDataset dataset) {
    341341      int maxSamples = Math.Min(InspectedRowsToDetermineTargets, dataset.Rows);
    342342      var validTargetVariables = (from v in dataset.DoubleVariables
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs

    r12012 r12515  
    3030  /// </summary>
    3131  [StorableClass]
    32   public abstract class ClassificationSolution : ClassificationSolutionBase {
     32  public class ClassificationSolution : ClassificationSolutionBase {
    3333    protected readonly Dictionary<int, double> evaluationCache;
    3434
     
    4646      evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows);
    4747      CalculateClassificationResults();
     48    }
     49
     50    public override IDeepCloneable Clone(Cloner cloner) {
     51      return new ClassificationSolution(this, cloner);
    4852    }
    4953
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r12012 r12515  
    111111
    112112
    113     public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
     113    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    114114      return model.GetEstimatedValues(dataset, rows);
    115115    }
    116116
    117     public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) {
     117    public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    118118      if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model.");
    119119      foreach (var x in GetEstimatedValues(dataset, rows)) {
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Clustering/ClusteringProblem.cs

    r12012 r12515  
    2727  [StorableClass]
    2828  [Item("Clustering Problem", "A general clustering problem.")]
    29   [Creatable("Problems")]
    3029  public class ClusteringProblem : DataAnalysisProblem<IClusteringProblemData>, IClusteringProblem {
    3130    [StorableConstructor]
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r12012 r12515  
    6363      get { return isEmpty; }
    6464    }
    65     public Dataset Dataset {
     65    public IDataset Dataset {
    6666      get { return DatasetParameter.Value; }
    6767    }
     
    126126    }
    127127
    128     protected DataAnalysisProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<ITransformation> transformations = null) {
     128    protected DataAnalysisProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<ITransformation> transformations = null) {
    129129      if (dataset == null) throw new ArgumentNullException("The dataset must not be null.");
    130130      if (allowedInputVariables == null) throw new ArgumentNullException("The allowedInputVariables must not be null.");
     
    144144      var transformationsList = new ItemList<ITransformation>(transformations ?? Enumerable.Empty<ITransformation>());
    145145
    146       Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", dataset));
     146      Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", (Dataset)dataset));
    147147      Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, "", inputVariables.AsReadOnly()));
    148148      Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", new IntRange(trainingPartitionStart, trainingPartitionEnd)));
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs

    r12012 r12515  
    5151    }
    5252
    53     public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
     53    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    5454      return rows.Select(row => Constant);
    5555    }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r12012 r12515  
    8080    }
    8181
    82     public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows) {
     82    public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows) {
    8383      var estimatedValuesEnumerators = (from model in models
    8484                                        select model.GetEstimatedValues(dataset, rows).GetEnumerator())
     
    9595    #region IRegressionModel Members
    9696
    97     public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
     97    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    9898      foreach (var estimatedValuesVector in GetEstimatedValueVectors(dataset, rows)) {
    9999        yield return estimatedValuesVector.Average();
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r12012 r12515  
    3535  [StorableClass]
    3636  [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)]
    3838  public sealed class RegressionEnsembleSolution : RegressionSolutionBase, IRegressionEnsembleSolution {
    3939    private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>();
     
    232232    }
    233233
    234     public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows) {
     234    public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows) {
    235235      if (!Model.Models.Any()) yield break;
    236236      var estimatedValuesEnumerators = (from model in Model.Models
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs

    r12012 r12515  
    2727  [StorableClass]
    2828  [Item("Regression Problem", "A general regression problem.")]
    29   [Creatable("Problems")]
    3029  public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent {
    3130    public string Filename { get; set; }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r12012 r12515  
    137137    }
    138138
    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)
    140140      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    141141      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs

    r12012 r12515  
    3030  /// </summary>
    3131  [StorableClass]
    32   public abstract class RegressionSolution : RegressionSolutionBase {
     32  public class RegressionSolution : RegressionSolutionBase {
    3333    protected readonly Dictionary<int, double> evaluationCache;
    3434
     
    4242      evaluationCache = new Dictionary<int, double>(original.evaluationCache);
    4343    }
    44     protected RegressionSolution(IRegressionModel model, IRegressionProblemData problemData)
     44    public RegressionSolution(IRegressionModel model, IRegressionProblemData problemData)
    4545      : base(model, problemData) {
    4646      evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows);
     
    4848    }
    4949
     50    public override IDeepCloneable Clone(Cloner cloner) {
     51      return new RegressionSolution(this, cloner);
     52    }
    5053
    5154    public override IEnumerable<double> EstimatedValues {
     
    6063
    6164    public override IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) {
    62       var rowsToEvaluate = rows.Except(evaluationCache.Keys);
     65      var rowsToEvaluate = rows.Where(row => !evaluationCache.ContainsKey(row));
    6366      var rowsEnumerator = rowsToEvaluate.GetEnumerator();
    6467      var valuesEnumerator = Model.GetEstimatedValues(ProblemData.Dataset, rowsToEvaluate).GetEnumerator();
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/ConstantTimeSeriesPrognosisModel.cs

    r12012 r12515  
    3939    public ConstantTimeSeriesPrognosisModel(double constant) : base(constant) { }
    4040
    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) {
    4242      return horizons.Select(horizon => Enumerable.Repeat(Constant, horizon));
    4343    }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs

    r12012 r12515  
    5858    }
    5959
    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) {
    6161      var rowsEnumerator = rows.GetEnumerator();
    6262      var horizonsEnumerator = horizons.GetEnumerator();
     
    9191    }
    9292
    93     public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
     93    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    9494      var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable);
    9595      foreach (int row in rows) {
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblem.cs

    r12012 r12515  
    2727  [StorableClass]
    2828  [Item("Time-series Prognosis Problem", "A general time-series prognosis problem.")]
    29   [Creatable("Problems")]
    3029  public class TimeSeriesPrognosisProblem : DataAnalysisProblem<ITimeSeriesPrognosisProblemData>, ITimeSeriesPrognosisProblem {
    3130    [StorableConstructor]
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs

    r12012 r12515  
    15821582      TrainingPartition.Start = 50;
    15831583    }
    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)
    15851585      : base(dataset, allowedInputVariables, targetVariable, transformations ?? Enumerable.Empty<ITransformation>()) {
    15861586      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  
    2626    void Remove(IClassificationModel model);
    2727    IEnumerable<IClassificationModel> Models { get; }
    28     IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows);
     28    IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows);
    2929  }
    3030}
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationEnsembleSolution.cs

    r12012 r12515  
    2626    new IClassificationEnsembleModel Model { get; }
    2727    IItemCollection<IClassificationSolution> ClassificationSolutions { get; }
    28     IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows);
     28    IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows);
    2929  }
    3030}
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs

    r12012 r12515  
    2323namespace HeuristicLab.Problems.DataAnalysis {
    2424  public interface IClassificationModel : IDataAnalysisModel {
    25     IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows);
     25    IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows);
    2626    IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData);
    2727  }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs

    r12012 r12515  
    3030    // class values and thresholds can only be assigned simultanously
    3131    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);
    3333
    3434    event EventHandler ThresholdsChanged;
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Clustering/IClusteringModel.cs

    r12012 r12515  
    2323namespace HeuristicLab.Problems.DataAnalysis {
    2424  public interface IClusteringModel : IDataAnalysisModel {
    25     IEnumerable<int> GetClusterValues(Dataset dataset, IEnumerable<int> rows);
     25    IEnumerable<int> GetClusterValues(IDataset dataset, IEnumerable<int> rows);
    2626  }
    2727}
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs

    r12012 r12515  
    2929    bool IsEmpty { get; }
    3030
    31     Dataset Dataset { get; }
     31    IDataset Dataset { get; }
    3232    ICheckedItemList<StringValue> InputVariables { get; }
    3333    IEnumerable<string> AllowedInputVariables { get; }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionEnsembleModel.cs

    r12012 r12515  
    2626    void Remove(IRegressionModel model);
    2727    IEnumerable<IRegressionModel> Models { get; }
    28     IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows);
     28    IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows);
    2929  }
    3030}
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionEnsembleSolution.cs

    r12012 r12515  
    2727    new RegressionEnsembleProblemData ProblemData { get; set; }
    2828    IItemCollection<IRegressionSolution> RegressionSolutions { get; }
    29     IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows);
     29    IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows);
    3030  }
    3131}
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs

    r12012 r12515  
    2323namespace HeuristicLab.Problems.DataAnalysis {
    2424  public interface IRegressionModel : IDataAnalysisModel {
    25     IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows);
     25    IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows);
    2626    IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData);
    2727  }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisModel.cs

    r12012 r12515  
    2323namespace HeuristicLab.Problems.DataAnalysis {
    2424  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);
    2626    ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData);
    2727  }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs

    r12012 r12515  
    3333
    3434    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);
    3636    }
    3737  }
  • branches/HiveStatistics/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs

    r12012 r12515  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
     27  [Obsolete("Use OnlinePearsonsRCalculator directly")]
    2728  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();
    3130
    3231    public double RSquared {
    3332      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;
    4235      }
    4336    }
     
    4740    #region IOnlineCalculator Members
    4841    public OnlineCalculatorError ErrorState {
    49       get { return covCalculator.ErrorState | sxCalculator.PopulationVarianceErrorState | syCalculator.PopulationVarianceErrorState; }
     42      get { return rCalculator.ErrorState; }
    5043    }
    5144    public double Value {
     
    5346    }
    5447    public void Reset() {
    55       covCalculator.Reset();
    56       sxCalculator.Reset();
    57       syCalculator.Reset();
     48      rCalculator.Reset();
    5849    }
    5950
    6051    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);
    6553    }
    6654
     
    6856
    6957    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;
    9060    }
    9161  }
Note: See TracChangeset for help on using the changeset viewer.