• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ISymbolicExpressionTree类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ISymbolicExpressionTree的典型用法代码示例。如果您正苦于以下问题:C# ISymbolicExpressionTree类的具体用法?C# ISymbolicExpressionTree怎么用?C# ISymbolicExpressionTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ISymbolicExpressionTree类属于命名空间,在下文中一共展示了ISymbolicExpressionTree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CalculateImpactAndReplacementValues

    protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) {
      var interpreter = Content.Model.Interpreter;
      var rows = Content.ProblemData.TrainingIndices;
      var dataset = Content.ProblemData.Dataset;
      var targetVariable = Content.ProblemData.TargetVariable;
      var targetValues = dataset.GetDoubleValues(targetVariable, rows);
      var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows).ToArray();

      var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();
      List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();
      OnlineCalculatorError errorState;
      double originalR = OnlinePearsonsRCalculator.Calculate(targetValues, originalOutput, out errorState);
      if (errorState != OnlineCalculatorError.None) originalR = 0.0;

      foreach (ISymbolicExpressionTreeNode node in nodes) {
        var parent = node.Parent;
        constantNode.Value = CalculateReplacementValue(node, tree);
        ISymbolicExpressionTreeNode replacementNode = constantNode;
        SwitchNode(parent, node, replacementNode);
        var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);
        double newR = OnlinePearsonsRCalculator.Calculate(targetValues, newOutput, out errorState);
        if (errorState != OnlineCalculatorError.None) newR = 0.0;

        // impact = 0 if no change
        // impact < 0 if new solution is better
        // impact > 0 if new solution is worse
        double impact = (originalR * originalR) - (newR * newR);
        impactAndReplacementValues[node] = new Tuple<double, double>(impact, constantNode.Value);
        SwitchNode(parent, replacementNode, node);
      }
      return impactAndReplacementValues;
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:32,代码来源:InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs


示例2: Prune

    public static ISymbolicExpressionTree Prune(ISymbolicExpressionTree tree, SymbolicRegressionSolutionImpactValuesCalculator impactValuesCalculator, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IRegressionProblemData problemData, DoubleLimit estimationLimits, IEnumerable<int> rows, double nodeImpactThreshold = 0.0, bool pruneOnlyZeroImpactNodes = false) {
      var clonedTree = (ISymbolicExpressionTree)tree.Clone();
      var model = new SymbolicRegressionModel(problemData.TargetVariable, clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
      var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); // skip the nodes corresponding to the ProgramRootSymbol and the StartSymbol

      double qualityForImpactsCalculation = double.NaN; // pass a NaN value initially so the impact calculator will calculate the quality

      for (int i = 0; i < nodes.Count; ++i) {
        var node = nodes[i];
        if (node is ConstantTreeNode) continue;

        double impactValue, replacementValue;
        double newQualityForImpactsCalculation;
        impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);

        if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue;
        if (!pruneOnlyZeroImpactNodes && impactValue > nodeImpactThreshold) continue;

        var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();
        constantNode.Value = replacementValue;

        ReplaceWithConstant(node, constantNode);
        i += node.GetLength() - 1; // skip subtrees under the node that was folded

        qualityForImpactsCalculation = newQualityForImpactsCalculation;
      }
      return model.SymbolicExpressionTree;
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:28,代码来源:SymbolicRegressionPruningOperator.cs


