Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/09/10 17:28:32 (15 years ago)
Author:
gkronber
Message:

Added first version of architecture altering operators for ADFs. #290 (Implement ADFs)

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3
Files:
3 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj

    r3265 r3294  
    8585    <None Include="HeuristicLabProblemsDataAnalysisRegressionPlugin.cs.frame" />
    8686    <None Include="Properties\AssemblyInfo.frame" />
     87    <Compile Include="RegressionProblemDataView.cs">
     88      <SubType>UserControl</SubType>
     89    </Compile>
     90    <Compile Include="RegressionProblemDataView.Designer.cs">
     91      <DependentUpon>RegressionProblemDataView.cs</DependentUpon>
     92    </Compile>
     93    <Compile Include="RegressionProblemData.cs" />
    8794    <Compile Include="CsvFileParser.cs" />
    8895    <Compile Include="DataFormatException.cs" />
     
    96103    <Compile Include="HeuristicLabProblemsDataAnalysisRegressionPlugin.cs" />
    97104    <Compile Include="Properties\AssemblyInfo.cs" />
    98     <Compile Include="Symbolic\SymbolicRegressionProblemView.cs">
    99       <SubType>UserControl</SubType>
    100     </Compile>
    101     <Compile Include="Symbolic\SymbolicRegressionProblemView.Designer.cs">
    102       <DependentUpon>SymbolicRegressionProblemView.cs</DependentUpon>
    103     </Compile>
    104105    <Compile Include="Symbolic\Symbols\Constant.cs" />
    105106    <Compile Include="Symbolic\Symbols\ConstantTreeNode.cs" />
    106107    <Compile Include="Symbolic\Symbols\Variable.cs" />
    107108    <Compile Include="Symbolic\Symbols\VariableTreeNode.cs" />
    108     <Compile Include="RegressionProblemView.cs">
    109       <SubType>UserControl</SubType>
    110     </Compile>
    111     <Compile Include="RegressionProblemView.Designer.cs">
    112       <DependentUpon>RegressionProblemView.cs</DependentUpon>
    113     </Compile>
    114109  </ItemGroup>
    115110  <ItemGroup>
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/RegressionProblem.cs

    r3264 r3294  
    3737  [StorableClass]
    3838  public class RegressionProblem : ParameterizedNamedItem {
     39    private const string RegressionProblemDataParameterName = "RegressionProblemData";
    3940    public override Image ItemImage {
    4041      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
     
    4243
    4344    #region Parameter Properties
    44     public ValueParameter<Dataset> DatasetParameter {
    45       get { return (ValueParameter<Dataset>)Parameters["Dataset"]; }
    46     }
    47     public ValueParameter<StringValue> TargetVariableParameter {
    48       get { return (ValueParameter<StringValue>)Parameters["TargetVariable"]; }
    49     }
    50     public ValueParameter<ItemList<StringValue>> InputVariablesParameter {
    51       get { return (ValueParameter<ItemList<StringValue>>)Parameters["InputVariables"]; }
    52     }
    53     public ValueParameter<IntValue> TrainingSamplesStartParameter {
    54       get { return (ValueParameter<IntValue>)Parameters["TrainingSamplesStart"]; }
    55     }
    56     public ValueParameter<IntValue> TrainingSamplesEndParameter {
    57       get { return (ValueParameter<IntValue>)Parameters["TrainingSamplesEnd"]; }
    58     }
    59     public OptionalValueParameter<IntValue> ValidationSamplesStartParameter {
    60       get { return (OptionalValueParameter<IntValue>)Parameters["ValidationSamplesStart"]; }
    61     }
    62     public OptionalValueParameter<IntValue> ValidationSamplesEndParameter {
    63       get { return (OptionalValueParameter<IntValue>)Parameters["ValidationSamplesEnd"]; }
    64     }
    65     public ValueParameter<IntValue> TestSamplesStartParameter {
    66       get { return (ValueParameter<IntValue>)Parameters["TestSamplesStart"]; }
    67     }
    68     public ValueParameter<IntValue> TestSamplesEndParameter {
    69       get { return (ValueParameter<IntValue>)Parameters["TestSamplesEnd"]; }
     45    public ValueParameter<RegressionProblemData> RegressionProblemDataParameter {
     46      get { return (ValueParameter<RegressionProblemData>)Parameters[RegressionProblemDataParameterName]; }
    7047    }
    7148    #endregion
    7249    #region properties
    73     public Dataset Dataset {
    74       get { return DatasetParameter.Value; }
    75       set { DatasetParameter.Value = value; }
    76     }
    77     public StringValue TargetVariable {
    78       get { return TargetVariableParameter.Value; }
    79       set { TargetVariableParameter.Value = value; }
    80     }
    81     public ItemList<StringValue> InputVariables {
    82       get { return InputVariablesParameter.Value; }
    83       set { InputVariablesParameter.Value = value; }
    84     }
    85     public IntValue TrainingSamplesStart {
    86       get { return TrainingSamplesStartParameter.Value; }
    87       set { TrainingSamplesStartParameter.Value = value; }
    88     }
    89     public IntValue TrainingSamplesEnd {
    90       get { return TrainingSamplesEndParameter.Value; }
    91       set { TrainingSamplesEndParameter.Value = value; }
    92     }
    93     public IntValue ValidationSamplesStart {
    94       get { return ValidationSamplesStartParameter.Value; }
    95       set { ValidationSamplesStartParameter.Value = value; }
    96     }
    97     public IntValue ValidationSamplesEnd {
    98       get { return ValidationSamplesEndParameter.Value; }
    99       set { ValidationSamplesEndParameter.Value = value; }
    100     }
    101     public IntValue TestSamplesStart {
    102       get { return TestSamplesStartParameter.Value; }
    103       set { TestSamplesStartParameter.Value = value; }
    104     }
    105     public IntValue TestSamplesEnd {
    106       get { return TestSamplesEndParameter.Value; }
    107       set { TestSamplesEndParameter.Value = value; }
     50    public RegressionProblemData RegressionProblemData {
     51      get { return RegressionProblemDataParameter.Value; }
     52      set { RegressionProblemDataParameter.Value = value; }
    10853    }
    10954    #endregion
     
    11156    public RegressionProblem()
    11257      : base() {
    113       var dataset = new Dataset();
    114       // TODO: wiring for sanity checks of parameter values based on dataset (target & input variables available?, training and test partition correct?...)
    115       Parameters.Add(new ValueParameter<Dataset>("Dataset", "The data set containing data to be analyzer.", dataset));
    116       Parameters.Add(new ValueParameter<StringValue>("TargetVariable", "The target variable for which a regression model should be created.", new StringValue()));
    117       Parameters.Add(new ValueParameter<ItemList<StringValue>>("InputVariables", "The input variables (regressors) that are available for the regression model.", new ItemList<StringValue>()));
    118       Parameters.Add(new ValueParameter<IntValue>("TrainingSamplesStart", "The start index of the training partition.", new IntValue()));
    119       Parameters.Add(new ValueParameter<IntValue>("TrainingSamplesEnd", "The end index of the training partition.", new IntValue()));
    120       Parameters.Add(new OptionalValueParameter<IntValue>("ValidationSamplesStart", "The start index of the validation partition."));
    121       Parameters.Add(new OptionalValueParameter<IntValue>("ValidationSamplesEnd", "The end index of the validation partition."));
    122       Parameters.Add(new ValueParameter<IntValue>("TestSamplesStart", "The start index of the test partition.", new IntValue()));
    123       Parameters.Add(new ValueParameter<IntValue>("TestSamplesEnd", "The end index of the test partition.", new IntValue()));
     58      Parameters.Add(new ValueParameter<RegressionProblemData>(RegressionProblemDataParameterName, "The data set, target variable and input variables of the regression problem.", new RegressionProblemData()));
    12459    }
    12560
    12661    [StorableConstructor]
    12762    private RegressionProblem(bool deserializing) : base() { }
    128 
    129     public virtual void ImportFromFile(string fileName) {
    130       var csvFileParser = new CsvFileParser();
    131       csvFileParser.Parse(fileName);
    132       Name = "Regression Problem (imported from " + Path.GetFileName(fileName);
    133       Dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
    134       Dataset.Name = Path.GetFileName(fileName);
    135       TargetVariable = new StringValue(Dataset.VariableNames.First());
    136       InputVariables = new ItemList<StringValue>(Dataset.VariableNames.Skip(1).Select(s => new StringValue(s)));
    137       TrainingSamplesStart = new IntValue(0);
    138       TrainingSamplesEnd = new IntValue(csvFileParser.Rows);
    139       TestSamplesStart = new IntValue(0);
    140       TestSamplesEnd = new IntValue(csvFileParser.Rows);
    141     }
    14263  }
    14364}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ArithmeticExpressionGrammar.cs

    r3269 r3294  
    3232namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
    3333  [StorableClass]
    34   public class ArithmeticExpressionGrammar : NamedItemCollection<Symbol>, ISymbolicExpressionGrammar {
    35 
     34  [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")]
     35  public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar {
     36    [Storable]
    3637    private List<string> variableNames = new List<string>();
    3738    public IEnumerable<string> VariableNames {
     
    3940      set {
    4041        variableNames = new List<string>(value);
    41         var variable = (HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable)allSymbols[5];
    42         variable.VariableNames = new ItemList<HeuristicLab.Data.StringValue>(variableNames.Select(x => new StringValue(x)));
     42        variableSymbol.VariableNames = variableNames;
    4343      }
    4444    }
    4545
     46    [Storable]
     47    private HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable variableSymbol;
     48
    4649    public ArithmeticExpressionGrammar()
    47       : this(allSymbols) {
     50      : base(0, 0, 0, 0) {
     51      Initialize();
    4852    }
    4953
    50     public ArithmeticExpressionGrammar(IEnumerable<Symbol> symbols)
    51       : base(symbols) {
    52       allSymbols = new List<Symbol>(symbols);
    53     }
     54    private void Initialize() {
     55      var add = new Addition();
     56      var sub = new Subtraction();
     57      var mul = new Multiplication();
     58      var div = new Division();
     59      var constant = new Constant();
     60      variableSymbol = new HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable();
    5461
    55     #region ISymbolicExpressionGrammar Members
    56     [Storable]
    57     private StartSymbol startSymbol = new StartSymbol();
    58     public Symbol StartSymbol {
    59       get { return startSymbol; }
    60     }
    61 
    62     [Storable]
    63     private static List<Symbol> allSymbols = new List<Symbol>() {
    64       new Addition(),
    65       new Subtraction(),
    66       new Multiplication(),
    67       new Division(),
    68       new Constant(),
    69       new HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable()
    70     };
    71     [Storable]
    72     private Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>> allowedSymbols = new Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>>() {
    73       {
    74         typeof(StartSymbol),
    75         new Dictionary<int, IEnumerable<Symbol>>()
    76         {
    77           { 0, allSymbols},
    78         }
    79       },      {
    80         typeof(Addition),
    81         new Dictionary<int, IEnumerable<Symbol>>()
    82         {
    83           { 0, allSymbols},
    84           { 1, allSymbols}
    85         }
    86       },
    87       {
    88         typeof(Subtraction),
    89         new Dictionary<int, IEnumerable<Symbol>>()
    90         {
    91           { 0, allSymbols},
    92           { 1, allSymbols}
    93         }
    94       },
    95       {
    96         typeof(Multiplication),
    97         new Dictionary<int, IEnumerable<Symbol>>()
    98         {
    99           { 0, allSymbols},
    100           { 1, allSymbols}
    101         }
    102       },
    103       {
    104         typeof(Division),
    105         new Dictionary<int, IEnumerable<Symbol>>()
    106         {
    107           { 0, allSymbols},
    108           { 1, allSymbols}
    109         }
    110       },
    111     };
    112     public IEnumerable<Symbol> AllowedSymbols(Symbol parent, int argumentIndex) {
    113       return allowedSymbols[parent.GetType()][argumentIndex];
    114     }
    115 
    116     [Storable]
    117     private Dictionary<Type, int> minLength = new Dictionary<Type, int>() {
    118       {typeof(StartSymbol), 1},
    119       {typeof(Addition), 3},
    120       {typeof(Subtraction), 3},
    121       {typeof(Multiplication), 4},
    122       {typeof(Division), 4},
    123       {typeof(Constant), 1},
    124       {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 1},
    125     };
    126     public int MinimalExpressionLength(Symbol start) {
    127       return minLength[start.GetType()];
    128     }
    129 
    130     [Storable]
    131     private Dictionary<Type, int> maxLength = new Dictionary<Type, int>() {
    132       {typeof(StartSymbol), int.MaxValue},
    133       {typeof(Addition), int.MaxValue},
    134       {typeof(Subtraction), int.MaxValue},
    135       {typeof(Multiplication), int.MaxValue},
    136       {typeof(Division), int.MaxValue},
    137       {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 1},
    138       {typeof(Constant), 1},
    139     };
    140     public int MaximalExpressionLength(Symbol start) {
    141       return maxLength[start.GetType()];
    142     }
    143 
    144     [Storable]
    145     private Dictionary<Type, int> minDepth = new Dictionary<Type, int>() {
    146       {typeof(StartSymbol), 1},
    147       {typeof(Addition), 1},
    148       {typeof(Subtraction), 1},
    149       {typeof(Multiplication), 1},
    150       {typeof(Division), 1},
    151       {typeof(Constant), 0},
    152       {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 0}
    153     };
    154     public int MinimalExpressionDepth(Symbol start) {
    155       return minDepth[start.GetType()];
    156     }
    157 
    158     [Storable]
    159     private Dictionary<Type, int> subTrees = new Dictionary<Type, int>() {
    160       {typeof(StartSymbol), 1},
    161       {typeof(Addition), 2},
    162       {typeof(Subtraction), 2},
    163       {typeof(Multiplication), 2},
    164       {typeof(Division), 2},
    165       {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 0},
    166       {typeof(Constant), 0},
    167     };
    168     public int MinSubTrees(Symbol start) {
    169       return subTrees[start.GetType()];
    170     }
    171     public int MaxSubTrees(Symbol start) {
    172       return subTrees[start.GetType()];
    173     }
    174 
    175     #endregion
    176 
    177     #region ISymbolicExpressionGrammar Members
     62      var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol };
     63      var functionSymbols = new List<Symbol>() { add, sub, mul, div };
     64      allSymbols.ForEach(s => AddAllowedSymbols(StartSymbol, 0, s));
    17865
    17966
    180     public bool IsValidExpression(SymbolicExpressionTree expression) {
    181       if (expression.Root.Symbol != StartSymbol) return false;
    182       return IsValidExpression(expression.Root);
    183     }
    184 
    185     #endregion
    186 
    187     private bool IsValidExpression(SymbolicExpressionTreeNode root) {
    188       if (root.SubTrees.Count < MinSubTrees(root.Symbol)) return false;
    189       if (root.SubTrees.Count > MaxSubTrees(root.Symbol)) return false;
    190       for (int i = 0; i < root.SubTrees.Count; i++) {
    191         if (!AllowedSymbols(root.Symbol, i).Contains(root.SubTrees[i].Symbol)) return false;
    192         if (!IsValidExpression(root.SubTrees[i])) return false;
     67      SetMinSubTreeCount(constant, 0);
     68      SetMaxSubTreeCount(constant, 0);
     69      SetMinSubTreeCount(variableSymbol, 0);
     70      SetMaxSubTreeCount(variableSymbol, 0);
     71      int maxSubTrees = 3;
     72      foreach (var functionSymbol in functionSymbols) {
     73        SetMinSubTreeCount(functionSymbol, 1);
     74        SetMaxSubTreeCount(functionSymbol, maxSubTrees);
     75        foreach (var childSymbol in allSymbols) {
     76          for (int argumentIndex = 0; argumentIndex < maxSubTrees; argumentIndex++) {
     77            AddAllowedSymbols(functionSymbol, argumentIndex, childSymbol);
     78          }
     79        }
    19380      }
    194       return true;
    19581    }
    19682  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ISymbolicRegressionEvaluator.cs

    r3253 r3294  
    3737  public interface ISymbolicRegressionEvaluator : ISingleObjectiveEvaluator {
    3838    ILookupParameter<SymbolicExpressionTree> FunctionTreeParameter { get; }
    39     ILookupParameter<Dataset> DatasetParameter { get; }
    40     ILookupParameter<StringValue> TargetVariableParameter { get; }
    41     ILookupParameter<IntValue> SamplesStartParameter { get; }
    42     ILookupParameter<IntValue> SamplesEndParameter { get; }
     39    ILookupParameter<RegressionProblemData> RegressionProblemDataParameter { get; }
    4340    ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter { get; }
    4441  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SimpleArithmeticExpressionEvaluator.cs

    r3269 r3294  
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
    32   /// <summary>
    33   /// Evaluates FunctionTrees recursively by interpretation of the function symbols in each node.
    34   /// Simple unoptimized code, arithmetic expressions only.
    35   /// Not thread-safe!
    36   /// </summary>
    3732  [StorableClass]
    3833  [Item("SimpleArithmeticExpressionEvaluator", "Default evaluator for arithmetic symbolic expression trees.")]
    39   public class SimpleArithmeticExpressionEvaluator : GeneralSymbolicExpressionTreeEvaluator {
     34  public class SimpleArithmeticExpressionEvaluator {
    4035    private Dataset dataset;
    4136    private int row;
     37    private Instruction[] code;
     38    private int pc;
    4239    public IEnumerable<double> EstimatedValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
    4340      this.dataset = dataset;
     41      var compiler = new SymbolicExpressionTreeCompiler();
     42      code = compiler.Compile(tree);
    4443      foreach (var row in rows) {
    4544        this.row = row;
    46         var estimatedValue = Evaluate(tree.Root.SubTrees[0]);
     45        pc = 0;
     46        var estimatedValue = Evaluate();
    4747        if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0;
    4848        else yield return estimatedValue;
     
    5050    }
    5151
    52     public override double Evaluate(SymbolicExpressionTreeNode node) {
    53       if (node.Symbol is HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable) {
    54         var variableTreeNode = node as VariableTreeNode;
    55         return dataset[row, dataset.VariableIndex(variableTreeNode.VariableName)] * variableTreeNode.Weight;
    56       } else if (node.Symbol is Constant) {
    57         return ((ConstantTreeNode)node).Value;
    58       } else {
    59         return base.Evaluate(node);
     52    public double Evaluate() {
     53      var currentInstr = code[pc++];
     54      switch (currentInstr.symbol) {
     55        case CodeSymbol.Add: {
     56            double s = 0.0;
     57            for (int i = 0; i < currentInstr.nArguments; i++) {
     58              s += Evaluate();
     59            }
     60            return s;
     61          }
     62        case CodeSymbol.Sub: {
     63            double s = Evaluate();
     64            for (int i = 1; i < currentInstr.nArguments; i++) {
     65              s -= Evaluate();
     66            }
     67            return s;
     68          }
     69        case CodeSymbol.Mul: {
     70            double p = Evaluate();
     71            for (int i = 1; i < currentInstr.nArguments; i++) {
     72              p *= Evaluate();
     73            }
     74            return p;
     75          }
     76        case CodeSymbol.Div: {
     77            double p = Evaluate();
     78            for (int i = 1; i < currentInstr.nArguments; i++) {
     79              p /= Evaluate();
     80            }
     81            return p;
     82          }
     83        case CodeSymbol.Dynamic: {
     84            if (currentInstr.dynamicNode is VariableTreeNode) {
     85              var variableTreeNode = currentInstr.dynamicNode as VariableTreeNode;
     86              return dataset[row, dataset.GetVariableIndex(variableTreeNode.VariableName)] * variableTreeNode.Weight;
     87            } else if (currentInstr.dynamicNode is ConstantTreeNode) {
     88              return ((ConstantTreeNode)currentInstr.dynamicNode).Value;
     89            } else throw new NotSupportedException();
     90          }
     91        default: throw new NotSupportedException();
    6092      }
    6193    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs

    r3253 r3294  
    3939  [StorableClass]
    4040  public abstract class SymbolicRegressionEvaluator : SingleSuccessorOperator, ISymbolicRegressionEvaluator {
     41    private const string QualityParameterName = "Quality";
     42    private const string FunctionTreeParameterName = "FunctionTree";
     43    private const string RegressionProblemDataParameterName = "RegressionProblemData";
     44    private const string NumberOfEvaluatedNodexParameterName = "NumberOfEvaluatedNodes";
    4145    #region ISymbolicRegressionEvaluator Members
    4246
    4347    public ILookupParameter<DoubleValue> QualityParameter {
    44       get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
     48      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
    4549    }
    4650
    4751    public ILookupParameter<SymbolicExpressionTree> FunctionTreeParameter {
    48       get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["FunctionTree"]; }
     52      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[FunctionTreeParameterName]; }
    4953    }
    5054
    51     public ILookupParameter<Dataset> DatasetParameter {
    52       get { return (ILookupParameter<Dataset>)Parameters["Dataset"]; }
     55    public ILookupParameter<RegressionProblemData> RegressionProblemDataParameter {
     56      get { return (ILookupParameter<RegressionProblemData>)Parameters[RegressionProblemDataParameterName]; }
    5357    }
    5458
    55     public ILookupParameter<StringValue> TargetVariableParameter {
    56       get { return (ILookupParameter<StringValue>)Parameters["TargetVariable"]; }
    57     }
     59    //public ILookupParameter<IntValue> SamplesStartParameter {
     60    //  get { return (ILookupParameter<IntValue>)Parameters["SamplesStart"]; }
     61    //}
    5862
    59     public ILookupParameter<IntValue> SamplesStartParameter {
    60       get { return (ILookupParameter<IntValue>)Parameters["SamplesStart"]; }
    61     }
    62 
    63     public ILookupParameter<IntValue> SamplesEndParameter {
    64       get { return (ILookupParameter<IntValue>)Parameters["SamplesEnd"]; }
    65     }
     63    //public ILookupParameter<IntValue> SamplesEndParameter {
     64    //  get { return (ILookupParameter<IntValue>)Parameters["SamplesEnd"]; }
     65    //}
    6666
    6767    public ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter {
    68       get { return (ILookupParameter<DoubleValue>)Parameters["NumberOfEvaluatedNodes"]; }
     68      get { return (ILookupParameter<DoubleValue>)Parameters[NumberOfEvaluatedNodexParameterName]; }
    6969    }
    7070
     
    7373    public SymbolicRegressionEvaluator()
    7474      : base() {
    75       Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the evaluated symbolic regression solution."));
    76       Parameters.Add(new LookupParameter<SymbolicExpressionTree>("FunctionTree", "The symbolic regression solution encoded as a symbolic expression tree."));
    77       Parameters.Add(new LookupParameter<Dataset>("Dataset", "The data set on which the symbolic regression solution should be evaluated."));
    78       Parameters.Add(new LookupParameter<StringValue>("TargetVariable", "The target variable of the symbolic regression solution."));
    79       Parameters.Add(new LookupParameter<IntValue>("SamplesStart", "The start index of the partition of the data set on which the symbolic regression solution should be evaluated."));
    80       Parameters.Add(new LookupParameter<IntValue>("SamplesEnd", "The end index of the partition of the data set on which the symbolic regression solution should be evaluated."));
    81       Parameters.Add(new LookupParameter<DoubleValue>("NumberOfEvaluatedNodes", "The number of evaluated nodes so far (for performance measurements.)"));
     75      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the evaluated symbolic regression solution."));
     76      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree."));
     77      Parameters.Add(new LookupParameter<RegressionProblemData>(RegressionProblemDataParameterName, "The data set on which the symbolic regression solution should be evaluated."));
     78      Parameters.Add(new LookupParameter<DoubleValue>(NumberOfEvaluatedNodexParameterName, "The number of evaluated nodes so far (for performance measurements.)"));
    8279    }
    8380
    8481    public override IOperation Apply() {
    8582      SymbolicExpressionTree solution = FunctionTreeParameter.ActualValue;
    86       Dataset dataset = DatasetParameter.ActualValue;
    87       StringValue targetVariable = TargetVariableParameter.ActualValue;
    88       IntValue samplesStart = SamplesStartParameter.ActualValue;
    89       IntValue samplesEnd = SamplesEndParameter.ActualValue;
     83      RegressionProblemData regressionProblemData = RegressionProblemDataParameter.ActualValue;
    9084      DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue;
    9185     
    92       QualityParameter.ActualValue = new DoubleValue(Evaluate(solution, dataset, targetVariable, samplesStart, samplesEnd, numberOfEvaluatedNodes));
     86      QualityParameter.ActualValue = new DoubleValue(Evaluate(solution, regressionProblemData.Dataset, regressionProblemData.TargetVariable, regressionProblemData.TrainingSamplesStart, regressionProblemData.TrainingSamplesEnd, numberOfEvaluatedNodes));
    9387      return null;
    9488    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs

    r3257 r3294  
    4141  public class SymbolicRegressionMeanSquaredErrorEvaluator : SymbolicRegressionEvaluator {
    4242    protected override double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes) {
    43       double mse = Apply(solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);
     43      double mse = Calculate(solution, dataset, targetVariable.Value, samplesStart.Value, samplesEnd.Value);
    4444      numberOfEvaluatedNodes.Value += solution.Size * (samplesEnd.Value - samplesStart.Value);
    4545      return mse;
    4646    }
    4747
    48     public static double Apply(SymbolicExpressionTree solution, Dataset dataset, string targetVariable, int start, int end) {
     48    public static double Calculate(SymbolicExpressionTree solution, Dataset dataset, string targetVariable, int start, int end) {
    4949      SimpleArithmeticExpressionEvaluator evaluator = new SimpleArithmeticExpressionEvaluator();
     50      int targetVariableIndex = dataset.GetVariableIndex(targetVariable);
    5051      var estimatedValues = evaluator.EstimatedValues(solution, dataset, Enumerable.Range(start, end - start));
    51       var originalValues = dataset.VariableValues(targetVariable, start, end);
    52       var values = new DoubleMatrix(MatrixExtensions<double>.Create(estimatedValues.ToArray(), originalValues));
    53       return SimpleMSEEvaluator.Calculate(values);
     52      var originalValues = from row in Enumerable.Range(start, end - start) select dataset[row, targetVariableIndex];
     53      return SimpleMSEEvaluator.Calculate(originalValues, estimatedValues);
    5454    }
    5555  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs

    r3269 r3294  
    7171      get { return (ValueParameter<DoubleValue>)Parameters["NumberOfEvaluatedNodes"]; }
    7272    }
     73    public ValueParameter<IntValue> MaxFunctionDefiningBranchesParameter {
     74      get { return (ValueParameter<IntValue>)Parameters["MaxFunctionDefiningBranches"]; }
     75    }
     76    public ValueParameter<IntValue> MaxFunctionArgumentsParameter {
     77      get { return (ValueParameter<IntValue>)Parameters["MaxFunctionArguments"]; }
     78    }
    7379    public OptionalValueParameter<ISingleObjectiveSolutionsVisualizer> VisualizerParameter {
    7480      get { return (OptionalValueParameter<ISingleObjectiveSolutionsVisualizer>)Parameters["Visualizer"]; }
     
    142148      Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the symbolic expression.", new IntValue(100)));
    143149      Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the symbolic expression.", new IntValue(10)));
     150      Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefiningBranches", "Maximal number of automatically defined functions.", new IntValue(3)));
     151      Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions.", new IntValue(3)));
    144152      Parameters.Add(new ValueParameter<DoubleValue>("NumberOfEvaluatedNodes", "The total number of evaluated function tree nodes (for performance measurements.)", new DoubleValue()));
    145153      Parameters.Add(new ValueParameter<ISingleObjectiveSolutionsVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", null));
     
    147155      creator.SymbolicExpressionTreeParameter.ActualName = "SymbolicRegressionModel";
    148156      evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError";
    149       InputVariablesParameter.ValueChanged += new EventHandler(InputVariablesParameter_ValueChanged);
     157      RegressionProblemDataParameter.ValueChanged += new EventHandler(RegressionProblemDataParameter_ValueChanged);
     158      RegressionProblemData.InputVariablesChanged += new EventHandler(RegressionProblemData_InputVariablesChanged);
    150159      ParameterizeSolutionCreator();
    151160      ParameterizeEvaluator();
     
    155164    }
    156165
    157     void InputVariablesParameter_ValueChanged(object sender, EventArgs e) {
    158       FunctionTreeGrammar.VariableNames = InputVariablesParameter.Value.Select(x => x.Value);
     166    void RegressionProblemDataParameter_ValueChanged(object sender, EventArgs e) {
     167      RegressionProblemData.InputVariablesChanged += new EventHandler(RegressionProblemData_InputVariablesChanged);
     168    }
     169
     170    void RegressionProblemData_InputVariablesChanged(object sender, EventArgs e) {
     171      FunctionTreeGrammar.VariableNames = RegressionProblemData.InputVariables.Select(x => x.Value);
    159172    }
    160173
     
    250263    private void ParameterizeEvaluator() {
    251264      Evaluator.FunctionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    252       Evaluator.SamplesStartParameter.ActualName = TrainingSamplesStartParameter.Name;
    253       Evaluator.SamplesEndParameter.ActualName = TrainingSamplesEndParameter.Name;
     265      Evaluator.RegressionProblemDataParameter.ActualName = RegressionProblemDataParameter.Name;
    254266    }
    255267    private void ParameterizeVisualizer() {
     
    277289      foreach (ISymbolicRegressionEvaluator op in Operators.OfType<ISymbolicRegressionEvaluator>()) {
    278290        op.FunctionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    279         op.DatasetParameter.ActualName = DatasetParameter.Name;
     291        op.RegressionProblemDataParameter.ActualName = RegressionProblemDataParameter.Name;
    280292        op.NumberOfEvaluatedNodesParameter.ActualName = NumberOfEvaluatedNodesParameter.Name;
    281         op.TargetVariableParameter.ActualName = TargetVariableParameter.Name;
    282         op.SamplesStartParameter.ActualName = TrainingSamplesStartParameter.Name;
    283         op.SamplesEndParameter.ActualName = TrainingSamplesEndParameter.Name;
    284293      }
    285294      foreach (SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) {
     
    287296        op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    288297      }
     298      foreach (SymbolicExpressionTreeManipulator op in Operators.OfType<SymbolicExpressionTreeManipulator>()) {
     299        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     300      }
     301      foreach (SymbolicExpressionTreeArchitectureAlteringOperator op in Operators.OfType<SymbolicExpressionTreeArchitectureAlteringOperator>()) {
     302      }
    289303    }
    290304    #endregion
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/Constant.cs

    r3269 r3294  
    3131  [Item("Constant", "Represents a constant value.")]
    3232  public sealed class Constant : Symbol {
    33     #region Parameter Properties
    34     public IValueParameter<DoubleValue> MinValueParameter {
    35       get { return (IValueParameter<DoubleValue>)Parameters["MinValue"]; }
     33    #region Propeties
     34    private double minValue;
     35    public double MinValue {
     36      get { return minValue; }
     37      set { minValue = value; }
    3638    }
    37     public IValueParameter<DoubleValue> MaxValueParameter {
    38       get { return (IValueParameter<DoubleValue>)Parameters["MaxValue"]; }
    39     }
    40     #endregion
    41     #region Propeties
    42     public DoubleValue MinValue {
    43       get { return MinValueParameter.Value; }
    44       set { MinValueParameter.Value = value; }
    45     }
    46     public DoubleValue MaxValue {
    47       get { return MaxValueParameter.Value; }
    48       set { MaxValueParameter.Value = value; }
     39    private double maxValue;
     40    public double MaxValue {
     41      get { return maxValue; }
     42      set { maxValue = value; }
    4943    }
    5044    #endregion
    5145    public Constant()
    5246      : base() {
    53       Parameters.Add(new ValueParameter<DoubleValue>("MinValue", "The minimal value of the constant.", new DoubleValue(-20.0)));
    54       Parameters.Add(new ValueParameter<DoubleValue>("MaxValue", "The maximal value of the constant.", new DoubleValue(20.0)));
    5547    }
    5648
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/ConstantTreeNode.cs

    r3269 r3294  
    5555    public override void ResetLocalParameters(IRandom random) {
    5656      base.ResetLocalParameters(random);
    57       var range = Symbol.MaxValue.Value - Symbol.MaxValue.Value;
    58       Value = random.NextDouble() * range - Symbol.MinValue.Value;
     57      var range = Symbol.MaxValue - Symbol.MaxValue;
     58      Value = random.NextDouble() * range - Symbol.MinValue;
    5959    }
    6060
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/Variable.cs

    r3269 r3294  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828using HeuristicLab.Parameters;
     29using System.Collections.Generic;
     30using System;
    2931namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols {
    3032  [StorableClass]
    3133  [Item("Variable", "Represents a variable value.")]
    3234  public sealed class Variable : Symbol {
    33     #region Parameter Properties
    34     public IValueParameter<DoubleValue> WeightNuParameter {
    35       get { return (IValueParameter<DoubleValue>)Parameters["WeightNu"]; }
     35    #region Properties
     36    private double weightNu;
     37    [Storable]
     38    public double WeightNu {
     39      get { return weightNu; }
     40      set { weightNu = value; }
    3641    }
    37     public IValueParameter<DoubleValue> WeightSigmaParameter {
    38       get { return (IValueParameter<DoubleValue>)Parameters["WeightSigma"]; }
     42    private double weightSigma;
     43    [Storable]
     44    public double WeightSigma {
     45      get { return weightSigma; }
     46      set {
     47        if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
     48        weightSigma = value;
     49      }
    3950    }
    40     public IValueParameter<ItemList<StringValue>> VariableNamesParameter {
    41       get { return (IValueParameter<ItemList<StringValue>>)Parameters["VariableNames"]; }
    42     }
    43     #endregion
    44     #region Properties
    45     public DoubleValue WeightNu {
    46       get { return WeightNuParameter.Value; }
    47       set { WeightNuParameter.Value = value; }
    48     }
    49     public DoubleValue WeightSigma {
    50       get { return WeightSigmaParameter.Value; }
    51       set { WeightSigmaParameter.Value = value; }
    52     }
    53     public ItemList<StringValue> VariableNames {
    54       get { return VariableNamesParameter.Value; }
    55       set { VariableNamesParameter.Value = value; }
     51    private List<string> variableNames;
     52    [Storable]
     53    public ICollection<string> VariableNames {
     54      get { return variableNames; }
     55      set {
     56        if (value == null) throw new ArgumentNullException();
     57        variableNames.Clear();
     58        variableNames.AddRange(value);
     59      }
    5660    }
    5761    #endregion
    5862    public Variable()
    5963      : base() {
    60       Parameters.Add(new ValueParameter<DoubleValue>("WeightNu", "The mean value for the initialization of weight ((N(nu, sigma)).", new DoubleValue(1.0)));
    61       Parameters.Add(new ValueParameter<DoubleValue>("WeightSigma", "The sigma value for the initialization of weight (N(nu, sigma))", new DoubleValue(1.0)));
    62       Parameters.Add(new ValueParameter<ItemList<StringValue>>("VariableNames", "The list of possible variable names for initialization."));
     64      weightNu = 1.0;
     65      weightSigma = 1.0;
     66      variableNames = new List<string>();
    6367    }
    6468
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Symbols/VariableTreeNode.cs

    r3269 r3294  
    5757    public override void ResetLocalParameters(IRandom random) {
    5858      base.ResetLocalParameters(random);
    59       var normalDistributedRNG = new NormalDistributedRandom(random, Symbol.WeightNu.Value, Symbol.WeightSigma.Value);
     59      var normalDistributedRNG = new NormalDistributedRandom(random, Symbol.WeightNu, Symbol.WeightSigma);
    6060      weight = normalDistributedRNG.NextDouble();
    61       int variableIndex = random.Next(0, Symbol.VariableNames.Count);
    62       variableName = Symbol.VariableNames[variableIndex].Value;
     61      var variableList = new List<string>(Symbol.VariableNames);
     62      int variableIndex = random.Next(0, variableList.Count);
     63      variableName = variableList[variableIndex];
    6364    }
    6465
Note: See TracChangeset for help on using the changeset viewer.