- Timestamp:
- 03/23/11 13:52:29 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r5809 r5818 77 77 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 78 78 var model = new SymbolicDiscriminantFunctionClassificationModel(bestTree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 79 var solution = new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemDataParameter.ActualValue);80 79 if (ApplyLinearScaling.Value) { 81 solution.ScaleModel();80 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 82 81 } 83 return solution;82 return new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemDataParameter.ActualValue); 84 83 } 85 84 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs
r5809 r5818 66 66 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQualities) { 67 67 var model = new SymbolicDiscriminantFunctionClassificationModel(bestTree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 68 var solution = new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemDataParameter.ActualValue);69 68 if (ApplyLinearScaling.Value) { 70 solution.ScaleModel();69 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 71 70 } 72 return solution;71 return new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemDataParameter.ActualValue); 73 72 } 74 73 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs
r5809 r5818 75 75 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 76 76 var model = new SymbolicDiscriminantFunctionClassificationModel(bestTree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 77 var solution = new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemDataParameter.ActualValue);78 77 if (ApplyLinearScaling.Value) { 79 solution.ScaleModel();78 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 80 79 } 81 return solution;80 return new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemDataParameter.ActualValue); 82 81 } 83 82 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs
r5809 r5818 66 66 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 67 67 var model = new SymbolicDiscriminantFunctionClassificationModel(bestTree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 68 var solution = new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemDataParameter.ActualValue);69 68 if (ApplyLinearScaling.Value) { 70 solution.ScaleModel();69 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 71 70 } 72 return solution;71 return new SymbolicDiscriminantFunctionClassificationSolution(model, ProblemDataParameter.ActualValue); 73 72 } 74 73 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs
r5809 r5818 115 115 } 116 116 #endregion 117 118 public static void Scale(SymbolicDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData) { 119 var dataset = problemData.Dataset; 120 var targetVariable = problemData.TargetVariable; 121 var rows = problemData.TrainingIndizes; 122 var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows); 123 var targetValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 124 double alpha; 125 double beta; 126 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta); 127 128 ConstantTreeNode alphaTreeNode = null; 129 ConstantTreeNode betaTreeNode = null; 130 // check if model has been scaled previously by analyzing the structure of the tree 131 var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0); 132 if (startNode.GetSubtree(0).Symbol is Addition) { 133 var addNode = startNode.GetSubtree(0); 134 if (addNode.SubtreesCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) { 135 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode; 136 var mulNode = addNode.GetSubtree(0); 137 if (mulNode.SubtreesCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) { 138 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode; 139 } 140 } 141 } 142 // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes 143 if (alphaTreeNode != null && betaTreeNode != null) { 144 betaTreeNode.Value *= beta; 145 alphaTreeNode.Value *= beta; 146 alphaTreeNode.Value += alpha; 147 } else { 148 var mainBranch = startNode.GetSubtree(0); 149 startNode.RemoveSubtree(0); 150 var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha); 151 startNode.AddSubtree(scaledMainBranch); 152 } 153 } 154 155 private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) { 156 if (alpha.IsAlmost(0.0)) { 157 return treeNode; 158 } else { 159 var node = (new Addition()).CreateTreeNode(); 160 var alphaConst = MakeConstant(alpha); 161 node.AddSubtree(treeNode); 162 node.AddSubtree(alphaConst); 163 return node; 164 } 165 } 166 167 private static ISymbolicExpressionTreeNode MakeProduct(double beta, ISymbolicExpressionTreeNode treeNode) { 168 if (beta.IsAlmost(1.0)) { 169 return treeNode; 170 } else { 171 var node = (new Multiplication()).CreateTreeNode(); 172 var betaConst = MakeConstant(beta); 173 node.AddSubtree(treeNode); 174 node.AddSubtree(betaConst); 175 return node; 176 } 177 } 178 179 private static ISymbolicExpressionTreeNode MakeConstant(double c) { 180 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 181 node.Value = c; 182 return node; 183 } 117 184 } 118 185 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationSolution.cs
r5809 r5818 87 87 ModelLength = Model.SymbolicExpressionTree.Length; 88 88 ModelDepth = Model.SymbolicExpressionTree.Depth; 89 } 90 91 public void ScaleModel() { 92 var dataset = ProblemData.Dataset; 93 var targetVariable = ProblemData.TargetVariable; 94 var rows = ProblemData.TrainingIndizes; 95 var estimatedValues = GetEstimatedValues(rows); 96 var targetValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 97 double alpha; 98 double beta; 99 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta); 100 101 ConstantTreeNode alphaTreeNode = null; 102 ConstantTreeNode betaTreeNode = null; 103 // check if model has been scaled previously by analyzing the structure of the tree 104 var startNode = Model.SymbolicExpressionTree.Root.GetSubtree(0); 105 if (startNode.GetSubtree(0).Symbol is Addition) { 106 var addNode = startNode.GetSubtree(0); 107 if (addNode.SubtreesCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) { 108 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode; 109 var mulNode = addNode.GetSubtree(0); 110 if (mulNode.SubtreesCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) { 111 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode; 112 } 113 } 114 } 115 // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes 116 if (alphaTreeNode != null && betaTreeNode != null) { 117 betaTreeNode.Value *= beta; 118 alphaTreeNode.Value *= beta; 119 alphaTreeNode.Value += alpha; 120 } else { 121 var mainBranch = startNode.GetSubtree(0); 122 startNode.RemoveSubtree(0); 123 var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha); 124 startNode.AddSubtree(scaledMainBranch); 125 } 126 127 OnModelChanged(EventArgs.Empty); 128 } 129 130 private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) { 131 if (alpha.IsAlmost(0.0)) { 132 return treeNode; 133 } else { 134 var node = (new Addition()).CreateTreeNode(); 135 var alphaConst = MakeConstant(alpha); 136 node.AddSubtree(treeNode); 137 node.AddSubtree(alphaConst); 138 return node; 139 } 140 } 141 142 private static ISymbolicExpressionTreeNode MakeProduct(double beta, ISymbolicExpressionTreeNode treeNode) { 143 if (beta.IsAlmost(1.0)) { 144 return treeNode; 145 } else { 146 var node = (new Multiplication()).CreateTreeNode(); 147 var betaConst = MakeConstant(beta); 148 node.AddSubtree(treeNode); 149 node.AddSubtree(betaConst); 150 return node; 151 } 152 } 153 154 private static ISymbolicExpressionTreeNode MakeConstant(double c) { 155 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 156 node.Value = c; 157 return node; 158 } 89 } 159 90 } 160 91 }
Note: See TracChangeset
for help on using the changeset viewer.