当前位置: 首页>>代码示例>>C#>>正文


C# ISymbolicExpressionTree类代码示例

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


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


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