示例3: CreateModel

 protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {
   var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
   var classificationProblemData = (IClassificationProblemData)problemData;
   var rows = classificationProblemData.TrainingIndices;
   model.RecalculateModelParameters(classificationProblemData, rows);
   return model;
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:SymbolicClassificationPruningOperator.cs


示例4: Manipulate

 protected override void Manipulate(IRandom random, ISymbolicExpressionTree tree) {
   tree.Root.ForEachNodePostfix(node => {
     if (node.HasLocalParameters) {
       node.ShakeLocalParameters(random, ShakingFactor);
     }
   });
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:7,代码来源:FullTreeShaker.cs


示例5: Solution

 public Solution(ISymbolicExpressionTree tree, string path, int nrOfRounds, EnemyCollection enemies)
   : base() {
   this.Tree = tree;
   this.Path = path;
   this.NrOfRounds = nrOfRounds;
   this.Enemies = enemies;
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:Solution.cs


示例6: Compile

    public static Instruction[] Compile(ISymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper, IEnumerable<Func<Instruction, Instruction>> postInstructionCompiledHooks) {
      Dictionary<string, ushort> entryPoint = new Dictionary<string, ushort>();
      List<Instruction> code = new List<Instruction>();
      // compile main body branches
      foreach (var branch in tree.Root.GetSubtree(0).Subtrees) {
        code.AddRange(Compile(branch, opCodeMapper, postInstructionCompiledHooks));
      }
      // compile function branches
      var functionBranches = from node in tree.IterateNodesPrefix()
                             where node.Symbol is Defun
                             select node;
      foreach (DefunTreeNode branch in functionBranches) {
        if (code.Count > ushort.MaxValue) throw new ArgumentException("Code for the tree is too long (> ushort.MaxValue).");
        entryPoint[branch.FunctionName] = (ushort)code.Count;
        code.AddRange(Compile(branch.GetSubtree(0), opCodeMapper, postInstructionCompiledHooks));
      }
      // address of all functions is fixed now
      // iterate through code again and fill in the jump locations
      for (int i = 0; i < code.Count; i++) {
        Instruction instr = code[i];
        if (instr.dynamicNode.Symbol is InvokeFunction) {
          var invokeNode = (InvokeFunctionTreeNode)instr.dynamicNode;
          instr.data = entryPoint[invokeNode.Symbol.FunctionName];
        }
      }

      return code.ToArray();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:28,代码来源:SymbolicExpressionTreeCompiler.cs


示例7: Calculate

    public static double Calculate(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows, IntRange evaluationPartition, int horizon, bool applyLinearScaling) {
      var horizions = rows.Select(r => Math.Min(horizon, evaluationPartition.End - r));
      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows.Zip(horizions, Enumerable.Range).SelectMany(r => r));
      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows, horizions).SelectMany(x => x);
      OnlineCalculatorError errorState;

      double mse;
      if (applyLinearScaling && horizon == 1) { //perform normal evaluation and afterwards scale the solution and calculate the fitness value        
        var mseCalculator = new OnlineMeanSquaredErrorCalculator();
        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows * horizon);
        errorState = mseCalculator.ErrorState;
        mse = mseCalculator.MeanSquaredError;
      } else if (applyLinearScaling) { //first create model to perform linear scaling and afterwards calculate fitness for the scaled model
        var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)solution.Clone(), interpreter, lowerEstimationLimit, upperEstimationLimit);
        model.Scale(problemData);
        var scaledSolution = model.SymbolicExpressionTree;
        estimatedValues = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset, rows, horizions).SelectMany(x => x);
        var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
      } else {
        var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
      }

      if (errorState != OnlineCalculatorError.None) return Double.NaN;
      else return mse;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:27,代码来源:SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs


示例8: SymbolicDiscriminantFunctionClassificationModel

 public SymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDiscriminantFunctionThresholdCalculator thresholdCalculator,
   double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
   : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
   this.thresholds = new double[0];
   this.classValues = new double[0];
   this.ThresholdCalculator = thresholdCalculator;
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:SymbolicDiscriminantFunctionClassificationModel.cs


示例9: DeleteSubroutine

    public static bool DeleteSubroutine(
      IRandom random,
      ISymbolicExpressionTree symbolicExpressionTree,
      int maxFunctionDefinitions, int maxFunctionArguments) {
      var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList();

      if (!functionDefiningBranches.Any())
        // no ADF to delete => abort
        return false;

      var selectedDefunBranch = functionDefiningBranches.SampleRandom(random);
      // remove the selected defun
      int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSubtree(selectedDefunBranch);
      symbolicExpressionTree.Root.RemoveSubtree(defunSubtreeIndex);

      // remove references to deleted function
      foreach (var subtree in symbolicExpressionTree.Root.Subtrees.OfType<SymbolicExpressionTreeTopLevelNode>()) {
        var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>()
                                    where symb.FunctionName == selectedDefunBranch.FunctionName
                                    select symb).SingleOrDefault();
        if (matchingInvokeSymbol != null) {
          subtree.Grammar.RemoveSymbol(matchingInvokeSymbol);
        }
      }

      DeletionByRandomRegeneration(random, symbolicExpressionTree, selectedDefunBranch);
      return true;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:28,代码来源:SubroutineDeleter.cs


