Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/08/17 17:02:13 (7 years ago)
Author:
jzenisek
Message:

#2719 merged with trunk (revision 15029)

Location:
branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis

  • branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r14400 r15030  
    4141
    4242    #region parameter properites
     43    //mkommend: inserted parameter caching due to performance reasons
     44    private IFixedValueParameter<Dataset> datasetParameter;
    4345    public IFixedValueParameter<Dataset> DatasetParameter {
    44       get { return (IFixedValueParameter<Dataset>)Parameters[DatasetParameterName]; }
    45     }
     46      get {
     47        if (datasetParameter == null) datasetParameter = (IFixedValueParameter<Dataset>)Parameters[DatasetParameterName];
     48        return datasetParameter;
     49      }
     50    }
     51
     52    private IFixedValueParameter<ReadOnlyCheckedItemList<StringValue>> inputVariablesParameter;
    4653    public IFixedValueParameter<ReadOnlyCheckedItemList<StringValue>> InputVariablesParameter {
    47       get { return (IFixedValueParameter<ReadOnlyCheckedItemList<StringValue>>)Parameters[InputVariablesParameterName]; }
    48     }
     54      get {
     55        if (inputVariablesParameter == null) inputVariablesParameter = (IFixedValueParameter<ReadOnlyCheckedItemList<StringValue>>)Parameters[InputVariablesParameterName];
     56        return inputVariablesParameter;
     57      }
     58    }
     59
     60    private IFixedValueParameter<IntRange> trainingPartitionParameter;
    4961    public IFixedValueParameter<IntRange> TrainingPartitionParameter {
    50       get { return (IFixedValueParameter<IntRange>)Parameters[TrainingPartitionParameterName]; }
    51     }
     62      get {
     63        if (trainingPartitionParameter == null) trainingPartitionParameter = (IFixedValueParameter<IntRange>)Parameters[TrainingPartitionParameterName];
     64        return trainingPartitionParameter;
     65      }
     66    }
     67
     68    private IFixedValueParameter<IntRange> testPartitionParameter;
    5269    public IFixedValueParameter<IntRange> TestPartitionParameter {
    53       get { return (IFixedValueParameter<IntRange>)Parameters[TestPartitionParameterName]; }
    54     }
     70      get {
     71        if (testPartitionParameter == null) testPartitionParameter = (IFixedValueParameter<IntRange>)Parameters[TestPartitionParameterName];
     72        return testPartitionParameter;
     73      }
     74    }
     75
    5576    public IFixedValueParameter<ReadOnlyItemList<ITransformation>> TransformationsParameter {
    5677      get { return (IFixedValueParameter<ReadOnlyItemList<ITransformation>>)Parameters[TransformationsParameterName]; }
     
    7394    }
    7495
     96    public double[,] AllowedInputsTrainingValues {
     97      get { return Dataset.ToArray(AllowedInputVariables, TrainingIndices); }
     98    }
     99
     100    public double[,] AllowedInputsTestValues { get { return Dataset.ToArray(AllowedInputVariables, TestIndices); } }
    75101    public IntRange TrainingPartition {
    76102      get { return TrainingPartitionParameter.Value; }
     
    102128    public virtual bool IsTrainingSample(int index) {
    103129      return index >= 0 && index < Dataset.Rows &&
    104         TrainingPartition.Start <= index && index < TrainingPartition.End &&
    105         (index < TestPartition.Start || TestPartition.End <= index);
     130             TrainingPartition.Start <= index && index < TrainingPartition.End &&
     131             (index < TestPartition.Start || TestPartition.End <= index);
    106132    }
    107133
     
    131157    protected DataAnalysisProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<ITransformation> transformations = null) {
    132158      if (dataset == null) throw new ArgumentNullException("The dataset must not be null.");
    133       if (allowedInputVariables == null) throw new ArgumentNullException("The allowedInputVariables must not be null.");
    134 
    135       if (allowedInputVariables.Except(dataset.DoubleVariables).Any())
    136         throw new ArgumentException("All allowed input variables must be present in the dataset and of type double.");
    137 
    138       var inputVariables = new CheckedItemList<StringValue>(dataset.DoubleVariables.Select(x => new StringValue(x)));
     159      if (allowedInputVariables == null) throw new ArgumentNullException("The allowed input variables must not be null.");
     160
     161      if (allowedInputVariables.Except(dataset.DoubleVariables).Except(dataset.StringVariables).Any())
     162        throw new ArgumentException("All allowed input variables must be present in the dataset and of type double or string.");
     163
     164      var variables = dataset.VariableNames.Where(variable => dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable));
     165      var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x)));
    139166      foreach (StringValue x in inputVariables)
    140167        inputVariables.SetItemCheckedState(x, allowedInputVariables.Contains(x.Value));
     
    214241        InputVariables.SetItemCheckedState(inputVariable, variable != null && data.InputVariables.ItemChecked(variable));
    215242      }
    216 
    217       TrainingPartition.Start = TrainingPartition.End = 0;
    218       TestPartition.Start = 0;
    219       TestPartition.End = Dataset.Rows;
    220243    }
    221244  }
Note: See TracChangeset for help on using the changeset viewer.