Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/13 13:13:41 (11 years ago)
Author:
spimming
Message:

#1888:

  • Merged revisions from trunk
Location:
branches/OaaS
Files:
1 deleted
27 edited
10 copied

Legend:

Unmodified
Added
Removed
  • branches/OaaS

  • branches/OaaS/HeuristicLab.Problems.DataAnalysis

  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r7921 r9363  
    191191        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
    192192      List<double> values = list as List<double>;
    193       if (values == null) throw new ArgumentException("The varialbe " + variableName + " is not a double variable.");
    194 
    195       foreach (int index in rows)
    196         yield return values[index];
     193      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a double variable.");
     194
     195      return rows.Select(index => values[index]);
    197196    }
    198197
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r7969 r9363  
    9393  </PropertyGroup>
    9494  <ItemGroup>
     95    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     96      <HintPath>..\..\bin\ALGLIB-3.7.0.dll</HintPath>
     97      <Private>False</Private>
     98    </Reference>
     99    <Reference Include="HeuristicLab.ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     100      <HintPath>..\..\bin\HeuristicLab.ALGLIB-3.6.0.dll</HintPath>
     101      <Private>False</Private>
     102    </Reference>
    95103    <Reference Include="System" />
    96104    <Reference Include="System.Core">
     
    108116  </ItemGroup>
    109117  <ItemGroup>
     118    <Compile Include="DatasetExtensions.cs" />
    110119    <Compile Include="DoubleLimit.cs" />
    111120    <Compile Include="Implementation\Classification\ClassificationEnsembleModel.cs">
     
    129138    </Compile>
    130139    <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" />
     140    <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" />
     141    <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisAutoRegressiveModel.cs" />
     142    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblem.cs" />
     143    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblemData.cs" />
     144    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisResults.cs" />
     145    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisSolution.cs" />
     146    <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisSolutionBase.cs" />
    131147    <Compile Include="Interfaces\Classification\IClassificationEnsembleModel.cs">
    132148      <SubType>Code</SubType>
     
    136152    </Compile>
    137153    <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" />
     154    <Compile Include="Interfaces\IDependencyCalculator.cs" />
    138155    <Compile Include="Interfaces\Regression\IRegressionEnsembleModel.cs">
    139156      <SubType>Code</SubType>
     
    141158    <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" />
    142159    <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" />
    143     <Compile Include="OnlineCalculators\HoeffdingsDependenceCalculator.cs" />
     160    <Compile Include="Interfaces\TimeSeriesPrognosis\IOnlineTimeSeriesCalculator.cs" />
     161    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisModel.cs" />
     162    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblem.cs" />
     163    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblemData.cs" />
     164    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" />
     165    <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" />
     166    <Compile Include="OnlineCalculators\DependencyCalculator\HoeffdingsDependenceCalculator.cs" />
     167    <Compile Include="OnlineCalculators\DependencyCalculator\PearsonsRDependenceCalculator.cs" />
     168    <Compile Include="OnlineCalculators\DependencyCalculator\PearsonsRSquaredDependenceCalculator.cs" />
     169    <Compile Include="OnlineCalculators\DependencyCalculator\SpearmansRankCorrelationCoefficientCalculator.cs" />
     170    <Compile Include="OnlineCalculators\OnlineBoundedMeanSquaredErrorCalculator.cs" />
     171    <Compile Include="OnlineCalculators\OnlineDirectionalSymmetryCalculator.cs" />
    144172    <Compile Include="OnlineCalculators\OnlineMaxAbsoluteErrorCalculator.cs" />
    145173    <Compile Include="OnlineCalculators\OnlineMeanErrorCalculator.cs" />
     
    180208    <Compile Include="OnlineCalculators\OnlinePearsonsRSquaredCalculator.cs" />
    181209    <Compile Include="Implementation\Regression\RegressionSolution.cs" />
     210    <Compile Include="OnlineCalculators\OnlineTheilsUStatisticCalculator.cs" />
     211    <Compile Include="OnlineCalculators\OnlineWeightedDirectionalSymmetryCalculator.cs" />
    182212    <Compile Include="Plugin.cs" />
    183213    <Compile Include="Implementation\Classification\ThresholdCalculators\AccuracyMaximizationThresholdCalculator.cs" />
     
    260290    </ProjectReference>
    261291  </ItemGroup>
     292  <ItemGroup />
    262293  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    263294  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
     
    269300  -->
    270301  <PropertyGroup>
    271     <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     302    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    272303set ProjectDir=$(ProjectDir)
    273304set SolutionDir=$(SolutionDir)
     
    276307call PreBuildEvent.cmd
    277308</PreBuildEvent>
     309    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     310export ProjectDir=$(ProjectDir)
     311export SolutionDir=$(SolutionDir)
     312
     313$SolutionDir/PreBuildEvent.sh
     314</PreBuildEvent>
    278315  </PropertyGroup>
    279316</Project>
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r7259 r9363  
    9595
    9696    IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    97       return new ClassificationEnsembleSolution(models, problemData);
     97      return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData));
    9898    }
    9999    #endregion
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r8174 r9363  
    3636  [Item("Classification Ensemble Solution", "A classification solution that contains an ensemble of multiple classification models")]
    3737  [Creatable("Data Analysis - Ensembles")]
    38   public sealed class ClassificationEnsembleSolution : ClassificationSolution, IClassificationEnsembleSolution {
     38  public sealed class ClassificationEnsembleSolution : ClassificationSolutionBase, IClassificationEnsembleSolution {
    3939    private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>();
    4040    private readonly Dictionary<int, double> testEvaluationCache = new Dictionary<int, double>();
     41    private readonly Dictionary<int, double> evaluationCache = new Dictionary<int, double>();
    4142
    4243    public new IClassificationEnsembleModel Model {
     
    104105    }
    105106
     107    public ClassificationEnsembleSolution(IClassificationProblemData problemData) :
     108      this(Enumerable.Empty<IClassificationModel>(), problemData) { }
     109
    106110    public ClassificationEnsembleSolution(IEnumerable<IClassificationModel> models, IClassificationProblemData problemData)
    107111      : this(models, problemData,
     
    150154    }
    151155
    152     protected override void RecalculateResults() {
    153       CalculateResults();
    154     }
    155156
    156157    #region Evaluation
     158    public override IEnumerable<double> EstimatedClassValues {
     159      get { return GetEstimatedClassValues(Enumerable.Range(0, ProblemData.Dataset.Rows)); }
     160    }
     161
    157162    public override IEnumerable<double> EstimatedTrainingClassValues {
    158163      get {
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r8121 r9363  
    223223    }
    224224
    225     private List<double> classValues;
    226     public List<double> ClassValues {
     225    private List<double> classValuesCache;
     226    private List<double> ClassValuesCache {
    227227      get {
    228         if (classValues == null) {
    229           classValues = Dataset.GetDoubleValues(TargetVariableParameter.Value.Value).Distinct().ToList();
    230           classValues.Sort();
     228        if (classValuesCache == null) {
     229          classValuesCache = Dataset.GetDoubleValues(TargetVariableParameter.Value.Value).Distinct().OrderBy(x => x).ToList();
    231230        }
    232         return classValues;
     231        return classValuesCache;
    233232      }
    234233    }
    235     IEnumerable<double> IClassificationProblemData.ClassValues {
    236       get { return ClassValues; }
    237     }
    238 
     234    public IEnumerable<double> ClassValues {
     235      get { return ClassValuesCache; }
     236    }
    239237    public int Classes {
    240       get { return ClassValues.Count; }
    241     }
    242 
    243     private List<string> classNames;
    244     public List<string> ClassNames {
     238      get { return ClassValuesCache.Count; }
     239    }
     240
     241    private List<string> classNamesCache;
     242    private List<string> ClassNamesCache {
    245243      get {
    246         if (classNames == null) {
    247           classNames = new List<string>();
     244        if (classNamesCache == null) {
     245          classNamesCache = new List<string>();
    248246          for (int i = 0; i < ClassNamesParameter.Value.Rows; i++)
    249             classNames.Add(ClassNamesParameter.Value[i, 0]);
     247            classNamesCache.Add(ClassNamesParameter.Value[i, 0]);
    250248        }
    251         return classNames;
     249        return classNamesCache;
    252250      }
    253251    }
    254     IEnumerable<string> IClassificationProblemData.ClassNames {
    255       get { return ClassNames; }
    256     }
    257 
    258     private Dictionary<Tuple<double, double>, double> classificationPenaltiesCache = new Dictionary<Tuple<double, double>, double>();
     252    public IEnumerable<string> ClassNames {
     253      get { return ClassNamesCache; }
     254    }
    259255    #endregion
    260256
     
    277273
    278274    public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { }
     275
     276    public ClassificationProblemData(IClassificationProblemData classificationProblemData)
     277      : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) {
     278      TrainingPartition.Start = classificationProblemData.TrainingPartition.Start;
     279      TrainingPartition.End = classificationProblemData.TrainingPartition.End;
     280      TestPartition.Start = classificationProblemData.TestPartition.Start;
     281      TestPartition.End = classificationProblemData.TestPartition.End;
     282
     283      for (int i = 0; i < classificationProblemData.ClassNames.Count(); i++)
     284        ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i);
     285
     286      for (int i = 0; i < Classes; i++) {
     287        for (int j = 0; j < Classes; j++) {
     288          ClassificationPenaltiesParameter.Value[i, j] = classificationProblemData.GetClassificationPenalty(ClassValuesCache[i], ClassValuesCache[j]);
     289        }
     290      }
     291    }
     292
    279293    public ClassificationProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)
    280294      : base(dataset, allowedInputVariables) {
     
    286300      Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, ""));
    287301
     302      RegisterParameterEvents();
    288303      ResetTargetVariableDependentMembers();
    289       RegisterParameterEvents();
    290     }
    291 
    292     private static IEnumerable<string> CheckVariablesForPossibleTargetVariables(Dataset dataset) {
     304    }
     305
     306    public static IEnumerable<string> CheckVariablesForPossibleTargetVariables(Dataset dataset) {
    293307      int maxSamples = Math.Min(InspectedRowsToDetermineTargets, dataset.Rows);
    294308      var validTargetVariables = (from v in dataset.DoubleVariables
     
    310324      DeregisterParameterEvents();
    311325
    312       classNames = null;
    313326      ((IStringConvertibleMatrix)ClassNamesParameter.Value).Columns = 1;
    314       ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = ClassValues.Count;
     327      ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = ClassValuesCache.Count;
    315328      for (int i = 0; i < Classes; i++)
    316         ClassNamesParameter.Value[i, 0] = "Class " + ClassValues[i];
     329        ClassNamesParameter.Value[i, 0] = "Class " + ClassValuesCache[i];
    317330      ClassNamesParameter.Value.ColumnNames = new List<string>() { "ClassNames" };
    318331      ClassNamesParameter.Value.RowNames = ClassValues.Select(s => "ClassValue: " + s);
    319332
    320       classificationPenaltiesCache.Clear();
    321       ((ValueParameter<DoubleMatrix>)ClassificationPenaltiesParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
    322333      ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Rows = Classes;
    323334      ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Columns = Classes;
     
    330341        }
    331342      }
    332       ((ValueParameter<DoubleMatrix>)ClassificationPenaltiesParameter).ReactOnValueToStringChangedAndValueItemImageChanged = true;
    333343      RegisterParameterEvents();
    334344    }
    335345
    336346    public string GetClassName(double classValue) {
    337       if (!ClassValues.Contains(classValue)) throw new ArgumentException();
    338       int index = ClassValues.IndexOf(classValue);
    339       return ClassNames[index];
     347      if (!ClassValuesCache.Contains(classValue)) throw new ArgumentException();
     348      int index = ClassValuesCache.IndexOf(classValue);
     349      return ClassNamesCache[index];
    340350    }
    341351    public double GetClassValue(string className) {
    342       if (!ClassNames.Contains(className)) throw new ArgumentException();
    343       int index = ClassNames.IndexOf(className);
    344       return ClassValues[index];
     352      if (!ClassNamesCache.Contains(className)) throw new ArgumentException();
     353      int index = ClassNamesCache.IndexOf(className);
     354      return ClassValuesCache[index];
    345355    }
    346356    public void SetClassName(double classValue, string className) {
    347       if (!classValues.Contains(classValue)) throw new ArgumentException();
    348       int index = ClassValues.IndexOf(classValue);
    349       ClassNames[index] = className;
     357      if (!ClassValuesCache.Contains(classValue)) throw new ArgumentException();
     358      int index = ClassValuesCache.IndexOf(classValue);
    350359      ClassNamesParameter.Value[index, 0] = className;
     360      // updating of class names cache is not necessary here as the parameter value fires a changed event which updates the cache
    351361    }
    352362
     
    355365    }
    356366    public double GetClassificationPenalty(double correctClassValue, double estimatedClassValue) {
    357       var key = Tuple.Create(correctClassValue, estimatedClassValue);
    358       if (!classificationPenaltiesCache.ContainsKey(key)) {
    359         int correctClassIndex = ClassValues.IndexOf(correctClassValue);
    360         int estimatedClassIndex = ClassValues.IndexOf(estimatedClassValue);
    361         classificationPenaltiesCache[key] = ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex];
    362       }
    363       return classificationPenaltiesCache[key];
     367      int correctClassIndex = ClassValuesCache.IndexOf(correctClassValue);
     368      int estimatedClassIndex = ClassValuesCache.IndexOf(estimatedClassValue);
     369      return ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex];
    364370    }
    365371    public void SetClassificationPenalty(string correctClassName, string estimatedClassName, double penalty) {
     
    367373    }
    368374    public void SetClassificationPenalty(double correctClassValue, double estimatedClassValue, double penalty) {
    369       var key = Tuple.Create(correctClassValue, estimatedClassValue);
    370       int correctClassIndex = ClassValues.IndexOf(correctClassValue);
    371       int estimatedClassIndex = ClassValues.IndexOf(estimatedClassValue);
     375      int correctClassIndex = ClassValuesCache.IndexOf(correctClassValue);
     376      int estimatedClassIndex = ClassValuesCache.IndexOf(estimatedClassValue);
    372377
    373378      ClassificationPenaltiesParameter.Value[correctClassIndex, estimatedClassIndex] = penalty;
     
    378383      TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged);
    379384      ClassNamesParameter.Value.Reset += new EventHandler(Parameter_ValueChanged);
    380       ClassNamesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);
     385      ClassNamesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(Parameter_ValueChanged);
     386      ClassificationPenaltiesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(Parameter_ValueChanged);
    381387      ClassificationPenaltiesParameter.Value.Reset += new EventHandler(Parameter_ValueChanged);
    382       ClassificationPenaltiesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);
    383388    }
    384389    private void DeregisterParameterEvents() {
    385390      TargetVariableParameter.ValueChanged -= new EventHandler(TargetVariableParameter_ValueChanged);
    386391      ClassNamesParameter.Value.Reset -= new EventHandler(Parameter_ValueChanged);
    387       ClassNamesParameter.Value.ItemChanged -= new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);
     392      ClassNamesParameter.Value.ItemChanged -= new EventHandler<EventArgs<int, int>>(Parameter_ValueChanged);
     393      ClassificationPenaltiesParameter.Value.ItemChanged -= new EventHandler<EventArgs<int, int>>(Parameter_ValueChanged);
    388394      ClassificationPenaltiesParameter.Value.Reset -= new EventHandler(Parameter_ValueChanged);
    389       ClassificationPenaltiesParameter.Value.ItemChanged -= new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged);
    390395    }
    391396
    392397    private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
    393       classValues = null;
     398      classValuesCache = null;
     399      classNamesCache = null;
    394400      ResetTargetVariableDependentMembers();
    395401      OnChanged();
    396402    }
    397403    private void Parameter_ValueChanged(object sender, EventArgs e) {
    398       OnChanged();
    399     }
    400     private void MatrixParameter_ItemChanged(object sender, EventArgs<int, int> e) {
     404      classNamesCache = null;
     405      ClassificationPenaltiesParameter.Value.RowNames = ClassNames.Select(name => "Actual " + name);
     406      ClassificationPenaltiesParameter.Value.ColumnNames = ClassNames.Select(name => "Estimated " + name);
    401407      OnChanged();
    402408    }
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs

    r8174 r9363  
    4545      : base(model, problemData) {
    4646      evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows);
     47      CalculateClassificationResults();
    4748    }
    4849
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r8139 r9363  
    8585    }
    8686
    87     protected void CalculateResults() {
     87    protected void CalculateClassificationResults() {
    8888      double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values
    8989      double[] originalTrainingClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToArray();
     
    114114
    115115    public abstract IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows);
     116
     117    protected override void RecalculateResults() {
     118      CalculateClassificationResults();
     119    }
    116120  }
    117121}
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r7259 r9363  
    3333  [StorableClass]
    3434  [Item("DiscriminantFunctionClassificationModel", "Represents a classification model that uses a discriminant function and classification thresholds.")]
    35   public abstract class DiscriminantFunctionClassificationModel : NamedItem, IDiscriminantFunctionClassificationModel {
     35  public class DiscriminantFunctionClassificationModel : NamedItem, IDiscriminantFunctionClassificationModel {
    3636    [Storable]
    3737    private IRegressionModel model;
     38    public IRegressionModel Model {
     39      get { return model; }
     40      private set { model = value; }
     41    }
    3842
    3943    [Storable]
     
    5155    }
    5256
     57    private IDiscriminantFunctionThresholdCalculator thresholdCalculator;
     58    [Storable]
     59    public IDiscriminantFunctionThresholdCalculator ThresholdCalculator {
     60      get { return thresholdCalculator; }
     61      private set { thresholdCalculator = value; }
     62    }
     63
    5364
    5465    [StorableConstructor]
     
    6172    }
    6273
    63     public DiscriminantFunctionClassificationModel(IRegressionModel model)
     74    public DiscriminantFunctionClassificationModel(IRegressionModel model, IDiscriminantFunctionThresholdCalculator thresholdCalculator)
    6475      : base() {
    6576      this.name = ItemName;
    6677      this.description = ItemDescription;
    6778      this.model = model;
    68       this.classValues = new double[] { 0.0 };
    69       this.thresholds = new double[] { double.NegativeInfinity };
     79      this.classValues = new double[0];
     80      this.thresholds = new double[0];
     81      this.thresholdCalculator = thresholdCalculator;
     82    }
     83
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      if (ThresholdCalculator == null) ThresholdCalculator = new AccuracyMaximizationThresholdCalculator();
     87    }
     88
     89    public override IDeepCloneable Clone(Cloner cloner) {
     90      return new DiscriminantFunctionClassificationModel(this, cloner);
    7091    }
    7192
     
    80101    }
    81102
     103    public virtual void RecalculateModelParameters(IClassificationProblemData problemData, IEnumerable<int> rows) {
     104      double[] classValues;
     105      double[] thresholds;
     106      var targetClassValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     107      var estimatedTrainingValues = GetEstimatedValues(problemData.Dataset, rows);
     108      thresholdCalculator.Calculate(problemData, estimatedTrainingValues, targetClassValues, out classValues, out thresholds);
     109      SetThresholdsAndClassValues(thresholds, classValues);
     110    }
     111
     112
    82113    public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
    83114      return model.GetEstimatedValues(dataset, rows);
     
    85116
    86117    public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) {
     118      if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model.");
    87119      foreach (var x in GetEstimatedValues(dataset, rows)) {
    88120        int classIndex = 0;
     
    103135    #endregion
    104136
    105     public abstract IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData);
    106     public abstract IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData);
     137    public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData) {
     138      return new DiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData));
     139    }
     140
     141    public virtual IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     142      return CreateDiscriminantFunctionClassificationSolution(problemData);
     143    }
    107144  }
    108145}
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs

    r8139 r9363  
    3232  [StorableClass]
    3333  [Item("DiscriminantFunctionClassificationSolution", "Represents a classification solution that uses a discriminant function and classification thresholds.")]
    34   public abstract class DiscriminantFunctionClassificationSolution : DiscriminantFunctionClassificationSolutionBase {
     34  public class DiscriminantFunctionClassificationSolution : DiscriminantFunctionClassificationSolutionBase {
    3535    protected readonly Dictionary<int, double> valueEvaluationCache;
    3636    protected readonly Dictionary<int, double> classValueEvaluationCache;
     
    4747      classValueEvaluationCache = new Dictionary<int, double>(original.classValueEvaluationCache);
    4848    }
    49     protected DiscriminantFunctionClassificationSolution(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData)
     49    public DiscriminantFunctionClassificationSolution(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData)
    5050      : base(model, problemData) {
    5151      valueEvaluationCache = new Dictionary<int, double>();
    5252      classValueEvaluationCache = new Dictionary<int, double>();
     53      CalculateRegressionResults();
     54      CalculateClassificationResults();
     55    }
    5356
    54       SetAccuracyMaximizingThresholds();
     57    public override IDeepCloneable Clone(Cloner cloner) {
     58      return new DiscriminantFunctionClassificationSolution(this, cloner);
    5559    }
    5660
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs

    r8139 r9363  
    8585      Add(new Result(TrainingRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
    8686      Add(new Result(TestRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
    87 
    8887      RegisterEventHandler();
    8988    }
     
    9291    private void AfterDeserialization() {
    9392      RegisterEventHandler();
    94     }
    95 
    96     protected override void OnModelChanged() {
    97       DeregisterEventHandler();
    98       SetAccuracyMaximizingThresholds();
    99       RegisterEventHandler();
    100       base.OnModelChanged();
    10193    }
    10294
     
    137129    }
    138130
    139     public void SetAccuracyMaximizingThresholds() {
    140       double[] classValues;
    141       double[] thresholds;
    142       var targetClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);
    143       AccuracyMaximizationThresholdCalculator.CalculateThresholds(ProblemData, EstimatedTrainingValues, targetClassValues, out classValues, out thresholds);
    144 
    145       Model.SetThresholdsAndClassValues(thresholds, classValues);
    146     }
    147 
    148     public void SetClassDistibutionCutPointThresholds() {
    149       double[] classValues;
    150       double[] thresholds;
    151       var targetClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);
    152       NormalDistributionCutPointsThresholdCalculator.CalculateThresholds(ProblemData, EstimatedTrainingValues, targetClassValues, out classValues, out thresholds);
    153 
    154       Model.SetThresholdsAndClassValues(thresholds, classValues);
    155     }
    156 
    157131    protected virtual void OnModelThresholdsChanged(EventArgs e) {
    158       CalculateResults();
    159       CalculateRegressionResults();
     132      OnModelChanged();
    160133    }
    161134
     
    165138
    166139    public abstract IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows);
     140
     141    protected override void RecalculateResults() {
     142      base.RecalculateResults();
     143      CalculateRegressionResults();
     144    }
    167145  }
    168146}
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs

    r8126 r9363  
    5353
    5454    public static void CalculateThresholds(IClassificationProblemData problemData, IEnumerable<double> estimatedValues, IEnumerable<double> targetClassValues, out double[] classValues, out double[] thresholds) {
    55       int slices = 100;
    56       double minThresholdInc = 10e-5; // necessary to prevent infinite loop when maxEstimated - minEstimated is effectively zero (constant model)
     55      const int slices = 100;
     56      const double minThresholdInc = 10e-5; // necessary to prevent infinite loop when maxEstimated - minEstimated is effectively zero (constant model)
    5757      List<double> estimatedValuesList = estimatedValues.ToList();
    5858      double maxEstimatedValue = estimatedValuesList.Max();
     
    6161      var estimatedAndTargetValuePairs =
    6262        estimatedValuesList.Zip(targetClassValues, (x, y) => new { EstimatedValue = x, TargetClassValue = y })
    63         .OrderBy(x => x.EstimatedValue)
    64         .ToList();
     63        .OrderBy(x => x.EstimatedValue).ToList();
    6564
    66       classValues = problemData.ClassValues.OrderBy(x => x).ToArray();
     65      classValues = estimatedAndTargetValuePairs.GroupBy(x => x.TargetClassValue)
     66        .Select(x => new { Median = x.Select(y => y.EstimatedValue).Median(), Class = x.Key })
     67        .OrderBy(x => x.Median).Select(x => x.Class).ToArray();
     68
    6769      int nClasses = classValues.Length;
    6870      thresholds = new double[nClasses];
    6971      thresholds[0] = double.NegativeInfinity;
    70       // thresholds[thresholds.Length - 1] = double.PositiveInfinity;
    7172
    7273      // incrementally calculate accuracy of all possible thresholds
     
    8586            //all positives
    8687            if (pair.TargetClassValue.IsAlmost(classValues[i - 1])) {
    87               if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue < actualThreshold)
     88              if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue <= actualThreshold)
    8889                //true positive
    89                 classificationScore += problemData.GetClassificationPenalty(classValues[i - 1], classValues[i - 1]);
     90                classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, pair.TargetClassValue);
    9091              else
    9192                //false negative
    92                 classificationScore += problemData.GetClassificationPenalty(classValues[i], classValues[i - 1]);
     93                classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i]);
    9394            }
    9495              //all negatives
    9596            else {
    96               if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue < actualThreshold)
    97                 //false positive
    98                 classificationScore += problemData.GetClassificationPenalty(classValues[i - 1], classValues[i]);
    99               else
    100                 //true negative, consider only upper class
    101                 classificationScore += problemData.GetClassificationPenalty(classValues[i], classValues[i]);
     97              //false positive
     98              if (pair.EstimatedValue > lowerThreshold && pair.EstimatedValue <= actualThreshold)
     99                classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i - 1]);
     100              else if (pair.EstimatedValue <= lowerThreshold)
     101                classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i - 2]);
     102              else if (pair.EstimatedValue > actualThreshold) {
     103                if (pair.TargetClassValue < classValues[i - 1]) //negative in wrong class, consider upper class
     104                  classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, classValues[i]);
     105                else //true negative, must be optimized by the other thresholds
     106                  classificationScore += problemData.GetClassificationPenalty(pair.TargetClassValue, pair.TargetClassValue);
     107              }
    102108            }
    103109          }
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/NormalDistributionCutPointsThresholdCalculator.cs

    r7259 r9363  
    5353
    5454    public static void CalculateThresholds(IClassificationProblemData problemData, IEnumerable<double> estimatedValues, IEnumerable<double> targetClassValues, out double[] classValues, out double[] thresholds) {
    55       double maxEstimatedValue = estimatedValues.Max();
    56       double minEstimatedValue = estimatedValues.Min();
    5755      var estimatedTargetValues = Enumerable.Zip(estimatedValues, targetClassValues, (e, t) => new { EstimatedValue = e, TargetValue = t }).ToList();
     56      double estimatedValuesRange = estimatedValues.Range();
    5857
    5958      Dictionary<double, double> classMean = new Dictionary<double, double>();
     
    7271        }
    7372      }
     73
    7474      double[] originalClasses = classMean.Keys.OrderBy(x => x).ToArray();
    7575      int nClasses = originalClasses.Length;
     
    8282          // calculate all thresholds
    8383          CalculateCutPoints(classMean[class0], classStdDev[class0], classMean[class1], classStdDev[class1], out x1, out x2);
    84           if (!thresholdList.Any(x => x.IsAlmost(x1))) thresholdList.Add(x1);
    85           if (!thresholdList.Any(x => x.IsAlmost(x2))) thresholdList.Add(x2);
     84
     85          // if the two cut points are too close (for instance because the stdDev=0)
     86          // then move them by 0.1% of the range of estimated values
     87          if (x1.IsAlmost(x2)) {
     88            x1 -= 0.001 * estimatedValuesRange;
     89            x2 += 0.001 * estimatedValuesRange;
     90          }
     91          if (!double.IsInfinity(x1) && !thresholdList.Any(x => x.IsAlmost(x1))) thresholdList.Add(x1);
     92          if (!double.IsInfinity(x2) && !thresholdList.Any(x => x.IsAlmost(x2))) thresholdList.Add(x2);
    8693        }
    8794      }
    8895      thresholdList.Sort();
     96
     97      // add small value and large value for the calculation of most influential class in each thresholded section
    8998      thresholdList.Insert(0, double.NegativeInfinity);
    90 
    91       // determine class values for each partition separated by a threshold by calculating the density of all class distributions
    92       // all points in the partition are classified as the class with the maximal density in the parition
    93       List<double> classValuesList = new List<double>();
    94       for (int i = 0; i < thresholdList.Count; i++) {
    95         double m;
    96         if (double.IsNegativeInfinity(thresholdList[i])) {
    97           m = thresholdList[i + 1] - 1.0; // smaller than the smalles non-infinity threshold
    98         } else if (i == thresholdList.Count - 1) {
    99           // last threshold
    100           m = thresholdList[i] + 1.0; // larger than the last threshold
    101         } else {
    102           m = thresholdList[i] + (thresholdList[i + 1] - thresholdList[i]) / 2.0; // middle of partition
    103         }
    104 
    105         // determine class with maximal probability density in m
    106         double maxDensity = double.MinValue;
    107         double maxDensityClassValue = -1;
    108         foreach (var classValue in originalClasses) {
    109           double density = NormalDensity(m, classMean[classValue], classStdDev[classValue]);
     99      thresholdList.Add(double.PositiveInfinity);
     100
     101
     102      // find the most likely class for the points between thresholds m
     103      List<double> filteredThresholds = new List<double>();
     104      List<double> filteredClassValues = new List<double>();
     105      for (int i = 0; i < thresholdList.Count - 1; i++) {
     106        // determine class with maximal density mass between the thresholds
     107        double maxDensity = DensityMass(thresholdList[i], thresholdList[i + 1], classMean[originalClasses[0]], classStdDev[originalClasses[0]]);
     108        double maxDensityClassValue = originalClasses[0];
     109        foreach (var classValue in originalClasses.Skip(1)) {
     110          double density = DensityMass(thresholdList[i], thresholdList[i + 1], classMean[classValue], classStdDev[classValue]);
    110111          if (density > maxDensity) {
    111112            maxDensity = density;
     
    113114          }
    114115        }
    115         classValuesList.Add(maxDensityClassValue);
    116       }
    117 
    118       // only keep thresholds at which the class changes
    119       // class B overrides threshold s. So only thresholds r and t are relevant and have to be kept
    120       //
    121       //      A    B  C
    122       //       /\  /\/\       
    123       //      / r\/ /\t\       
    124       //     /   /\/  \ \     
    125       //    /   / /\s  \ \     
    126       //  -/---/-/ -\---\-\----
    127       List<double> filteredThresholds = new List<double>();
    128       List<double> filteredClassValues = new List<double>();
    129       filteredThresholds.Add(thresholdList[0]);
    130       filteredClassValues.Add(classValuesList[0]);
    131       for (int i = 0; i < classValuesList.Count - 1; i++) {
    132         if (classValuesList[i] != classValuesList[i + 1]) {
    133           filteredThresholds.Add(thresholdList[i + 1]);
    134           filteredClassValues.Add(classValuesList[i + 1]);
    135         }
    136       }
     116        if (maxDensity > double.NegativeInfinity &&
     117          (filteredClassValues.Count == 0 || !maxDensityClassValue.IsAlmost(filteredClassValues.Last()))) {
     118          filteredThresholds.Add(thresholdList[i]);
     119          filteredClassValues.Add(maxDensityClassValue);
     120        }
     121      }
     122
     123      if (filteredThresholds.Count == 0 || !double.IsNegativeInfinity(filteredThresholds.First())) {
     124        // this happens if there are no thresholds (distributions for all classes are exactly the same)
     125        // or when the CDF up to the first threshold is zero
     126        // -> all samples should be classified as the class with the most observations
     127        // group observations by target class and select the class with largest count
     128        double mostFrequentClass = targetClassValues.GroupBy(c => c)
     129                              .OrderBy(g => g.Count())
     130                              .Last().Key;
     131        filteredThresholds.Insert(0, double.NegativeInfinity);
     132        filteredClassValues.Insert(0, mostFrequentClass);
     133      }
     134
    137135      thresholds = filteredThresholds.ToArray();
    138136      classValues = filteredClassValues.ToArray();
    139137    }
    140138
    141     private static double NormalDensity(double x, double mu, double sigma) {
     139    private static double sqr2 = Math.Sqrt(2.0);
     140    // returns the density function of the standard normal distribution at x
     141    private static double NormalCDF(double x) {
     142      return 0.5 * (1 + alglib.errorfunction(x / sqr2));
     143    }
     144
     145    // approximation of the log of the normal cummulative distribution from the lightspeed toolbox by Tom Minka
     146    // http://research.microsoft.com/en-us/um/people/minka/software/lightspeed/
     147    private static double[] c = new double[] { -1, 5 / 2.0, -37 / 3.0, 353 / 4.0, -4081 / 5.0, 55205 / 6.0, -854197 / 7.0 };
     148    private static double LogNormalCDF(double x) {
     149      if (x >= -6.5)
     150        // calculate the log directly if x is large enough
     151        return Math.Log(NormalCDF(x));
     152      else {
     153        double z = Math.Pow(x, -2);
     154        // asymptotic series for logcdf
     155        double y = z * (c[0] + z * (c[1] + z * (c[2] + z * (c[3] + z * (c[4] + z * (c[5] + z * c[6]))))));
     156        return y - 0.5 * Math.Log(2 * Math.PI) - 0.5 * x * x - Math.Log(-x);
     157      }
     158    }
     159
     160    // determines the value NormalCDF(mu,sigma, upper)  - NormalCDF(mu, sigma, lower)
     161    // = the integral of the PDF of N(mu, sigma) in the range [lower, upper]
     162    private static double DensityMass(double lower, double upper, double mu, double sigma) {
    142163      if (sigma.IsAlmost(0.0)) {
    143         if (x.IsAlmost(mu)) return 1.0; else return 0.0;
     164        if (lower < mu && mu < upper) return 0.0; // all mass is between lower and upper
     165        else return double.NegativeInfinity; // no mass is between lower and upper
     166      }
     167
     168      if (lower > mu) {
     169        return DensityMass(-upper, -lower, -mu, sigma);
     170      }
     171
     172      upper = (upper - mu) / sigma;
     173      lower = (lower - mu) / sigma;
     174      if (double.IsNegativeInfinity(lower)) return LogNormalCDF(upper);
     175
     176      return LogNormalCDF(upper) + Math.Log(1 - Math.Exp(LogNormalCDF(lower) - LogNormalCDF(upper)));
     177    }
     178
     179    // Calculates the points x1 and x2 where the distributions N(m1, s1) == N(m2,s2).
     180    // In the general case there should be two cut points. If either s1 or s2 is 0 then x1==x2.
     181    // If both s1 and s2 are zero than there are no cut points but we should return something reasonable (e.g. (m1 + m2) / 2) then.
     182    private static void CalculateCutPoints(double m1, double s1, double m2, double s2, out double x1, out double x2) {
     183      if (s1.IsAlmost(s2)) {
     184        if (m1.IsAlmost(m2)) {
     185          x1 = double.NegativeInfinity;
     186          x2 = double.NegativeInfinity;
     187        } else {
     188          // s1==s2 and m1 != m2
     189          // return something reasonable. cut point should be half way between m1 and m2
     190          x1 = (m1 + m2) / 2;
     191          x2 = double.NegativeInfinity;
     192        }
     193      } else if (s1.IsAlmost(0.0)) {
     194        // when s1 is 0.0 the cut points are exactly at m1 ...
     195        x1 = m1;
     196        x2 = m1;
     197      } else if (s2.IsAlmost(0.0)) {
     198        // ... same for s2
     199        x1 = m2;
     200        x2 = m2;
    144201      } else {
    145         return (1.0 / Math.Sqrt(2.0 * Math.PI * sigma * sigma)) * Math.Exp(-((x - mu) * (x - mu)) / (2.0 * sigma * sigma));
    146       }
    147     }
    148 
    149     private static void CalculateCutPoints(double m1, double s1, double m2, double s2, out double x1, out double x2) {
    150       double a = (s1 * s1 - s2 * s2);
    151       x1 = -(-m2 * s1 * s1 + m1 * s2 * s2 + Math.Sqrt(s1 * s1 * s2 * s2 * ((m1 - m2) * (m1 - m2) + 2.0 * (-s1 * s1 + s2 * s2) * Math.Log(s2 / s1)))) / a;
    152       x2 = (m2 * s1 * s1 - m1 * s2 * s2 + Math.Sqrt(s1 * s1 * s2 * s2 * ((m1 - m2) * (m1 - m2) + 2.0 * (-s1 * s1 + s2 * s2) * Math.Log(s2 / s1)))) / a;
     202        if (s2 < s1) {
     203          // make sure s2 is the larger std.dev.
     204          CalculateCutPoints(m2, s2, m1, s1, out x1, out x2);
     205        } else {
     206          // general case
     207          // calculate the solutions x1, x2 where N(m1,s1) == N(m2,s2)
     208          double g = Math.Sqrt(2 * s2 * s2 * Math.Log(s2 / s1) - 2 * s1 * s1 * Math.Log(s2 / s1) - 2 * m1 * m2 + m1 * m1 + m2 * m2);
     209          double s = (s1 * s1 - s2 * s2);
     210          x1 = (m2 * s1 * s1 - m1 * s2 * s2 + s1 * s2 * g) / s;
     211          x2 = -(m1 * s2 * s2 - m2 * s1 * s1 + s1 * s2 * g) / s;
     212        }
     213      }
    153214    }
    154215  }
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblem.cs

    r7823 r9363  
    6666    }
    6767
     68    protected DataAnalysisProblem(T problemData)
     69      : this() {
     70      ProblemData = problemData;
     71    }
     72
    6873    [StorableHook(HookType.AfterDeserialization)]
    6974    private void AfterDeserialization() {
     
    97102      Description = data.Description;
    98103      ProblemData = data;
    99       OnReset();
    100104    }
    101105
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r8139 r9363  
    107107    [StorableConstructor]
    108108    protected DataAnalysisProblemData(bool deserializing) : base(deserializing) { }
     109
    109110    [StorableHook(HookType.AfterDeserialization)]
    110111    private void AfterDeserialization() {
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs

    r7259 r9363  
    2727
    2828namespace HeuristicLab.Problems.DataAnalysis {
     29  [StorableClass]
    2930  [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")]
    3031  public class ConstantRegressionModel : NamedItem, IRegressionModel {
    3132    [Storable]
    32     private double constant;
     33    protected double constant;
    3334    public double Constant {
    3435      get { return constant; }
     
    5556
    5657    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    57       return new ConstantRegressionSolution(this, problemData);
     58      return new ConstantRegressionSolution(this, new RegressionProblemData(problemData));
    5859    }
    5960  }
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionSolution.cs

    r7049 r9363  
    1 using HeuristicLab.Common;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using HeuristicLab.Common;
    223using HeuristicLab.Core;
    324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r7259 r9363  
    102102
    103103    public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    104       return new RegressionEnsembleSolution(this.Models, problemData);
     104      return new RegressionEnsembleSolution(this.Models, new RegressionEnsembleProblemData(problemData));
    105105    }
    106106    IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r8174 r9363  
    3636  [Item("Regression Ensemble Solution", "A regression solution that contains an ensemble of multiple regression models")]
    3737  [Creatable("Data Analysis - Ensembles")]
    38   public sealed class RegressionEnsembleSolution : RegressionSolution, IRegressionEnsembleSolution {
     38  public sealed class RegressionEnsembleSolution : RegressionSolutionBase, IRegressionEnsembleSolution {
    3939    private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>();
    4040    private readonly Dictionary<int, double> testEvaluationCache = new Dictionary<int, double>();
     41    private readonly Dictionary<int, double> evaluationCache = new Dictionary<int, double>();
    4142
    4243    public new IRegressionEnsembleModel Model {
     
    155156    }
    156157
    157     protected override void RecalculateResults() {
    158       CalculateResults();
    159     }
    160 
    161158    #region Evaluation
     159    public override IEnumerable<double> EstimatedValues {
     160      get { return GetEstimatedValues(Enumerable.Range(0, ProblemData.Dataset.Rows)); }
     161    }
     162
    162163    public override IEnumerable<double> EstimatedTrainingValues {
    163164      get {
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs

    r7823 r9363  
    3636    public override IDeepCloneable Clone(Cloner cloner) { return new RegressionProblem(this, cloner); }
    3737
    38     public RegressionProblem()
    39       : base() {
    40       ProblemData = new RegressionProblemData();
    41     }
     38    public RegressionProblem() : base(new RegressionProblemData()) { }
     39
    4240  }
    4341}
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r8121 r9363  
    121121      : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) {
    122122    }
     123    public RegressionProblemData(IRegressionProblemData regressionProblemData)
     124      : this(regressionProblemData.Dataset, regressionProblemData.AllowedInputVariables, regressionProblemData.TargetVariable) {
     125      TrainingPartition.Start = regressionProblemData.TrainingPartition.Start;
     126      TrainingPartition.End = regressionProblemData.TrainingPartition.End;
     127      TestPartition.Start = regressionProblemData.TestPartition.Start;
     128      TestPartition.End = regressionProblemData.TestPartition.End;
     129    }
    123130
    124131    public RegressionProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs

    r8139 r9363  
    4545      : base(model, problemData) {
    4646      evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows);
     47      CalculateRegressionResults();
    4748    }
    4849
    49     protected override void RecalculateResults() {
    50       CalculateResults();
    51     }
    5250
    5351    public override IEnumerable<double> EstimatedValues {
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs

    r8139 r9363  
    2929  [StorableClass]
    3030  public abstract class RegressionSolutionBase : DataAnalysisSolution, IRegressionSolution {
    31     private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)";
    32     private const string TestMeanSquaredErrorResultName = "Mean squared error (test)";
    33     private const string TrainingMeanAbsoluteErrorResultName = "Mean absolute error (training)";
    34     private const string TestMeanAbsoluteErrorResultName = "Mean absolute error (test)";
    35     private const string TrainingSquaredCorrelationResultName = "Pearson's R² (training)";
    36     private const string TestSquaredCorrelationResultName = "Pearson's R² (test)";
    37     private const string TrainingRelativeErrorResultName = "Average relative error (training)";
    38     private const string TestRelativeErrorResultName = "Average relative error (test)";
    39     private const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)";
    40     private const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)";
    41     private const string TrainingMeanErrorResultName = "Mean error (training)";
    42     private const string TestMeanErrorResultName = "Mean error (test)";
     31    protected const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)";
     32    protected const string TestMeanSquaredErrorResultName = "Mean squared error (test)";
     33    protected const string TrainingMeanAbsoluteErrorResultName = "Mean absolute error (training)";
     34    protected const string TestMeanAbsoluteErrorResultName = "Mean absolute error (test)";
     35    protected const string TrainingSquaredCorrelationResultName = "Pearson's R² (training)";
     36    protected const string TestSquaredCorrelationResultName = "Pearson's R² (test)";
     37    protected const string TrainingRelativeErrorResultName = "Average relative error (training)";
     38    protected const string TestRelativeErrorResultName = "Average relative error (test)";
     39    protected const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)";
     40    protected const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)";
     41    protected const string TrainingMeanErrorResultName = "Mean error (training)";
     42    protected const string TestMeanErrorResultName = "Mean error (test)";
     43
     44    protected const string TrainingMeanSquaredErrorResultDescription = "Mean of squared errors of the model on the training partition";
     45    protected const string TestMeanSquaredErrorResultDescription = "Mean of squared errors of the model on the test partition";
     46    protected const string TrainingMeanAbsoluteErrorResultDescription = "Mean of absolute errors of the model on the training partition";
     47    protected const string TestMeanAbsoluteErrorResultDescription = "Mean of absolute errors of the model on the test partition";
     48    protected const string TrainingSquaredCorrelationResultDescription = "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition";
     49    protected const string TestSquaredCorrelationResultDescription = "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition";
     50    protected const string TrainingRelativeErrorResultDescription = "Average of the relative errors of the model output and the actual values on the training partition";
     51    protected const string TestRelativeErrorResultDescription = "Average of the relative errors of the model output and the actual values on the test partition";
     52    protected const string TrainingNormalizedMeanSquaredErrorResultDescription = "Normalized mean of squared errors of the model on the training partition";
     53    protected const string TestNormalizedMeanSquaredErrorResultDescription = "Normalized mean of squared errors of the model on the test partition";
     54    protected const string TrainingMeanErrorResultDescription = "Mean of errors of the model on the training partition";
     55    protected const string TestMeanErrorResultDescription = "Mean of errors of the model on the test partition";
    4356
    4457    public new IRegressionModel Model {
     
    115128    protected RegressionSolutionBase(IRegressionModel model, IRegressionProblemData problemData)
    116129      : base(model, problemData) {
    117       Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue()));
    118       Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue()));
    119       Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue()));
    120       Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue()));
    121       Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
    122       Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
    123       Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue()));
    124       Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue()));
    125       Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue()));
    126       Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue()));
    127       Add(new Result(TrainingMeanErrorResultName, "Mean of errors of the model on the training partition", new DoubleValue()));
    128       Add(new Result(TestMeanErrorResultName, "Mean of errors of the model on the test partition", new DoubleValue()));
     130      Add(new Result(TrainingMeanSquaredErrorResultName, TrainingMeanSquaredErrorResultDescription, new DoubleValue()));
     131      Add(new Result(TestMeanSquaredErrorResultName, TestMeanSquaredErrorResultDescription, new DoubleValue()));
     132      Add(new Result(TrainingMeanAbsoluteErrorResultName, TrainingMeanAbsoluteErrorResultDescription, new DoubleValue()));
     133      Add(new Result(TestMeanAbsoluteErrorResultName, TestMeanAbsoluteErrorResultDescription, new DoubleValue()));
     134      Add(new Result(TrainingSquaredCorrelationResultName, TrainingSquaredCorrelationResultDescription, new DoubleValue()));
     135      Add(new Result(TestSquaredCorrelationResultName, TestSquaredCorrelationResultDescription, new DoubleValue()));
     136      Add(new Result(TrainingRelativeErrorResultName, TrainingRelativeErrorResultDescription, new PercentValue()));
     137      Add(new Result(TestRelativeErrorResultName, TestRelativeErrorResultDescription, new PercentValue()));
     138      Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, TrainingNormalizedMeanSquaredErrorResultDescription, new DoubleValue()));
     139      Add(new Result(TestNormalizedMeanSquaredErrorResultName, TestNormalizedMeanSquaredErrorResultDescription, new DoubleValue()));
     140      Add(new Result(TrainingMeanErrorResultName, TrainingMeanErrorResultDescription, new DoubleValue()));
     141      Add(new Result(TestMeanErrorResultName, TestMeanErrorResultDescription, new DoubleValue()));
    129142    }
    130143
     
    164177    }
    165178
    166     protected void CalculateResults() {
     179    protected override void RecalculateResults() {
     180      CalculateRegressionResults();
     181    }
     182
     183    protected void CalculateRegressionResults() {
    167184      IEnumerable<double> estimatedTrainingValues = EstimatedTrainingValues; // cache values
    168185      IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs

    r7259 r9363  
    2626    IEnumerable<double> Thresholds { get; }
    2727    IEnumerable<double> ClassValues { get; }
     28    IDiscriminantFunctionThresholdCalculator ThresholdCalculator { get; }
     29    void RecalculateModelParameters(IClassificationProblemData problemData, IEnumerable<int> rows);
    2830    // class values and thresholds can only be assigned simultanously
    2931    void SetThresholdsAndClassValues(IEnumerable<double> thresholds, IEnumerable<double> classValues);
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Plugin.cs.frame

    r7823 r9363  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis","Provides base classes for data analysis tasks.", "3.4.2.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis","Provides base classes for data analysis tasks.", "3.4.3.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis-3.4.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.ALGLIB","3.7.0")]
    3031  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3132  [PluginDependency("HeuristicLab.Common", "3.3")]
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis/3.4/Properties/AssemblyInfo.cs.frame

    r7259 r9363  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.2.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.4.3.$WCREV$")]
Note: See TracChangeset for help on using the changeset viewer.