Changeset 236
- Timestamp:
- 05/12/08 22:31:35 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs
r235 r236 104 104 105 105 private static double EvaluateBakedCode() { 106 int arity = codeArr[PC++]; 107 int functionSymbol = codeArr[PC++]; 108 int nLocalVariables = codeArr[PC++]; 106 int arity = codeArr[PC]; 107 int functionSymbol = codeArr[PC+1]; 108 int nLocalVariables = codeArr[PC+2]; 109 PC += 3; 109 110 switch(functionSymbol) { 110 111 case VARIABLE: { 111 int var = (int)dataArr[DP ++];112 double weight = dataArr[DP+ +];113 int offset = (int)dataArr[DP++];114 int row = sampleIndex + offset;112 int var = (int)dataArr[DP]; 113 double weight = dataArr[DP+1]; 114 int row = sampleIndex + (int)dataArr[DP+2]; 115 DP += 3; 115 116 if(row < 0 || row >= dataset.Rows) return double.NaN; 116 117 else return weight * dataset.GetValue(row, var); 117 118 } 118 119 case CONSTANT: { 119 double value = dataArr[DP++]; 120 return value; 120 return dataArr[DP++]; 121 121 } 122 122 case MULTIPLICATION: { 123 double result = 1.0;124 for(int i = 0; i < arity; i++) {123 double result = EvaluateBakedCode(); 124 for(int i = 1; i < arity; i++) { 125 125 result *= EvaluateBakedCode(); 126 126 } … … 128 128 } 129 129 case ADDITION: { 130 double sum = 0.0;131 for(int i = 0; i < arity; i++) {130 double sum = EvaluateBakedCode(); 131 for(int i = 1; i < arity; i++) { 132 132 sum += EvaluateBakedCode(); 133 133 } … … 146 146 } 147 147 case DIVISION: { 148 double result; 148 149 if(arity == 1) { 149 double divisor = EvaluateBakedCode(); 150 if(divisor == 0) return 0; 151 else return 1.0 / divisor; 150 result = 1.0 / EvaluateBakedCode(); 152 151 } else { 153 doubleresult = EvaluateBakedCode();152 result = EvaluateBakedCode(); 154 153 for(int i = 1; i < arity; i++) { 155 double divisor = EvaluateBakedCode(); 156 if(divisor == 0) result = 0; 157 else result /= divisor; 154 result /= EvaluateBakedCode(); 158 155 } 159 return result; 160 } 156 } 157 if(double.IsInfinity(result)) return 0.0; 158 else return result; 161 159 } 162 160 case AVERAGE: { 163 double sum = 0.0;164 for(int i = 0; i < arity; i++) {161 double sum = EvaluateBakedCode(); 162 for(int i = 1; i < arity; i++) { 165 163 sum += EvaluateBakedCode(); 166 164 } … … 185 183 } 186 184 case SIGNUM: { 187 // protected signum188 185 double value = EvaluateBakedCode(); 189 if(value < 0) return -1; 190 if(value > 0) return 1; 191 return 0; 186 if(double.IsNaN(value)) return double.NaN; 187 else return Math.Sign(value); 192 188 } 193 189 case SQRT: { … … 203 199 for(int i = 0; i < arity; i++) { 204 200 double x = Math.Round(EvaluateBakedCode()); 205 if(x == 0) result *= 0; 206 else if(x == 1.0) result *= 1.0; 207 else result *= double.NaN; 201 if(x == 0 || x==1.0) result *= x; 202 else result = double.NaN; 208 203 } 209 204 return result;
Note: See TracChangeset
for help on using the changeset viewer.