Index: trunk/sources/HeuristicLab.StructureIdentification/CrossValidation.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/CrossValidation.cs	(revision 516)
+++ trunk/sources/HeuristicLab.StructureIdentification/CrossValidation.cs	(revision 516)
@@ -0,0 +1,110 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.DataAnalysis;
+
+namespace HeuristicLab.StructureIdentification {
+  public class CrossValidation : OperatorBase {
+
+    private const string DATASET = "Dataset";
+    private const string NFOLD = "n-Fold";
+    private const string TRAININGSAMPLESSTART = "TrainingSamplesStart";
+    private const string TRAININGSAMPLESEND = "TrainingSamplesEnd";
+    private const string VALIDATIONSAMPLESSTART = "ValidationSamplesStart";
+    private const string VALIDATIONSAMPLESEND = "ValidationSamplesEnd";
+    private const string TESTSAMPLESSTART = "TestSamplesStart";
+    private const string TESTSAMPLESEND = "TestSamplesEnd";
+
+    public override string Description {
+      get { return @"TASK"; }
+    }
+
+    public CrossValidation()
+      : base() {
+      AddVariableInfo(new VariableInfo(DATASET, "The original dataset and the new datasets in the newly created subscopes", typeof(Dataset), VariableKind.In));
+      AddVariableInfo(new VariableInfo(NFOLD, "Number of folds for the cross-validation", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo(TRAININGSAMPLESSTART, "The start of training samples in the original dataset and starts of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
+      AddVariableInfo(new VariableInfo(TRAININGSAMPLESEND, "The end of training samples in the original dataset and ends of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
+      AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESSTART, "The start of validation samples in the original dataset and starts of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
+      AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESEND, "The end of validation samples in the original dataset and ends of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New));
+      AddVariableInfo(new VariableInfo(TESTSAMPLESSTART, "The start of the test samples in the new datasets", typeof(IntData), VariableKind.New));
+      AddVariableInfo(new VariableInfo(TESTSAMPLESEND, "The end of the test samples in the new datasets", typeof(IntData), VariableKind.New));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      Dataset origDataset = GetVariableValue<Dataset>(DATASET, scope, true);
+      int nFolds = GetVariableValue<IntData>(NFOLD, scope, true).Data;
+      int origTrainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data;
+      int origTrainingSamplesEnd = GetVariableValue<IntData>(TRAININGSAMPLESEND, scope, true).Data;
+      int origValidationSamplesStart = GetVariableValue<IntData>(VALIDATIONSAMPLESSTART, scope, true).Data;
+      int origValidationSamplesEnd = GetVariableValue<IntData>(VALIDATIONSAMPLESEND, scope, true).Data;
+      int n=origDataset.Rows;
+      int origTrainingSamples = (origTrainingSamplesEnd-origTrainingSamplesStart);
+      int origValidationSamples = (origValidationSamplesEnd-origValidationSamplesStart);
+
+      double percentTrainingSamples = origTrainingSamples / (double)(origValidationSamples + origTrainingSamples);
+      int nTestSamples = n / nFolds;
+
+      int newTrainingSamplesStart = 0;
+      int newTrainingSamplesEnd = (int)((n - nTestSamples) * percentTrainingSamples);
+      int newValidationSamplesStart = newTrainingSamplesEnd;
+      int newValidationSamplesEnd = n - nTestSamples;
+      int newTestSamplesStart = n - nTestSamples;
+      int newTestSamplesEnd = n;
+
+      for(int i = 0; i < nFolds; i++) {
+        Scope childScope = new Scope(i.ToString());
+        Dataset rotatedSet = new Dataset();
+
+        double[] samples = new double[origDataset.Samples.Length];
+        Array.Copy(origDataset.Samples, samples, samples.Length);
+        RotateArray(samples, i * nFolds);
+
+        rotatedSet.Rows = origDataset.Rows;
+        rotatedSet.Columns = origDataset.Columns;
+        rotatedSet.Samples = samples;
+        childScope.AddVariable(new Variable(scope.TranslateName(DATASET), rotatedSet));
+        childScope.AddVariable(new Variable(scope.TranslateName(TRAININGSAMPLESSTART), new IntData(newTrainingSamplesStart)));
+        childScope.AddVariable(new Variable(scope.TranslateName(TRAININGSAMPLESEND), new IntData(newTrainingSamplesEnd)));
+        childScope.AddVariable(new Variable(scope.TranslateName(VALIDATIONSAMPLESSTART), new IntData(newValidationSamplesStart)));
+        childScope.AddVariable(new Variable(scope.TranslateName(VALIDATIONSAMPLESEND), new IntData(newValidationSamplesEnd)));
+        childScope.AddVariable(new Variable(scope.TranslateName(TESTSAMPLESSTART), new IntData(newTestSamplesStart)));
+        childScope.AddVariable(new Variable(scope.TranslateName(TESTSAMPLESEND), new IntData(newTestSamplesEnd)));
+
+        scope.AddSubScope(childScope);
+      }
+      return null;
+    }
+
+    private void RotateArray(double[] samples, int p) {
+      Array.Reverse(samples, 0, p);
+      Array.Reverse(samples, p, samples.Length - p);
+      Array.Reverse(samples);
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.StructureIdentification/HeuristicLab.StructureIdentification.csproj
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/HeuristicLab.StructureIdentification.csproj	(revision 515)
+++ trunk/sources/HeuristicLab.StructureIdentification/HeuristicLab.StructureIdentification.csproj	(revision 516)
@@ -48,4 +48,7 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="CrossValidation.cs" />
+    <Compile Include="MulticlassOneVsOneAnalyzer.cs" />
+    <Compile Include="MulticlassModeller.cs" />
     <Compile Include="Evaluation\ClassificationMeanSquaredErrorEvaluator.cs" />
     <Compile Include="Evaluation\ClassificationMatrixEvaluator.cs" />
Index: trunk/sources/HeuristicLab.StructureIdentification/MulticlassModeller.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/MulticlassModeller.cs	(revision 516)
+++ trunk/sources/HeuristicLab.StructureIdentification/MulticlassModeller.cs	(revision 516)
@@ -0,0 +1,151 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.DataAnalysis;
+
+namespace HeuristicLab.StructureIdentification {
+  public class MulticlassModeller : OperatorBase {
+
+    private const string DATASET = "Dataset";
+    private const string TARGETVARIABLE = "TargetVariable";
+    private const string TARGETCLASSVALUES = "TargetClassValues";
+    private const string TRAININGSAMPLESSTART = "TrainingSamplesStart";
+    private const string TRAININGSAMPLESEND = "TrainingSamplesEnd";
+    private const string VALIDATIONSAMPLESSTART = "ValidationSamplesStart";
+    private const string VALIDATIONSAMPLESEND = "ValidationSamplesEnd";
+    private const string CLASSAVALUE = "ClassAValue";
+    private const string CLASSBVALUE = "ClassBValue";
+    private const double EPSILON = 1E-6;
+    public override string Description {
+      get { return @"TASK"; }
+    }
+
+    public MulticlassModeller()
+      : base() {
+      AddVariableInfo(new VariableInfo(DATASET, "The original dataset and the new dataset parts in the newly created subscopes", typeof(Dataset), VariableKind.In));
+      AddVariableInfo(new VariableInfo(TARGETVARIABLE, "TargetVariable", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo(TARGETCLASSVALUES, "Class values of the target variable in the original dataset and in the new dataset parts", typeof(ItemList<DoubleData>), VariableKind.In | VariableKind.New));
+      AddVariableInfo(new VariableInfo(CLASSAVALUE, "The original class value of the new class A", typeof(DoubleData), VariableKind.New));
+      AddVariableInfo(new VariableInfo(CLASSBVALUE, "The original class value of the new class B", typeof(DoubleData), VariableKind.New));
+      AddVariableInfo(new VariableInfo(TRAININGSAMPLESSTART, "The start of training samples in the original dataset and starts of training samples in the new dataset parts", typeof(IntData), VariableKind.In | VariableKind.New));
+      AddVariableInfo(new VariableInfo(TRAININGSAMPLESEND, "The end of training samples in the original dataset and ends of training samples in the new dataset parts", typeof(IntData), VariableKind.In | VariableKind.New));
+      AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESSTART, "The start of validation samples in the original dataset and starts of validation samples in the new dataset parts", typeof(IntData), VariableKind.In | VariableKind.New));
+      AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESEND, "The end of validation samples in the original dataset and ends of validation samples in the new dataset parts", typeof(IntData), VariableKind.In | VariableKind.New));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      Dataset origDataset = GetVariableValue<Dataset>(DATASET, scope, true);
+      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
+      ItemList<DoubleData> classValues = GetVariableValue<ItemList<DoubleData>>(TARGETCLASSVALUES, scope, true);
+      int origTrainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data;
+      int origTrainingSamplesEnd = GetVariableValue<IntData>(TRAININGSAMPLESEND, scope, true).Data;
+      int origValidationSamplesStart = GetVariableValue<IntData>(VALIDATIONSAMPLESSTART, scope, true).Data;
+      int origValidationSamplesEnd = GetVariableValue<IntData>(VALIDATIONSAMPLESEND, scope, true).Data;
+      ItemList<DoubleData> binaryClassValues = new ItemList<DoubleData>();
+      binaryClassValues.Add(new DoubleData(0.0));
+      binaryClassValues.Add(new DoubleData(1.0));
+      for(int i = 0; i < classValues.Count-1; i++) {
+        for(int j = i+1; j < classValues.Count; j++) {
+          Dataset dataset = new Dataset();
+          dataset.Columns = origDataset.Columns;
+          double classAValue = classValues[i].Data;
+          double classBValue = classValues[j].Data;
+          int trainingSamplesStart;
+          int trainingSamplesEnd;
+          int validationSamplesStart;
+          int validationSamplesEnd;
+
+          trainingSamplesStart = 0;
+          List<double[]> rows = new List<double[]>();
+          for(int k = origTrainingSamplesStart; k < origTrainingSamplesEnd; k++) {
+            double[] row = new double[dataset.Columns];
+            double targetValue = origDataset.GetValue(k, targetVariable);
+            if(IsEqual(targetValue, classAValue)) {
+              for(int l = 0; l < row.Length; l++) {
+                row[l] = origDataset.GetValue(k, l);
+              }
+              row[targetVariable] = 0;
+              rows.Add(row);
+            } else if(IsEqual(targetValue, classBValue)) {
+              for(int l = 0; l < row.Length; l++) {
+                row[l] = origDataset.GetValue(k, l);
+              }
+              row[targetVariable] = 1.0;
+              rows.Add(row);
+            }
+          }
+          trainingSamplesEnd = rows.Count;
+          validationSamplesStart = rows.Count;
+          for(int k = origValidationSamplesStart; k < origValidationSamplesEnd; k++) {
+            double[] row = new double[dataset.Columns];
+            double targetValue = origDataset.GetValue(k, targetVariable);
+            if(IsEqual(targetValue, classAValue)) {
+              for(int l = 0; l < row.Length; l++) {
+                row[l] = origDataset.GetValue(k, l);
+              }
+              row[targetVariable] = 0;
+              rows.Add(row);
+            } else if(IsEqual(targetValue, classBValue)) {
+              for(int l = 0; l < row.Length; l++) {
+                row[l] = origDataset.GetValue(k, l);
+              }
+              row[targetVariable] = 1.0;
+              rows.Add(row);
+            }
+          }
+          validationSamplesEnd = rows.Count;
+
+          dataset.Rows = rows.Count;
+          dataset.Samples = new double[dataset.Rows * dataset.Columns];
+          for(int k = 0; k < dataset.Rows; k++) {
+            for(int l = 0; l < dataset.Columns; l++) {
+              dataset.SetValue(k, l, rows[k][l]);
+            }
+          }
+
+          Scope childScope = new Scope(classAValue+" vs. "+classBValue);
+
+          childScope.AddVariable(new Variable(scope.TranslateName(TARGETCLASSVALUES), binaryClassValues));
+          childScope.AddVariable(new Variable(scope.TranslateName(CLASSAVALUE), new DoubleData(classAValue)));
+          childScope.AddVariable(new Variable(scope.TranslateName(CLASSBVALUE), new DoubleData(classBValue)));
+          childScope.AddVariable(new Variable(scope.TranslateName(TRAININGSAMPLESSTART), new IntData(trainingSamplesStart)));
+          childScope.AddVariable(new Variable(scope.TranslateName(TRAININGSAMPLESEND), new IntData(trainingSamplesEnd)));
+          childScope.AddVariable(new Variable(scope.TranslateName(VALIDATIONSAMPLESSTART), new IntData(validationSamplesStart)));
+          childScope.AddVariable(new Variable(scope.TranslateName(VALIDATIONSAMPLESEND), new IntData(validationSamplesEnd)));
+          childScope.AddVariable(new Variable(scope.TranslateName(DATASET), dataset));
+          scope.AddSubScope(childScope);
+        }
+      }
+      return null;
+    }
+
+    private bool IsEqual(double x, double y) {
+      return Math.Abs(x - y) < EPSILON;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.StructureIdentification/MulticlassOneVsOneAnalyzer.cs
===================================================================
--- trunk/sources/HeuristicLab.StructureIdentification/MulticlassOneVsOneAnalyzer.cs	(revision 516)
+++ trunk/sources/HeuristicLab.StructureIdentification/MulticlassOneVsOneAnalyzer.cs	(revision 516)
@@ -0,0 +1,129 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.DataAnalysis;
+using HeuristicLab.Functions;
+
+namespace HeuristicLab.StructureIdentification {
+  public class MulticlassOneVsOneAnalyzer : OperatorBase {
+
+    private const string DATASET = "Dataset";
+    private const string TARGETVARIABLE = "TargetVariable";
+    private const string TARGETCLASSVALUES = "TargetClassValues";
+    private const string SAMPLESSTART = "SamplesStart";
+    private const string SAMPLESEND = "SamplesEnd";
+    private const string CLASSAVALUE = "ClassAValue";
+    private const string CLASSBVALUE = "ClassBValue";
+    private const string BESTMODELLSCOPE = "BestValidationSolution";
+    private const string BESTMODELL = "FunctionTree";
+    private const string VOTES = "Votes";
+    private const string ACCURACY = "Accuracy";
+
+    private const double EPSILON = 1E-6;
+    public override string Description {
+      get { return @"TASK"; }
+    }
+
+    public MulticlassOneVsOneAnalyzer()
+      : base() {
+      AddVariableInfo(new VariableInfo(DATASET, "The dataset to use", typeof(Dataset), VariableKind.In));
+      AddVariableInfo(new VariableInfo(TARGETVARIABLE, "Target variable", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo(TARGETCLASSVALUES, "Class values of the target variable in the original dataset", typeof(ItemList<DoubleData>), VariableKind.In));
+      AddVariableInfo(new VariableInfo(CLASSAVALUE, "The original class value of the class A in the subscope", typeof(DoubleData), VariableKind.In));
+      AddVariableInfo(new VariableInfo(CLASSBVALUE, "The original class value of the class B in the subscope", typeof(DoubleData), VariableKind.In));
+      AddVariableInfo(new VariableInfo(SAMPLESSTART, "The start of samples in the original dataset", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo(SAMPLESEND, "The end of samples in the original dataset", typeof(IntData), VariableKind.In));
+      AddVariableInfo(new VariableInfo(BESTMODELLSCOPE, "The variable containing the scope of the model (incl. meta data)", typeof(IScope), VariableKind.In));
+      AddVariableInfo(new VariableInfo(BESTMODELL, "The variable in the scope of the model that contains the actual model", typeof(IFunctionTree), VariableKind.In));
+      AddVariableInfo(new VariableInfo(VOTES, "Array with the votes for each instance", typeof(IntMatrixData), VariableKind.New));
+      AddVariableInfo(new VariableInfo(ACCURACY, "Accuracy of the one-vs-one multi-cass classifier", typeof(DoubleData), VariableKind.New));
+    }
+
+    public override IOperation Apply(IScope scope) {
+      Dataset dataset = GetVariableValue<Dataset>(DATASET, scope, true);
+      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
+      int samplesStart = GetVariableValue<IntData>(SAMPLESSTART, scope, true).Data;
+      int samplesEnd = GetVariableValue<IntData>(SAMPLESEND, scope, true).Data;
+      ItemList<DoubleData> classValues = GetVariableValue<ItemList<DoubleData>>(TARGETCLASSVALUES, scope, true);
+      int[,] votes = new int[samplesEnd - samplesStart, classValues.Count];
+
+      foreach(IScope childScope in scope.SubScopes) {
+        double classAValue = GetVariableValue<DoubleData>(CLASSAVALUE, childScope, true).Data;
+        double classBValue = GetVariableValue<DoubleData>(CLASSBVALUE, childScope, true).Data;
+        IScope bestScope = GetVariableValue<IScope>(BESTMODELLSCOPE, childScope, true);
+        IFunctionTree functionTree = GetVariableValue<IFunctionTree>(BESTMODELL, bestScope, true);
+
+        IEvaluator evaluator = functionTree.CreateEvaluator();
+        evaluator.ResetEvaluator(functionTree, dataset);
+
+        for(int i = 0; i < (samplesEnd - samplesStart); i++) {
+          double est = evaluator.Evaluate(i + samplesStart);
+          if(est < 0.5) {
+            CastVote(votes, i, classAValue, classValues);
+          } else {
+            CastVote(votes, i, classBValue, classValues);
+          }
+        }
+      }
+
+      int correctlyClassified = 0;
+      for(int i = 0; i < (samplesEnd - samplesStart); i++) {
+        double originalClassValue = dataset.GetValue(i + samplesStart, targetVariable);
+        double estimatedClassValue = classValues[0].Data;
+        int maxVotes = votes[i, 0];
+        int sameVotes = 0;
+        for(int j = 1; j < classValues[j].Data; j++) {
+          if(votes[i, j] > maxVotes) {
+            maxVotes = votes[i, j];
+            estimatedClassValue = classValues[j].Data;
+            sameVotes = 0;
+          } else if(votes[i, j] == maxVotes) {
+            sameVotes++;
+          }
+        }
+        if(IsEqual(originalClassValue, estimatedClassValue) && sameVotes == 0) correctlyClassified++;
+      }
+
+      double accuracy = correctlyClassified / (double)(samplesEnd - samplesStart);
+
+      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(VOTES), new IntMatrixData(votes)));
+      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(ACCURACY), new DoubleData(accuracy)));
+      return null;
+    }
+
+    private void CastVote(int[,] votes, int sample, double votedClass, ItemList<DoubleData> classValues) {
+      for(int i = 0; i < classValues.Count; i++) {
+        if(IsEqual(classValues[i].Data, votedClass)) votes[sample, i]++;
+      }
+    }
+
+    private bool IsEqual(double x, double y) {
+      return Math.Abs(x - y) < EPSILON;
+    }
+  }
+}
