Changeset 18237
- Timestamp:
- 03/14/22 14:15:52 (3 years ago)
- Location:
- branches/3040_VectorBasedGP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/VectorUnrollingNonlinearLeastSquaresConstantOptimizationEvaluator.cs
r18234 r18237 182 182 int i = 0; 183 183 foreach (var node in tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>()) { 184 ConstantTreeNode constantTreeNode = node as ConstantTreeNode; 185 VariableTreeNodeBase variableTreeNodeBase = node as VariableTreeNodeBase; 186 FactorVariableTreeNode factorVarTreeNode = node as FactorVariableTreeNode; 187 if (constantTreeNode != null) 184 if (node is ConstantTreeNode constantTreeNode) { 188 185 constantTreeNode.Value = constants[i++]; 189 else if (updateVariableWeights && variableTreeNodeBase != null)186 } else if (updateVariableWeights && node is VariableTreeNodeBase variableTreeNodeBase) { 190 187 variableTreeNodeBase.Weight = constants[i++]; 191 else if (factorVarTreeNode != null) {188 } else if (node is FactorVariableTreeNode factorVarTreeNode) { 192 189 for (int j = 0; j < factorVarTreeNode.Weights.Length; j++) 193 190 factorVarTreeNode.Weights[j] = constants[i++]; -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToTensorConverter.cs
r17554 r18237 120 120 if (node.Symbol is Addition) { 121 121 var terms = node.Subtrees.Select(ConvertNode).ToList(); 122 if (terms.Count == 1) return terms[0]; 122 123 return terms.Aggregate((a, b) => a + b); 123 124 } … … 131 132 if (node.Symbol is Multiplication) { 132 133 var terms = node.Subtrees.Select(ConvertNode).ToList(); 134 if (terms.Count == 1) return terms[0]; 133 135 return terms.Aggregate((a, b) => a * b); 134 136 } … … 152 154 153 155 if (node.Symbol is Logarithm) { 154 return math_ops.log(156 return tf.log( 155 157 ConvertNode(node.GetSubtree(0))); 156 158 } 157 159 158 160 if (node.Symbol is Exponential) { 159 return math_ops.pow(161 return tf.pow( 160 162 (float)Math.E, 161 163 ConvertNode(node.GetSubtree(0))); … … 168 170 169 171 if (node.Symbol is SquareRoot) { 170 return math_ops.sqrt(172 return tf.sqrt( 171 173 ConvertNode(node.GetSubtree(0))); 172 174 } 173 175 174 176 if (node.Symbol is Cube) { 175 return math_ops.pow(177 return tf.pow( 176 178 ConvertNode(node.GetSubtree(0)), 3.0f); 177 179 } 178 180 179 181 if (node.Symbol is CubeRoot) { 180 return math_ops.pow(182 return tf.pow( 181 183 ConvertNode(node.GetSubtree(0)), 1.0f / 3.0f); 182 184 // TODO … … 207 209 } 208 210 209 //if (node.Symbol is StandardDeviation) { 210 // return tf.reduce_std( 211 // ConvertNode(node.GetSubtree(0)), 212 // axis: new [] { 1 } 213 // ); 214 //} 211 if (node.Symbol is StandardDeviation) { 212 return reduce_std( 213 ConvertNode(node.GetSubtree(0)), 214 axis: new[] { 1 }, 215 keepdims: true 216 ); 217 } 218 219 if (node.Symbol is Variance) { 220 return reduce_var( 221 ConvertNode(node.GetSubtree(0)), 222 axis: new[] { 1 } , 223 keepdims: true 224 ); 225 } 215 226 216 227 if (node.Symbol is Sum) { … … 220 231 keepdims: true); 221 232 } 233 234 if (node.Symbol is SubVector) { 235 var tensor = ConvertNode(node.GetSubtree(0)); 236 int rows = tensor.shape[0], vectorLength = tensor.shape[1]; 237 var windowedNode = (IWindowedSymbolTreeNode)node; 238 int startIdx = SymbolicDataAnalysisExpressionTreeVectorInterpreter.ToVectorIdx(windowedNode.Offset, vectorLength); 239 int endIdx = SymbolicDataAnalysisExpressionTreeVectorInterpreter.ToVectorIdx(windowedNode.Length, vectorLength); 240 var slices = SymbolicDataAnalysisExpressionTreeVectorInterpreter.GetVectorSlices(startIdx, endIdx, vectorLength); 241 242 var segments = new List<Tensor>(); 243 foreach (var (start, count) in slices) { 244 segments.Add(tensor[new Slice(), new Slice(start, start + count)]); 245 } 246 return tf.concat(segments.ToArray(), axis: 1); 247 } 248 222 249 223 250 if (node.Symbol is StartSymbol) { … … 237 264 } 238 265 239 return tf.re duce_sum(prediction, axis: new[] {1 });266 return tf.reshape(prediction, shape: new[] { -1 }); 240 267 } 241 268 242 269 throw new NotSupportedException($"Node symbol {node.Symbol} is not supported."); 270 } 271 272 private static Tensor reduce_var(Tensor input_tensor, int[] axis = null, bool keepdims = false) { 273 var means = tf.reduce_mean(input_tensor, axis, true); 274 var squared_deviation = tf.square(input_tensor - means); 275 return tf.reduce_mean(squared_deviation, axis, keepdims); 276 } 277 private static Tensor reduce_std(Tensor input_tensor, int[] axis = null, bool keepdims = false) { 278 return tf.sqrt(reduce_var(input_tensor, axis, keepdims)); 243 279 } 244 280 … … 271 307 !(n.Symbol is CubeRoot) && 272 308 !(n.Symbol is Mean) && 273 //!(n.Symbol is StandardDeviation) && 274 !(n.Symbol is Sum) 309 !(n.Symbol is StandardDeviation) && 310 !(n.Symbol is Variance) && 311 !(n.Symbol is Sum) && 312 !(n.Symbol is SubVector) 275 313 select n).Any(); 276 314 return !containsUnknownSymbol; -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r18060 r18237 339 339 { typeof(NumberPeaksOfSize), OpCodes.NumberPeaksOfSize }, 340 340 { typeof(LargeNumberOfPeaks), OpCodes.LargeNumberOfPeaks }, 341 { typeof(TimeReversalAsymmetryStatistic), OpCodes.TimeReversalAsymmetryStatistic }, 341 { typeof(TimeReversalAsymmetryStatistic), OpCodes.TimeReversalAsymmetryStatistic }, 342 342 #endregion 343 343 };
Note: See TracChangeset
for help on using the changeset viewer.