Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2174


Ignore:
Timestamp:
07/20/09 20:14:47 (15 years ago)
Author:
gkronber
Message:

Implemented #302 (Show variable names instead of var<index> in GP function trees).

  • Added a new operator that chooses a random value from a list of possible values.
  • Changed mutation operator for variables and differentials
  • Changed internal linear representation of function trees to support different types for local data.
Location:
trunk/sources
Files:
1 added
10 edited

Legend:

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

    r1529 r2174  
    6767        case SymbolTable.NOR: return !(Step() | Step());
    6868        case SymbolTable.VARIABLE:
    69           return dataset.GetValue(currentRow, (int)curFun.data[0]) != 0.0;
     69          return dataset.GetValue(currentRow, (int)curFun.localData[0]) != 0.0;
    7070        case SymbolTable.UNKNOWN:
    7171        default:
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Constant.cs

    r2166 r2174  
    4141    public Constant()
    4242      : base() {
    43       AddVariableInfo(new VariableInfo(VALUE, "The constant value", typeof(ConstrainedDoubleData), VariableKind.None));
     43      AddVariableInfo(new VariableInfo(VALUE, "The constant value", typeof(DoubleData), VariableKind.None));
    4444      GetVariableInfo(VALUE).Local = true;
    4545
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs

    r2165 r2174  
    3232namespace HeuristicLab.GP.StructureIdentification {
    3333  public class FunctionLibraryInjector : OperatorBase {
    34     private const string NUMBEROFINPUTVARIABLES = "NumberOfInputVariables";
    3534    private const string FUNCTIONLIBRARY = "FunctionLibrary";
    3635    private const string TARGETVARIABLE = "TargetVariable";
     
    7069    public FunctionLibraryInjector()
    7170      : base() {
    72       AddVariableInfo(new VariableInfo(NUMBEROFINPUTVARIABLES, "The number of available input variables", typeof(IntData), VariableKind.In));
    7371      AddVariableInfo(new VariableInfo(TARGETVARIABLE, "The target variable", typeof(IntData), VariableKind.In));
    7472      AddVariableInfo(new VariableInfo(MINTIMEOFFSET, "Minimal time offset for all features", typeof(IntData), VariableKind.In));
     
    111109      StructId.Variable variable;
    112110      GPOperatorLibrary operatorLibrary;
    113       int nInputVariables = GetVariableValue<IntData>(NUMBEROFINPUTVARIABLES, scope, true).Data;
    114111      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
    115112
     
    225222      ConditionalAddOperator(XOR_ALLOWED, operatorLibrary, xor);
    226223
    227       variable.SetConstraints(1, nInputVariables, minTimeOffset, maxTimeOffset);
    228       differential.SetConstraints(1, nInputVariables, minTimeOffset, maxTimeOffset);
     224      variable.SetConstraints(minTimeOffset, maxTimeOffset);
     225      differential.SetConstraints(minTimeOffset, maxTimeOffset);
    229226
    230227      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary));
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ModelAnalyzerExporter.cs

    r2167 r2174  
    196196        weight = ((DoubleData)weightItem).Data;
    197197      }
    198       double index = ((ConstrainedIntData)tree.GetLocalVariable(Variable.INDEX).Value).Data;
     198      string index = ((StringData)tree.GetLocalVariable(Variable.INDEX).Value).Data;
    199199      double offset = ((ConstrainedIntData)tree.GetLocalVariable(Variable.OFFSET).Value).Data;
    200200
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs

    r2034 r2174  
    7878        case EvaluatorSymbolTable.DIFFERENTIAL:
    7979        case EvaluatorSymbolTable.VARIABLE: {
    80             instr.i_arg0 = (short)f.data[0]; // var
    81             instr.d_arg0 = f.data[1]; // weight
    82             instr.i_arg1 = (short)f.data[2]; // sample-offset
     80            instr.i_arg0 = (short)dataset.GetVariableIndex((string)f.localData[0]); // var
     81            instr.d_arg0 = (double)f.localData[1]; // weight
     82            instr.i_arg1 = (short)(int)f.localData[2]; // sample-offset
    8383            break;
    8484          }
    8585        case EvaluatorSymbolTable.CONSTANT: {
    86             instr.d_arg0 = f.data[0]; // value
     86            instr.d_arg0 = (double)f.localData[0]; // value
    8787            break;
    8888          }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Variable.cs

    r2166 r2174  
    3838    public const string INDEX = "Variable";
    3939
    40     private int minIndex;
    41     private int maxIndex;
    4240    private int minOffset;
    4341    private int maxOffset;
     
    5351    public Variable()
    5452      : base() {
    55       AddVariableInfo(new VariableInfo(INDEX, "Index of the variable in the dataset representing this feature", typeof(ConstrainedIntData), VariableKind.None));
     53      AddVariableInfo(new VariableInfo(INDEX, "The variable name", typeof(StringData), VariableKind.None));
    5654      GetVariableInfo(INDEX).Local = true;
    57       AddVariableInfo(new VariableInfo(WEIGHT, "Weight is multiplied to the feature value", typeof(ConstrainedDoubleData), VariableKind.None));
     55      AddVariableInfo(new VariableInfo(WEIGHT, "Weight is multiplied to the feature value", typeof(DoubleData), VariableKind.None));
    5856      GetVariableInfo(WEIGHT).Local = true;
    5957      AddVariableInfo(new VariableInfo(OFFSET, "SampleOffset is added to the sample index", typeof(ConstrainedIntData), VariableKind.None));
     
    6765      AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight));
    6866
    69       ConstrainedIntData variable = new ConstrainedIntData();
     67      StringData variable = new StringData();
    7068      AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));
    71       minIndex = 0; maxIndex = 1000;
    7269
    7370      ConstrainedIntData sampleOffset = new ConstrainedIntData();
     
    8481      CombinedOperator combinedOp = new CombinedOperator();
    8582      SequentialProcessor seq = new SequentialProcessor();
    86       UniformRandomizer indexRandomizer = new UniformRandomizer();
    87       indexRandomizer.Min = minIndex;
    88       indexRandomizer.Max = maxIndex + 1; // uniform randomizer generates numbers in the range [min, max[
    89       indexRandomizer.GetVariableInfo("Value").ActualName = INDEX;
    90       indexRandomizer.Name = "Index Randomizer";
     83      UniformItemChooser variableRandomizer = new UniformItemChooser();
     84      variableRandomizer.GetVariableInfo("Value").ActualName = INDEX;
     85      variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
     86      variableRandomizer.Name = "Variable randomizer";
    9187      NormalRandomizer weightRandomizer = new NormalRandomizer();
    9288      weightRandomizer.Mu = 0.0;
     
    10197
    10298      combinedOp.OperatorGraph.AddOperator(seq);
    103       combinedOp.OperatorGraph.AddOperator(indexRandomizer);
     99      combinedOp.OperatorGraph.AddOperator(variableRandomizer);
    104100      combinedOp.OperatorGraph.AddOperator(weightRandomizer);
    105101      combinedOp.OperatorGraph.AddOperator(offsetRandomizer);
    106102      combinedOp.OperatorGraph.InitialOperator = seq;
    107       seq.AddSubOperator(indexRandomizer);
     103      seq.AddSubOperator(variableRandomizer);
    108104      seq.AddSubOperator(weightRandomizer);
    109105      seq.AddSubOperator(offsetRandomizer);
     
    120116      CombinedOperator combinedOp = new CombinedOperator();
    121117      SequentialProcessor seq = new SequentialProcessor();
    122       UniformRandomizer indexRandomizer = new UniformRandomizer();
    123       indexRandomizer.Min = minIndex;
    124       indexRandomizer.Max = maxIndex + 1;
    125       indexRandomizer.GetVariableInfo("Value").ActualName = INDEX;
    126       indexRandomizer.Name = "Index Randomizer";
     118      UniformItemChooser variableRandomizer = new UniformItemChooser();
     119      variableRandomizer.GetVariableInfo("Value").ActualName = INDEX;
     120      variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
     121      variableRandomizer.Name = "Variable randomizer";
    127122      NormalRandomAdder weightRandomAdder = new NormalRandomAdder();
    128123      weightRandomAdder.Mu = 0.0;
     
    137132
    138133      combinedOp.OperatorGraph.AddOperator(seq);
    139       combinedOp.OperatorGraph.AddOperator(indexRandomizer);
     134      combinedOp.OperatorGraph.AddOperator(variableRandomizer);
    140135      combinedOp.OperatorGraph.AddOperator(weightRandomAdder);
    141136      combinedOp.OperatorGraph.AddOperator(offsetRandomAdder);
    142137      combinedOp.OperatorGraph.InitialOperator = seq;
    143       seq.AddSubOperator(indexRandomizer);
     138      seq.AddSubOperator(variableRandomizer);
    144139      seq.AddSubOperator(weightRandomAdder);
    145140      seq.AddSubOperator(offsetRandomAdder);
     
    152147    }
    153148
    154     public void SetConstraints(int minInputIndex, int maxInputIndex, int minSampleOffset, int maxSampleOffset) {
     149    public void SetConstraints(int minSampleOffset, int maxSampleOffset) {
    155150      ConstrainedIntData offset = GetVariableValue<ConstrainedIntData>(OFFSET, null, false);
    156151      IntBoundedConstraint offsetConstraint = new IntBoundedConstraint();
     
    165160      offset.AddConstraint(offsetConstraint);
    166161
    167       ConstrainedIntData index = GetVariableValue<ConstrainedIntData>(INDEX, null, false);
    168       IntBoundedConstraint indexConstraint = new IntBoundedConstraint();
    169       minIndex = minInputIndex;
    170       maxIndex = maxInputIndex;
    171       indexConstraint.LowerBound = minInputIndex;
    172       indexConstraint.LowerBoundEnabled = true;
    173       indexConstraint.LowerBoundIncluded = true;
    174       indexConstraint.UpperBound = maxInputIndex;
    175       indexConstraint.UpperBoundEnabled = true;
    176       indexConstraint.UpperBoundIncluded = true;
    177       index.AddConstraint(indexConstraint);
     162      //ConstrainedIntData index = GetVariableValue<ConstrainedIntData>(INDEX, null, false);
     163      //IntBoundedConstraint indexConstraint = new IntBoundedConstraint();
     164      //minIndex = minInputIndex;
     165      //maxIndex = maxInputIndex;
     166      //indexConstraint.LowerBound = minInputIndex;
     167      //indexConstraint.LowerBoundEnabled = true;
     168      //indexConstraint.LowerBoundIncluded = true;
     169      //indexConstraint.UpperBound = maxInputIndex;
     170      //indexConstraint.UpperBoundEnabled = true;
     171      //indexConstraint.UpperBoundIncluded = true;
     172      //index.AddConstraint(indexConstraint);
    178173
    179174      SetupInitialization();
  • trunk/sources/HeuristicLab.GP/3.3/BakedFunctionTree.cs

    r1529 r2174  
    3434    public byte arity = 0;
    3535    public IFunction functionType;
    36     public List<double> data = new List<double>();
     36    public List<object> localData = new List<object>();
    3737
    3838    public LightWeightFunction Clone() {
     
    4040      clone.arity = arity;
    4141      clone.functionType = functionType;
    42       clone.data.AddRange(data);
     42      clone.localData.AddRange(localData);
    4343      return clone;
    4444    }
     
    5050      get {
    5151        FlattenVariables();
    52         FlattenTrees(); 
     52        FlattenTrees();
    5353        return linearRepresentation;
    5454      }
     
    7272      variables = new List<IVariable>();
    7373      variablesExpanded = true;
    74       foreach(IVariableInfo variableInfo in function.VariableInfos) {
    75         if(variableInfo.Local) {
     74      foreach (IVariableInfo variableInfo in function.VariableInfos) {
     75        if (variableInfo.Local) {
    7676          variables.Add((IVariable)function.GetVariable(variableInfo.FormalName).Clone());
    7777        }
     
    8484      fun.functionType = tree.Function;
    8585      linearRepresentation.Add(fun);
    86       foreach(IVariable variable in tree.LocalVariables) {
    87         IItem value = variable.Value;
    88         fun.data.Add(GetDoubleValue(value));
    89       }
    90       foreach(IFunctionTree subTree in tree.SubTrees) {
     86      foreach (IVariable variable in tree.LocalVariables) {
     87        IObjectData value = (IObjectData)variable.Value;
     88        fun.localData.Add(value.Data);
     89      }
     90      foreach (IFunctionTree subTree in tree.SubTrees) {
    9191        AddSubTree(new BakedFunctionTree(subTree));
    9292      }
    93     }
    94 
    95     private double GetDoubleValue(IItem value) {
    96       if(value is DoubleData) {
    97         return ((DoubleData)value).Data;
    98       } else if(value is ConstrainedDoubleData) {
    99         return ((ConstrainedDoubleData)value).Data;
    100       } else if(value is IntData) {
    101         return ((IntData)value).Data;
    102       } else if(value is ConstrainedIntData) {
    103         return ((ConstrainedIntData)value).Data;
    104       } else throw new NotSupportedException("Invalid datatype of local variable for GP");
    10593    }
    10694
     
    10896      int arity = linearRepresentation[branchRoot].arity;
    10997      int length = 1;
    110       for(int i = 0; i < arity; i++) {
     98      for (int i = 0; i < arity; i++) {
    11199        length += BranchLength(branchRoot + length);
    112100      }
     
    115103
    116104    private void FlattenTrees() {
    117       if(treesExpanded) {
     105      if (treesExpanded) {
    118106        linearRepresentation[0].arity = (byte)subTrees.Count;
    119         foreach(BakedFunctionTree subTree in subTrees) {
     107        foreach (BakedFunctionTree subTree in subTrees) {
    120108          subTree.FlattenVariables();
    121109          subTree.FlattenTrees();
     
    128116
    129117    private void FlattenVariables() {
    130       if(variablesExpanded) {
    131         linearRepresentation[0].data.Clear();
    132         foreach(IVariable variable in variables) {
    133           linearRepresentation[0].data.Add(GetDoubleValue(variable.Value));
     118      if (variablesExpanded) {
     119        linearRepresentation[0].localData.Clear();
     120        foreach (IVariable variable in variables) {
     121          object objData = variable.Value;
     122          while (objData is IObjectData) objData = ((IObjectData)objData).Data;
     123          linearRepresentation[0].localData.Add(objData);
    134124        }
    135125        variablesExpanded = false;
     
    140130    public int Size {
    141131      get {
    142         if(treesExpanded) {
     132        if (treesExpanded) {
    143133          int size = 1;
    144           foreach(BakedFunctionTree tree in subTrees) {
     134          foreach (BakedFunctionTree tree in subTrees) {
    145135            size += tree.Size;
    146136          }
    147137          return size;
    148         } else 
    149         return linearRepresentation.Count;
     138        } else
     139          return linearRepresentation.Count;
    150140      }
    151141    }
     
    153143    public int Height {
    154144      get {
    155         if(treesExpanded) {
     145        if (treesExpanded) {
    156146          int height = 0;
    157           foreach(IFunctionTree subTree in subTrees) {
     147          foreach (IFunctionTree subTree in subTrees) {
    158148            int curHeight = subTree.Height;
    159             if(curHeight > height) height = curHeight;
    160           }
    161           return height+1;
     149            if (curHeight > height) height = curHeight;
     150          }
     151          return height + 1;
    162152        } else {
    163153          int nextBranchStart;
     
    171161      int height = 0;
    172162      branchStart++;
    173       for(int i = 0; i < f.arity; i++) {
     163      for (int i = 0; i < f.arity; i++) {
    174164        int curHeight = BranchHeight(branchStart, out nextBranchStart);
    175         if(curHeight > height) height = curHeight;
     165        if (curHeight > height) height = curHeight;
    176166        branchStart = nextBranchStart;
    177167      }
     
    182172    public IList<IFunctionTree> SubTrees {
    183173      get {
    184         if(!treesExpanded) {
     174        if (!treesExpanded) {
    185175          subTrees = new List<IFunctionTree>();
    186176          int arity = linearRepresentation[0].arity;
    187177          int branchIndex = 1;
    188           for(int i = 0; i < arity; i++) {
     178          for (int i = 0; i < arity; i++) {
    189179            BakedFunctionTree subTree = new BakedFunctionTree();
    190180            int length = BranchLength(branchIndex);
    191             for(int j = branchIndex; j < branchIndex + length; j++) {
     181            for (int j = branchIndex; j < branchIndex + length; j++) {
    192182              subTree.linearRepresentation.Add(linearRepresentation[j]);
    193183            }
     
    205195    public ICollection<IVariable> LocalVariables {
    206196      get {
    207         if(!variablesExpanded) {
     197        if (!variablesExpanded) {
    208198          variables = new List<IVariable>();
    209199          IFunction function = Function;
    210200          int localVariableIndex = 0;
    211           foreach(IVariableInfo variableInfo in function.VariableInfos) {
    212             if(variableInfo.Local) {
     201          foreach (IVariableInfo variableInfo in function.VariableInfos) {
     202            if (variableInfo.Local) {
    213203              IVariable clone = (IVariable)function.GetVariable(variableInfo.FormalName).Clone();
    214               IItem value = clone.Value;
    215               if(value is ConstrainedDoubleData) {
    216                 ((ConstrainedDoubleData)value).Data = linearRepresentation[0].data[localVariableIndex];
    217               } else if(value is ConstrainedIntData) {
    218                 ((ConstrainedIntData)value).Data = (int)linearRepresentation[0].data[localVariableIndex];
    219               } else if(value is DoubleData) {
    220                 ((DoubleData)value).Data = linearRepresentation[0].data[localVariableIndex];
    221               } else if(value is IntData) {
    222                 ((IntData)value).Data = (int)linearRepresentation[0].data[localVariableIndex];
    223               } else throw new NotSupportedException("Invalid local variable type for GP.");
     204              IObjectData objData = (IObjectData)clone.Value;
     205              if (objData is ConstrainedDoubleData) {
     206                ((ConstrainedDoubleData)objData).Data = (double)linearRepresentation[0].localData[localVariableIndex];
     207              } else if (objData is ConstrainedIntData) {
     208                ((ConstrainedIntData)objData).Data = (int)linearRepresentation[0].localData[localVariableIndex];
     209              } else {
     210                objData.Data = linearRepresentation[0].localData[localVariableIndex];
     211              }
    224212              variables.Add(clone);
    225213              localVariableIndex++;
     
    227215          }
    228216          variablesExpanded = true;
    229           linearRepresentation[0].data.Clear();
     217          linearRepresentation[0].localData.Clear();
    230218        }
    231219        return variables;
     
    238226
    239227    public IVariable GetLocalVariable(string name) {
    240       foreach(IVariable var in LocalVariables) {
    241         if(var.Name == name) return var;
     228      foreach (IVariable var in LocalVariables) {
     229        if (var.Name == name) return var;
    242230      }
    243231      return null;
     
    253241
    254242    public void AddSubTree(IFunctionTree tree) {
    255       if(!treesExpanded) throw new InvalidOperationException();
     243      if (!treesExpanded) throw new InvalidOperationException();
    256244      subTrees.Add(tree);
    257245    }
    258246
    259247    public void InsertSubTree(int index, IFunctionTree tree) {
    260       if(!treesExpanded) throw new InvalidOperationException();
     248      if (!treesExpanded) throw new InvalidOperationException();
    261249      subTrees.Insert(index, tree);
    262250    }
     
    264252    public void RemoveSubTree(int index) {
    265253      // sanity check
    266       if(!treesExpanded) throw new InvalidOperationException();
     254      if (!treesExpanded) throw new InvalidOperationException();
    267255      subTrees.RemoveAt(index);
    268256    }
     
    273261      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    274262      XmlNode linearRepresentationNode = document.CreateElement("LinearRepresentation");
    275       foreach(LightWeightFunction f in linearRepresentation) {
    276         XmlNode entryNode = PersistenceManager.Persist("FunctionType", f.functionType, document, persistedObjects);
     263      foreach (LightWeightFunction f in linearRepresentation) {
     264        XmlNode entryNode = PersistenceManager.Persist("Function", f.functionType, document, persistedObjects);
    277265        XmlAttribute arityAttribute = document.CreateAttribute("Arity");
    278         arityAttribute.Value = f.arity+"";
     266        arityAttribute.Value = XmlConvert.ToString(f.arity);
    279267        entryNode.Attributes.Append(arityAttribute);
    280         if(f.data.Count > 0) {
    281           XmlAttribute dataAttribute = document.CreateAttribute("Data");
    282           dataAttribute.Value = GetString(f.data);
    283           entryNode.Attributes.Append(dataAttribute);
     268        foreach (object o in f.localData) {
     269          if (f.localData.Count > 0) {
     270            entryNode.AppendChild(CreateDataNode(document, o));
     271          }
    284272        }
    285273        linearRepresentationNode.AppendChild(entryNode);
     
    287275
    288276      node.AppendChild(linearRepresentationNode);
     277      return node;
     278    }
     279
     280    private XmlNode CreateDataNode(XmlDocument doc, object o) {
     281      XmlNode node = doc.CreateElement("Data");
     282      XmlAttribute typeAttr = doc.CreateAttribute("Type");
     283      node.Attributes.Append(typeAttr);
     284      if (o is double) {
     285        node.Value = XmlConvert.ToString((double)o);
     286        typeAttr.Value = "d";
     287      } else if (o is int) {
     288        node.Value = XmlConvert.ToString((int)o);
     289        typeAttr.Value = "i";
     290      } else if (o is string) {
     291        node.Value = (string)o;
     292        typeAttr.Value = "s";
     293      } else throw new ArgumentException("Invalid type for local data element: " + o);
    289294      return node;
    290295    }
     
    293298      base.Populate(node, restoredObjects);
    294299      XmlNode linearRepresentationNode = node.SelectSingleNode("LinearRepresentation");
    295       foreach(XmlNode entryNode in linearRepresentationNode.ChildNodes) {
     300      foreach (XmlNode entryNode in linearRepresentationNode.ChildNodes) {
    296301        LightWeightFunction f = new LightWeightFunction();
    297         f.arity = byte.Parse(entryNode.Attributes["Arity"].Value, CultureInfo.InvariantCulture);
    298         if(entryNode.Attributes["Data"]!=null)
    299           f.data = GetList<double>(entryNode.Attributes["Data"].Value, s => double.Parse(s, CultureInfo.InvariantCulture));
     302        f.arity = XmlConvert.ToByte(entryNode.Attributes["Arity"].Value);
     303        foreach (XmlNode dataNode in entryNode.ChildNodes) {
     304          f.localData.Add(ParseDataNode(dataNode));
     305        }
    300306        f.functionType = (IFunction)PersistenceManager.Restore(entryNode, restoredObjects);
    301307        linearRepresentation.Add(f);
     
    305311    }
    306312
    307     private string GetString(IEnumerable<double> xs) {
    308       StringBuilder builder = new StringBuilder();
    309       foreach(double x in xs) {
    310         builder.Append(x.ToString("r", CultureInfo.InvariantCulture) + "; ");
    311       }
    312       if(builder.Length > 0) builder.Remove(builder.Length - 2, 2);
    313       return builder.ToString();
    314     }
    315 
    316     private List<T> GetList<T>(string s, Converter<string, T> converter) {
    317       List<T> result = new List<T>();
    318       string[] tokens = s.Split(new char[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
    319       foreach(string token in tokens) {
    320         T x = converter(token.Trim());
    321         result.Add(x);
    322       }
    323       return result;
    324     }
     313    private object ParseDataNode(XmlNode dataNode) {
     314      string type = dataNode.Attributes["Type"].Value;
     315      if (type == "d") {
     316        return XmlConvert.ToDouble(dataNode.Value);
     317      } else if (type == "i") {
     318        return XmlConvert.ToInt32(dataNode.Value);
     319      } else if (type == "s") {
     320        return dataNode.Value;
     321      } else throw new FormatException("Can't parse type \"" + type + "\" \"" + dataNode.Value + "\" as local data for GP trees");
     322    }
     323
     324    //private string GetString(IEnumerable<double> xs) {
     325    //  StringBuilder builder = new StringBuilder();
     326    //  foreach (double x in xs) {
     327    //    builder.Append(x.ToString("r", CultureInfo.InvariantCulture) + "; ");
     328    //  }
     329    //  if (builder.Length > 0) builder.Remove(builder.Length - 2, 2);
     330    //  return builder.ToString();
     331    //}
     332
     333    //private List<T> GetList<T>(string s, Converter<string, T> converter) {
     334    //  List<T> result = new List<T>();
     335    //  string[] tokens = s.Split(new char[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
     336    //  foreach (string token in tokens) {
     337    //    T x = converter(token.Trim());
     338    //    result.Add(x);
     339    //  }
     340    //  return result;
     341    //}
    325342
    326343    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    327344      BakedFunctionTree clone = new BakedFunctionTree();
    328345      // in case the user (de)serialized the tree between evaluation and selection we have to flatten the tree again.
    329       if(treesExpanded) FlattenTrees();
    330       if(variablesExpanded) FlattenVariables();
    331       foreach(LightWeightFunction f in linearRepresentation) {
     346      if (treesExpanded) FlattenTrees();
     347      if (variablesExpanded) FlattenVariables();
     348      foreach (LightWeightFunction f in linearRepresentation) {
    332349        clone.linearRepresentation.Add(f.Clone());
    333350      }
  • trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjector.cs

    r2165 r2174  
    7878      AddVariableInfo(new VariableInfo("MaxNumberOfTrainingSamples", "Maximal number of training samples to use (optional)", typeof(IntData), VariableKind.In));
    7979      AddVariableInfo(new VariableInfo("NumberOfInputVariables", "The number of available input variables", typeof(IntData), VariableKind.New));
     80      AddVariableInfo(new VariableInfo("InputVariables", "List of input variable names", typeof(ItemList), VariableKind.New));
    8081    }
    8182
     
    9798
    9899      Dataset scopeDataset = CreateNewDataset(operatorDataset, targetVariable, operatorAllowedFeatures);
     100      ItemList inputVariables = new ItemList();
     101      for (int i = 1; i < scopeDataset.Columns; i++) {
     102        inputVariables.Add(new StringData(scopeDataset.GetVariableName(i)));
     103      }
    99104
    100       scope.AddVariable(new Variable("Dataset", scopeDataset));
    101       scope.AddVariable(new Variable("TargetVariable", new IntData(0)));
    102       scope.AddVariable(new Variable("NumberOfInputVariables", new IntData(scopeDataset.Columns - 1)));
     105      scope.AddVariable(new Variable(scope.TranslateName("Dataset"), scopeDataset));
     106      scope.AddVariable(new Variable(scope.TranslateName("TargetVariable"), new IntData(0)));
     107      scope.AddVariable(new Variable(scope.TranslateName("NumberOfInputVariables"), new IntData(scopeDataset.Columns - 1)));
     108      scope.AddVariable(new Variable(scope.TranslateName("InputVariables"), inputVariables));
    103109
    104110      int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
     
    116122      scope.AddVariable(new Variable(scope.TranslateName("ActualTrainingSamplesStart"), new IntData(trainingStart)));
    117123      scope.AddVariable(new Variable(scope.TranslateName("ActualTrainingSamplesEnd"), new IntData(trainingStart + nTrainingSamples)));
     124
     125
    118126      return null;
    119127    }
     
    154162
    155163    private void AddVariableToScope(string variableName, IScope scope) {
    156       scope.AddVariable(new Variable(variableName, (IItem)GetVariable(variableName).Value.Clone()));     
     164      scope.AddVariable(new Variable(scope.TranslateName(variableName), (IItem)GetVariable(variableName).Value.Clone()));     
    157165    }
    158166  }
  • trunk/sources/HeuristicLab.Random/3.2/HeuristicLab.Random-3.2.csproj

    r1534 r2174  
    8181  </ItemGroup>
    8282  <ItemGroup>
     83    <Compile Include="UniformItemChooser.cs" />
    8384    <Compile Include="UniformRandomAdder.cs" />
    8485    <Compile Include="NormalRandomAdder.cs" />
  • trunk/sources/HeuristicLab.Random/3.2/UniformRandomizer.cs

    r1530 r2174  
    6363    /// </summary>
    6464    public UniformRandomizer() {
    65       AddVariableInfo(new VariableInfo("Value", "The value to manipulate (type is one of: IntData, ConstrainedIntData, DoubleData, ConstrainedDoubleData)", typeof(IObjectData), VariableKind.In));
     65      AddVariableInfo(new VariableInfo("Value", "The value to manipulate (type is one of: IntData, ConstrainedIntData, DoubleData, ConstrainedDoubleData)", typeof(IObjectData), VariableKind.Out));
    6666      AddVariableInfo(new VariableInfo("Random", "The random generator to use", typeof(MersenneTwister), VariableKind.In));
    6767      AddVariableInfo(new VariableInfo("Min", "Lower bound of the uniform distribution (inclusive)", typeof(DoubleData), VariableKind.None));
Note: See TracChangeset for help on using the changeset viewer.