Changeset 17851


Ignore:
Timestamp:
02/26/21 09:51:21 (17 months ago)
Author:
gkronber
Message:

#3106 Create solution for best individual of each generation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3106_AnalyticContinuedFractionsRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/ContinuedFractionRegression/Problem.cs

    r17850 r17851  
    1414using HeuristicLab.Problems.DataAnalysis;
    1515using HeuristicLab.Problems.DataAnalysis.Symbolic;
     16using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    1617using HeuristicLab.Problems.Instances;
    1718
     
    417418      #endregion
    418419
    419       results.AddOrUpdateResult("Model", CreateSymbolicExpressionTree(binar, coeff, TrainingTrainingDataset.VariableNames.ToArray()));
     420      #region create tree and regression solution
     421      var allVariables = TrainingTrainingDataset.VariableNames;
     422      var allowedInputVariables = allVariables.Take(allVariables.Count() - 1);
     423      var targetVariable = allVariables.Last();
     424
     425      var tree = CreateSymbolicExpressionTree(binar, coeff, TrainingTrainingDataset.VariableNames.ToArray());
     426      var model = new SymbolicRegressionModel(targetVariable, tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter());
     427      var combinedData = MatrixExtensions.VertCat(dataMatrix.CloneAsMatrix(), dataMatrixTest.CloneAsMatrix());
     428      var combinedDs = new Dataset(allVariables, combinedData);
     429      var problemData = new RegressionProblemData(combinedDs, allowedInputVariables, targetVariable);
     430      problemData.TrainingPartition.Start = 0;
     431      problemData.TrainingPartition.End = dataMatrix.Rows;
     432      problemData.TestPartition.Start = dataMatrix.Rows;
     433      problemData.TestPartition.End = combinedDs.Rows;
     434      var sol = new SymbolicRegressionSolution(model, problemData);
     435      results.AddOrUpdateResult("Solution", sol);
     436      #endregion
    420437    }
    421438
     
    457474
    458475      var startNode = startSy.CreateTreeNode();
    459       var progRootNode = progRootSy.CreateTreeNode();
    460       startNode.AddSubtree(progRootNode);
    461       progRootNode.AddSubtree(expression);
    462       return new SymbolicExpressionTree(progRootNode) ;
     476      var progRoot = progRootSy.CreateTreeNode();
     477      progRoot.AddSubtree(startNode);
     478      startNode.AddSubtree(expression);
     479      return new SymbolicExpressionTree(progRoot) ;
    463480    }
    464481
Note: See TracChangeset for help on using the changeset viewer.