示例10: Solution

 public Solution(ISymbolicExpressionTree tree, int length, int width, double quality)
   : base("Solution", "A lawn mower solution.") {
   this.Tree = tree;
   this.Length = length;
   this.Width = width;
   this.Quality = quality;
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:7,代码来源:Solution.cs


示例11: RemoveRandomBranch

    public static void RemoveRandomBranch(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, int maxTreeLength, int maxTreeDepth) {
      var allowedSymbols = new List<ISymbol>();
      ISymbolicExpressionTreeNode parent;
      int childIndex;
      int maxLength;
      int maxDepth;
      // repeat until a fitting parent and child are found (MAX_TRIES times)
      int tries = 0;

      var nodes = symbolicExpressionTree.Root.IterateNodesPrefix().Skip(1).Where(n => n.SubtreeCount > 0).ToList();
      do {
        parent = nodes.SampleRandom(random);

        childIndex = random.Next(parent.SubtreeCount);
        var child = parent.GetSubtree(childIndex);
        maxLength = maxTreeLength - symbolicExpressionTree.Length + child.GetLength();
        maxDepth = maxTreeDepth - symbolicExpressionTree.Root.GetBranchLevel(child);

        allowedSymbols.Clear();
        foreach (var symbol in parent.Grammar.GetAllowedChildSymbols(parent.Symbol, childIndex)) {
          // check basic properties that the new symbol must have
          if ((symbol.Name != child.Symbol.Name || symbol.MinimumArity > 0) &&
            symbol.InitialFrequency > 0 &&
            parent.Grammar.GetMinimumExpressionDepth(symbol) <= maxDepth &&
            parent.Grammar.GetMinimumExpressionLength(symbol) <= maxLength) {
            allowedSymbols.Add(symbol);
          }
        }
        tries++;
      } while (tries < MAX_TRIES && allowedSymbols.Count == 0);

      if (tries >= MAX_TRIES) return;
      ReplaceWithMinimalTree(random, symbolicExpressionTree.Root, parent, childIndex);
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:34,代码来源:RemoveBranchManipulation.cs


示例12: Interpreter

 public Interpreter(ISymbolicExpressionTree tree, BoolMatrix world, int maxTimeSteps) {
   this.Expression = tree;
   this.MaxTimeSteps = maxTimeSteps;
   // create a clone of the world because the ant will remove the food items it can find.
   World = (BoolMatrix)world.Clone();
   CountFoodItems();
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:Interpreter.cs


示例13: CalculateSimilarity

    public double CalculateSimilarity(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
      if (t1 == t2)
        return 1;

      var map = ComputeBottomUpMapping(t1.Root, t2.Root);
      return 2.0 * map.Count / (t1.Length + t2.Length);
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:SymbolicExpressionTreeBottomUpSimilarityCalculator.cs


示例14: Format

 public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
   int nodeCounter = 1;
   StringBuilder strBuilder = new StringBuilder();
   strBuilder.AppendLine("graph {");
   strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root, 0, ref nodeCounter));
   strBuilder.AppendLine("}");
   return strBuilder.ToString();
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:8,代码来源:SymbolicExpressionTreeGraphvizFormatter.cs


示例15: Calculate

 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, IProblemData problemData, IEnumerable<int> rows) {
   IEnumerable<double> signals = GetSignals(interpreter, solution, problemData.Dataset, rows);
   IEnumerable<double> returns = problemData.Dataset.GetDoubleValues(problemData.PriceChangeVariable, rows);
   OnlineCalculatorError errorState;
   double sharpRatio = OnlineSharpeRatioCalculator.Calculate(returns, signals, problemData.TransactionCosts, out errorState);
   if (errorState != OnlineCalculatorError.None) return 0.0;
   else return sharpRatio;
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:8,代码来源:SharpeRatioEvaluator.cs


示例16: CreateModel

    /// <summary>
    /// It is necessary to create new models of an unknown type with new trees in the simplifier.
    /// For this purpose the cloner is used by registering the new tree as already cloned object and invoking the clone mechanism.
    /// This results in a new model of the same type as the old one with an exchanged tree.
    /// </summary>
    /// <param name="tree">The new tree that should be included in the new object</param>
    /// <returns></returns>
    protected ISymbolicClassificationModel CreateModel(ISymbolicExpressionTree tree) {
      var cloner = new Cloner();
      cloner.RegisterClonedObject(Content.Model.SymbolicExpressionTree, tree);

      var model = (ISymbolicClassificationModel)Content.Model.Clone(cloner);
      model.RecalculateModelParameters(Content.ProblemData, Content.ProblemData.TrainingIndices);
      return model;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:15,代码来源:InteractiveSymbolicClassificationSolutionSimplifierViewBase.cs


示例17: Simplify

 public ISymbolicExpressionTree Simplify(ISymbolicExpressionTree originalTree) {
   var clone = (ISymbolicExpressionTreeNode)originalTree.Root.Clone();
   // macro expand (initially no argument trees)
   var macroExpandedTree = MacroExpand(clone, clone.GetSubtree(0), new List<ISymbolicExpressionTreeNode>());
   ISymbolicExpressionTreeNode rootNode = (new ProgramRootSymbol()).CreateTreeNode();
   rootNode.AddSubtree(GetSimplifiedTree(macroExpandedTree));
   return new SymbolicExpressionTree(rootNode);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:8,代码来源:SymbolicDataAnalysisExpressionTreeSimplifier.cs


示例18: Format

 public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
   // skip root and start symbols
   StringBuilder strBuilder = new StringBuilder();
   GenerateHeader(strBuilder, symbolicExpressionTree);
   FormatRecursively(symbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0), strBuilder);
   GenerateFooter(strBuilder);
   return strBuilder.ToString();
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:8,代码来源:SymbolicDataAnalysisExpressionCSharpFormatter.cs


示例19: CalculateImpactAndReplacementValues

 protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) {
   var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();
   foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     double impactValue, replacementValue, newQualityForImpactsCalculation;
     calculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);
     impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue));
   }
   return impactAndReplacementValues;
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:9,代码来源:InteractiveSymbolicRegressionSolutionSimplifierView.cs


示例20: Calculate

 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
   IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
   IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
   IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
   OnlineCalculatorError errorState;
   double mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState);
   if (errorState != OnlineCalculatorError.None) mse = double.NaN;
   return new double[2] { mse, solution.Length };
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:9,代码来源:SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs



注:本文中的ISymbolicExpressionTree类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ISymbolicExpressionTreeNode类代码示例发布时间:2022-05-24
下一篇:
C# ISymbolWriter类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap