Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2165


Ignore:
Timestamp:
07/16/09 11:34:22 (15 years ago)
Author:
gkronber
Message:

Removed variable AllowedFeatures in all modeling algorithms. #709

Location:
trunk/sources
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.Boolean/3.3/FunctionLibraryInjector.cs

    r1529 r2165  
    3232  public class FunctionLibraryInjector : OperatorBase {
    3333    private const string TARGETVARIABLE = "TargetVariable";
    34     private const string ALLOWEDFEATURES = "AllowedFeatures";
    3534    private const string OPERATORLIBRARY = "FunctionLibrary";
    3635
     
    4544      : base() {
    4645      AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));
    47       AddVariableInfo(new VariableInfo(ALLOWEDFEATURES, "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));
    4846      AddVariableInfo(new VariableInfo(OPERATORLIBRARY, "Preconfigured default operator library", typeof(GPOperatorLibrary), VariableKind.New));
    4947    }
    5048
    5149    public override IOperation Apply(IScope scope) {
    52       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>(ALLOWEDFEATURES, scope, true);
    5350      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
    5451
    55       // remove the target-variable in case it occures in allowed features
    56       List<IntData> ts = allowedFeatures.FindAll(d => d.Data == targetVariable);
    57       foreach (IntData t in ts) allowedFeatures.Remove(t);
    58 
    5952      InitDefaultOperatorLibrary();
    60 
    61       int[] allowedIndexes = new int[allowedFeatures.Count];
    62       for (int i = 0; i < allowedIndexes.Length; i++) {
    63         allowedIndexes[i] = allowedFeatures[i].Data;
    64       }
    65 
    66       variable.SetConstraints(allowedIndexes);
    6753
    6854      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(OPERATORLIBRARY), operatorLibrary));
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VariableEvaluationImpactCalculator.cs

    r2043 r2165  
    4141
    4242
    43     protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     43    protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    4444      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    4545      IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VariableQualityImpactCalculator.cs

    r2136 r2165  
    4040    }
    4141
    42     protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     42    protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    4343      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    4444      IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs

    r2130 r2165  
    3232namespace HeuristicLab.GP.StructureIdentification {
    3333  public class FunctionLibraryInjector : OperatorBase {
     34    private const string NUMBEROFINPUTVARIABLES = "NumberOfInputVariables";
    3435    private const string FUNCTIONLIBRARY = "FunctionLibrary";
    3536    private const string TARGETVARIABLE = "TargetVariable";
    36     private const string ALLOWEDFEATURES = "AllowedFeatures";
    3737    private const string MINTIMEOFFSET = "MinTimeOffset";
    3838    private const string MAXTIMEOFFSET = "MaxTimeOffset";
     
    7070    public FunctionLibraryInjector()
    7171      : base() {
     72      AddVariableInfo(new VariableInfo(NUMBEROFINPUTVARIABLES, "The number of available input variables", typeof(IntData), VariableKind.In));
    7273      AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));
    73       AddVariableInfo(new VariableInfo(ALLOWEDFEATURES, "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));
    74       AddVariableInfo(new Core.VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), Core.VariableKind.In));
    75       AddVariableInfo(new Core.VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), Core.VariableKind.In));
     74      AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In));
     75      AddVariableInfo(new VariableInfo(MAXTIMEOFFSET, "Maximal time offset for all feature", typeof(IntData), VariableKind.In));
    7676      AddVariableInfo(new VariableInfo(FUNCTIONLIBRARY, "Preconfigured default operator library", typeof(GPOperatorLibrary), VariableKind.New));
    7777
     
    111111      StructId.Variable variable;
    112112      GPOperatorLibrary operatorLibrary;
    113 
    114       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>(ALLOWEDFEATURES, scope, true);
     113      int nInputVariables = GetVariableValue<IntData>(NUMBEROFINPUTVARIABLES, scope, true).Data;
    115114      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
    116115
     
    226225      ConditionalAddOperator(XOR_ALLOWED, operatorLibrary, xor);
    227226
    228       int[] allowedIndexes = new int[allowedFeatures.Count];
    229       for (int i = 0; i < allowedIndexes.Length; i++) {
    230         allowedIndexes[i] = allowedFeatures[i].Data;
    231       }
    232 
    233       variable.SetConstraints(allowedIndexes, minTimeOffset, maxTimeOffset);
    234       differential.SetConstraints(allowedIndexes, minTimeOffset, maxTimeOffset);
     227      variable.SetConstraints(1, nInputVariables, minTimeOffset, maxTimeOffset);
     228      differential.SetConstraints(1, nInputVariables, minTimeOffset, maxTimeOffset);
    235229
    236230      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary));
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Variable.cs

    r1618 r2165  
    154154    }
    155155
    156     public void SetConstraints(int[] allowedIndexes, int minSampleOffset, int maxSampleOffset) {
     156    public void SetConstraints(int minInputIndex, int maxInputIndex, int minSampleOffset, int maxSampleOffset) {
    157157      ConstrainedIntData offset = GetVariableValue<ConstrainedIntData>(OFFSET, null, false);
    158       IntBoundedConstraint rangeConstraint = new IntBoundedConstraint();
     158      IntBoundedConstraint offsetConstraint = new IntBoundedConstraint();
    159159      this.minOffset = minSampleOffset;
    160160      this.maxOffset = maxSampleOffset;
    161       rangeConstraint.LowerBound = minSampleOffset;
    162       rangeConstraint.LowerBoundEnabled = true;
    163       rangeConstraint.LowerBoundIncluded = true;
    164       rangeConstraint.UpperBound = maxSampleOffset;
    165       rangeConstraint.UpperBoundEnabled = true;
    166       rangeConstraint.UpperBoundIncluded = true;
    167       offset.AddConstraint(rangeConstraint);
     161      offsetConstraint.LowerBound = minSampleOffset;
     162      offsetConstraint.LowerBoundEnabled = true;
     163      offsetConstraint.LowerBoundIncluded = true;
     164      offsetConstraint.UpperBound = maxSampleOffset;
     165      offsetConstraint.UpperBoundEnabled = true;
     166      offsetConstraint.UpperBoundIncluded = true;
     167      offset.AddConstraint(offsetConstraint);
    168168
    169169      ConstrainedIntData index = GetVariableValue<ConstrainedIntData>(INDEX, null, false);
    170       Array.Sort(allowedIndexes);
    171       minIndex = allowedIndexes[0]; maxIndex = allowedIndexes[allowedIndexes.Length - 1];
    172       List<IConstraint> constraints = new List<IConstraint>();
    173       int start = allowedIndexes[0];
    174       int prev = start;
    175       for(int i = 1; i < allowedIndexes.Length; i++) {
    176         if(allowedIndexes[i] != prev + 1) {
    177           IntBoundedConstraint lastRange = new IntBoundedConstraint();
    178           lastRange.LowerBound = start;
    179           lastRange.LowerBoundEnabled = true;
    180           lastRange.LowerBoundIncluded = true;
    181           lastRange.UpperBound = prev;
    182           lastRange.UpperBoundEnabled = true;
    183           lastRange.UpperBoundIncluded = true;
    184           constraints.Add(lastRange);
    185           start = allowedIndexes[i];
    186           prev = start;
    187         }
    188         prev = allowedIndexes[i];
    189       }
    190       IntBoundedConstraint range = new IntBoundedConstraint();
    191       range.LowerBound = start;
    192       range.LowerBoundEnabled = true;
    193       range.LowerBoundIncluded = true;
    194       range.UpperBound = prev;
    195       range.UpperBoundEnabled = true;
    196       range.UpperBoundIncluded = true;
    197       constraints.Add(range);
    198       if(constraints.Count > 1) {
    199         OrConstraint or = new OrConstraint();
    200         foreach(IConstraint c in constraints) or.Clauses.Add(c);
    201         index.AddConstraint(or);
    202       } else {
    203         index.AddConstraint(constraints[0]);
    204       }
     170      IntBoundedConstraint indexConstraint = new IntBoundedConstraint();
     171      minIndex = minInputIndex;
     172      maxIndex = maxInputIndex;
     173      indexConstraint.LowerBound = minInputIndex;
     174      indexConstraint.LowerBoundEnabled = true;
     175      indexConstraint.LowerBoundIncluded = true;
     176      indexConstraint.UpperBound = maxInputIndex;
     177      indexConstraint.UpperBoundEnabled = true;
     178      indexConstraint.UpperBoundIncluded = true;
     179      index.AddConstraint(indexConstraint);
    205180
    206181      SetupInitialization();
  • trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegressionOperator.cs

    r2154 r2165  
    3838      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
    3939      AddVariableInfo(new VariableInfo("SamplesEnd", "End index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
    40       AddVariableInfo(new VariableInfo("AllowedFeatures", "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));
    4140      AddVariableInfo(new VariableInfo("LinearRegressionModel", "Formula that was calculated by linear regression", typeof(IFunctionTree), VariableKind.Out | VariableKind.New));
    4241      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.New | VariableKind.Out));
     
    4948      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
    5049      int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data;
    51       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);
    52       List<int> allowedRows = CalculateAllowedRows(dataset, allowedFeatures, targetVariable, start, end);
     50      List<int> allowedRows = CalculateAllowedRows(dataset, targetVariable, start, end);
     51      List<int> allowedColumns = CalculateAllowedColumns(dataset, targetVariable, start, end);
    5352
    54       List<IntData> disallowedFeatures = new List<IntData>();
    55       foreach (IntData allowedFeature in allowedFeatures) {
    56         if (IsAlmost(dataset.GetMinimum(allowedFeature.Data, start, end), 0.0) &&
    57             IsAlmost(dataset.GetMaximum(allowedFeature.Data, start, end), 0.0))
    58           disallowedFeatures.Add(allowedFeature);
    59       }
    60       foreach (IntData disallowedFeature in disallowedFeatures)
    61         allowedFeatures.Remove(disallowedFeature);
    62 
    63       double[,] inputMatrix = PrepareInputMatrix(dataset, allowedFeatures, allowedRows);
     53      double[,] inputMatrix = PrepareInputMatrix(dataset, allowedColumns, allowedRows);
    6454      double[] targetVector = PrepareTargetVector(dataset, targetVariable, allowedRows);
    6555      double[] coefficients = CalculateCoefficients(inputMatrix, targetVector);
    66       IFunctionTree tree = CreateModel(coefficients, allowedFeatures);
     56      IFunctionTree tree = CreateModel(coefficients, allowedColumns);
    6757
    6858      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("LinearRegressionModel"), tree));
     
    7666    }
    7767
    78     private IFunctionTree CreateModel(double[] coefficients, ItemList<IntData> allowedFeatures) {
     68    private IFunctionTree CreateModel(double[] coefficients, List<int> allowedColumns) {
    7969      IFunctionTree root = new Addition().GetTreeNode();
    8070      IFunctionTree actNode = root;
     
    8474      for (int i = 0; i < coefficients.Length - 1; i++) {
    8575        v = new GP.StructureIdentification.Variable();
    86         v.GetVariable(GP.StructureIdentification.Variable.INDEX).Value = new ConstrainedIntData(allowedFeatures[i].Data);
     76        v.GetVariable(GP.StructureIdentification.Variable.INDEX).Value = new ConstrainedIntData(allowedColumns[i]);
    8777        v.GetVariable(GP.StructureIdentification.Variable.WEIGHT).Value = new ConstrainedDoubleData(coefficients[i]);
    8878        v.GetVariable(GP.StructureIdentification.Variable.OFFSET).Value = new ConstrainedIntData(0);
     
    9080      }
    9181      GP.StructureIdentification.Constant c = new Constant();
    92       c.GetVariable(GP.StructureIdentification.Constant.VALUE).Value = new ConstrainedDoubleData(coefficients[coefficients.Length - 1] * 1.0);
     82      c.GetVariable(GP.StructureIdentification.Constant.VALUE).Value = new ConstrainedDoubleData(coefficients[coefficients.Length - 1]);
    9383      nodes.Enqueue(c.GetTreeNode());
    9484
     
    10797      double[] weights = new double[targetVector.Length];
    10898      double[] coefficients = new double[inputMatrix.GetLength(1)];
    109       for(int i=0;i<weights.Length;i++) weights[i] = 1.0;
     99      for (int i = 0; i < weights.Length; i++) weights[i] = 1.0;
    110100      // call external ALGLIB solver
    111101      leastsquares.buildgeneralleastsquares(ref targetVector, ref weights, ref inputMatrix, inputMatrix.GetLength(0), inputMatrix.GetLength(1), ref coefficients);
     
    115105
    116106    //returns list of valid row indexes (rows without NaN values)
    117     private List<int> CalculateAllowedRows(Dataset dataset, ItemList<IntData> allowedFeatures, int targetVariable, int start, int end) {
     107    private List<int> CalculateAllowedRows(Dataset dataset, int targetVariable, int start, int end) {
    118108      List<int> allowedRows = new List<int>();
    119109      bool add;
    120110      for (int row = start; row < end; row++) {
    121111        add = true;
    122         for (int col = 0; col < allowedFeatures.Count && add == true; col++) {
    123           if (double.IsNaN(dataset.GetValue(row, allowedFeatures[col].Data)) ||
     112        for (int col = 0; col < dataset.Columns && add == true; col++) {
     113          if (double.IsNaN(dataset.GetValue(row, col)) ||
    124114              double.IsNaN(dataset.GetValue(row, targetVariable)))
    125115            add = false;
     
    132122    }
    133123
    134     private double[,] PrepareInputMatrix(Dataset dataset, ItemList<IntData> allowedFeatures, List<int> allowedRows) {
     124    //returns list of valid column indexes (columns which contain at least one non-zero value)
     125    private List<int> CalculateAllowedColumns(Dataset dataset, int targetVariable, int start, int end) {
     126      List<int> allowedColumns = new List<int>();
     127      for (int i = 0; i < dataset.Columns; i++) {
     128        if (i == targetVariable) continue;
     129        if (!IsAlmost(dataset.GetMinimum(i, start, end), 0.0) ||
     130            !IsAlmost(dataset.GetMaximum(i, start, end), 0.0))
     131          allowedColumns.Add(i);
     132      }
     133      return allowedColumns;
     134    }
     135
     136    private double[,] PrepareInputMatrix(Dataset dataset, List<int> allowedColumns, List<int> allowedRows) {
    135137      int rowCount = allowedRows.Count;
    136       double[,] matrix = new double[rowCount, allowedFeatures.Count + 1];
    137       for (int col = 0; col < allowedFeatures.Count; col++) {
     138      double[,] matrix = new double[rowCount, allowedColumns.Count + 1];
     139      for (int col = 0; col < allowedColumns.Count; col++) {
    138140        for (int row = 0; row < allowedRows.Count; row++)
    139           matrix[row, col] = dataset.GetValue(allowedRows[row], allowedFeatures[col].Data);
     141          matrix[row, col] = dataset.GetValue(allowedRows[row], allowedColumns[col]);
    140142      }
    141143      //add constant 1.0 in last column
    142144      for (int i = 0; i < rowCount; i++)
    143         matrix[i, allowedFeatures.Count] = constant;
     145        matrix[i, allowedColumns.Count] = constant;
    144146      return matrix;
    145147    }
  • trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjector.cs

    r2162 r2165  
    7777
    7878      AddVariableInfo(new VariableInfo("MaxNumberOfTrainingSamples", "Maximal number of training samples to use (optional)", typeof(IntData), VariableKind.In));
     79      AddVariableInfo(new VariableInfo("NumberOfInputVariables", "The number of available input variables", typeof(IntData), VariableKind.New));
    7980    }
    8081
     
    9798      Dataset scopeDataset = CreateNewDataset(operatorDataset, targetVariable, operatorAllowedFeatures);
    9899
    99       ItemList<IntData> allowedFeatures = new ItemList<IntData>();
    100       allowedFeatures.AddRange(Enumerable.Range(1, scopeDataset.Columns -1 ).Select(x=>new IntData(x)));
    101 
    102100      scope.AddVariable(new Variable("Dataset", scopeDataset));
    103       scope.AddVariable(new Variable("AllowedFeatures", allowedFeatures));
    104101      scope.AddVariable(new Variable("TargetVariable", new IntData(0)));
     102      scope.AddVariable(new Variable("NumberOfInputVariables", new IntData(scopeDataset.Columns - 1)));
    105103
    106104      int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableEvaluationImpactCalculator.cs

    r2136 r2165  
    5858    }
    5959
    60     protected override double[] CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
    61       return GetOutputs(scope, dataset, targetVariable, allowedFeatures, start, end);
     60    protected override double[] CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
     61      return GetOutputs(scope, dataset, targetVariable, start, end);
    6262    }
    6363
     
    7575    }
    7676
    77     protected abstract double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end);
     77    protected abstract double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end);
    7878  }
    7979}
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableImpactCalculatorBase.cs

    r2043 r2165  
    3434
    3535    public override string Description {
    36       get { return @"Calculates the impact of all allowed input variables on the model."; }
     36      get { return @"Calculates the impact of all input variables on the model."; }
    3737    }
    3838
     
    4747      AddVariableInfo(new VariableInfo("Dataset", "Dataset", typeof(Dataset), VariableKind.In));
    4848      AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(IntData), VariableKind.In));
    49       AddVariableInfo(new VariableInfo("AllowedFeatures", "Indexes of allowed input variables", typeof(ItemList<IntData>), VariableKind.In));
    5049      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.In));
    5150      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "TrainingSamplesEnd", typeof(IntData), VariableKind.In));
     
    5453
    5554    public override IOperation Apply(IScope scope) {
    56       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);
    5755      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    5856      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
     
    6159      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    6260
    63       T referenceValue = CalculateValue(scope, dataset, targetVariable, allowedFeatures, start, end);
    64       double[] impacts = new double[allowedFeatures.Count];
     61      T referenceValue = CalculateValue(scope, dataset, targetVariable, start, end);
     62      double[] impacts = new double[dataset.Columns];
    6563
    66       for (int i = 0; i < allowedFeatures.Count && !abortRequested; i++) {
    67         int currentVariable = allowedFeatures[i].Data;
    68         var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable, CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end);
    69         T newValue = CalculateValue(scope, dirtyDataset, targetVariable, allowedFeatures, start, end);
    70         impacts[i] = CalculateImpact(referenceValue, newValue);
    71         ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end);
     64      for (int i = 0; i < impacts.Length && !abortRequested; i++) {
     65        int currentVariable = i;
     66        if (currentVariable != targetVariable) {
     67          var oldValues = ReplaceVariableValues(dirtyDataset, currentVariable, CalculateNewValues(dirtyDataset, currentVariable, start, end), start, end);
     68          T newValue = CalculateValue(scope, dirtyDataset, targetVariable, start, end);
     69          impacts[i] = CalculateImpact(referenceValue, newValue);
     70          ReplaceVariableValues(dirtyDataset, currentVariable, oldValues, start, end);
     71        }
    7272      }
    7373
     
    7676
    7777        ItemList variableImpacts = new ItemList();
    78         for (int i = 0; i < allowedFeatures.Count; i++) {
    79           int currentVariable = allowedFeatures[i].Data;
    80           ItemList row = new ItemList();
    81           row.Add(new StringData(dataset.GetVariableName(currentVariable)));
    82           row.Add(new DoubleData(impacts[i]));
    83           variableImpacts.Add(row);
     78        for (int i = 0; i < impacts.Length; i++) {
     79          int currentVariable = i;
     80          if (currentVariable != targetVariable) {
     81            ItemList row = new ItemList();
     82            row.Add(new StringData(dataset.GetVariableName(currentVariable)));
     83            row.Add(new DoubleData(impacts[i]));
     84            variableImpacts.Add(row);
     85          }
    8486        }
    8587
     
    9193    }
    9294
    93     protected abstract T CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end);
     95    protected abstract T CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end);
    9496
    9597    protected abstract double CalculateImpact(T referenceValue, T newValue);
  • trunk/sources/HeuristicLab.Modeling/3.2/VariableQualityImpactCalculator.cs

    r2043 r2165  
    4343    }
    4444
    45     protected override double CalculateValue(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
    46       return CalculateQuality(scope, dataset, targetVariable, allowedFeatures, start, end);
     45    protected override double CalculateValue(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
     46      return CalculateQuality(scope, dataset, targetVariable, start, end);
    4747    }
    4848
    49     protected abstract double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end);
     49    protected abstract double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end);
    5050  }
    5151}
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SVMHelper.cs

    r2148 r2165  
    99namespace HeuristicLab.SupportVectorMachines {
    1010  public class SVMHelper {
    11     public static SVM.Problem CreateSVMProblem(Dataset dataset, ItemList<IntData> allowedFeatures, int targetVariable, int start, int end) {
     11    public static SVM.Problem CreateSVMProblem(Dataset dataset, int targetVariable, int start, int end) {
    1212      int rowCount = end - start;
    13       double[] samples = dataset.Samples;
     13      List<int> skippedFeatures = new List<int>();
     14      for (int i = 0; i < dataset.Columns; i++) {
     15        if (i != targetVariable) {
     16          if (dataset.GetRange(i, start, end) == 0)
     17            skippedFeatures.Add(i);
     18        }
     19      }
    1420
    15       List<int> skippedFeatures = new List<int>();
    16       for (int i = 0; i < allowedFeatures.Count; i++) {
    17         if (dataset.GetRange(allowedFeatures[i].Data, start, end) == 0)
    18           skippedFeatures.Add(i);
    19       }
     21      int maxColumns = dataset.Columns - skippedFeatures.Count();
    2022
    2123      double[] targetVector = new double[rowCount];
    2224      for (int i = 0; i < rowCount; i++) {
    23         double value = samples[(start + i) * dataset.Columns + targetVariable];
     25        double value = dataset.GetValue(start + i, targetVariable);
    2426          targetVector[i] = value;
    2527      }
     
    3133      for (int row = 0; row < rowCount; row++) {
    3234        tempRow = new List<SVM.Node>();
    33         for (int col = 0; col < allowedFeatures.Count; col++) {
    34           if (!skippedFeatures.Contains(col)) {
    35             double value = samples[(start + row) * dataset.Columns + allowedFeatures[col].Data];
     35        for (int col = 0; col < dataset.Columns; col++) {
     36          if (!skippedFeatures.Contains(col) && col!=targetVariable) {
     37            double value = dataset.GetValue(start + row, col);
    3638            if (!double.IsNaN(value))
    37               tempRow.Add(new SVM.Node(allowedFeatures[col].Data, value));
     39              tempRow.Add(new SVM.Node(col, value));
    3840          }
    3941        }
    40         if (!double.IsNaN(samples[(start + row) * dataset.Columns + targetVariable])) {
     42        if (!double.IsNaN(dataset.GetValue(start + row, targetVariable))) {
    4143          nodes[addedRows] = tempRow.ToArray();
    4244          addedRows++;
     
    4446      }
    4547
    46       return new SVM.Problem(targetVector.Length, targetVector, nodes, allowedFeatures.Max(x => x.Data));
     48      return new SVM.Problem(targetVector.Length, targetVector, nodes, maxColumns);
    4749    }
    4850  }
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorCreator.cs

    r2163 r2165  
    3939      //Dataset infos
    4040      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    41       AddVariableInfo(new VariableInfo("AllowedFeatures", "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));
    4241      AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
    4342      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    6766      abortRequested = false;
    6867      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    69       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);
    7068      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    7169      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
     
    8381      parameter.Gamma = GetVariableValue<DoubleData>("SVMGamma", scope, true).Data;
    8482
    85       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     83      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end);
    8684      SVM.RangeTransform rangeTransform = SVM.Scaling.DetermineRange(problem);
    8785      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, rangeTransform);
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorEvaluator.cs

    r2148 r2165  
    3535      //Dataset infos
    3636      AddVariableInfo(new VariableInfo("Dataset", "Dataset with all samples on which to apply the function", typeof(Dataset), VariableKind.In));
    37       AddVariableInfo(new VariableInfo("AllowedFeatures", "List of indexes of allowed features", typeof(ItemList<IntData>), VariableKind.In));
    3837      AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
    3938      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    4746    public override IOperation Apply(IScope scope) {
    4847      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
    49       ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>("AllowedFeatures", scope, true);
    5048      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
    5149      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
     
    5351
    5452      SVMModel modelData = GetVariableValue<SVMModel>("SVMModel", scope, true);
    55       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     53      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end);
    5654      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, modelData.RangeTransform);
    5755
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableEvaluationImpactCalculator.cs

    r2043 r2165  
    3838
    3939
    40     protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     40    protected override double[] GetOutputs(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    4141      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
    42       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     42      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end);
    4343      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform);
    4444
  • trunk/sources/HeuristicLab.SupportVectorMachines/3.2/VariableQualityImpactCalculator.cs

    r2136 r2165  
    3737    }
    3838
    39     protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, ItemList<IntData> allowedFeatures, int start, int end) {
     39    protected override double CalculateQuality(IScope scope, Dataset dataset, int targetVariable, int start, int end) {
    4040      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
    41       SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, allowedFeatures, targetVariable, start, end);
     41      SVM.Problem problem = SVMHelper.CreateSVMProblem(dataset, targetVariable, start, end);
    4242      SVM.Problem scaledProblem = SVM.Scaling.Scale(problem, model.RangeTransform);
    4343
Note: See TracChangeset for help on using the changeset viewer.