Ejemplo n.º 1
0
 public OperatorControl(Operator @operator)
 {
     Orientation = Orientation.Horizontal;
     Operator = @operator;
     _checkBox = new CheckBox { Content = Operator.Name, Width = 50};
     SliderWithValueText sliderWithValueText = new SliderWithValueText(190, 0, 100, 50);
     _probabilitySlider = sliderWithValueText.Slider;
     Children.Add(_checkBox);
     Children.Add(sliderWithValueText);
 }
Ejemplo n.º 2
0
        public static FormulaGenerationArguments CreateRandom(Random random, Bounds<int> dimensionCountBounds, Bounds<int> minimalDepthBounds,
            Bounds leafProbabilityBounds, Bounds constantProbabilityBounds, Bounds constantBounds, IDictionary<Operator, Bounds> operatorAndMaxProbabilityBoundsMap,
            Operator[] obligatoryOperators, Bounds unaryVsBinaryOperatorsProbabilityBounds)
        {
            Dictionary<Operator, double> operatorAndProbabilityMap = operatorAndMaxProbabilityBoundsMap.ToDictionary(e => e.Key, e => random.Next(e.Value));
            Operator[] unaryOperators = operatorAndMaxProbabilityBoundsMap.Keys.Where(op => op.Arity == 1).ToArray();
            Operator[] binaryOperators = operatorAndMaxProbabilityBoundsMap.Keys.Where(op => op.Arity == 2).ToArray();
            int unaryOperatorsToDeleteCount = random.Next(new Bounds<int>(0, unaryOperators.Length - 1));
            int binaryOperatorsToDeleteCount = random.Next(new Bounds<int>(0, binaryOperators.Length - 1));
            var unaryOperatorsToDelete = random.TakeDistinct(unaryOperators, unaryOperatorsToDeleteCount).Where(op => obligatoryOperators.All(o => o != op));
            var binaryOperatorsToDelete = random.TakeDistinct(binaryOperators, binaryOperatorsToDeleteCount).Where(op => obligatoryOperators.All(o => o != op));
            var operatorsToDelete = unaryOperatorsToDelete.Concat(binaryOperatorsToDelete);
            foreach (var op in operatorsToDelete)
            {
                operatorAndProbabilityMap.Remove(op);
            }

            double ubp = random.Next(unaryVsBinaryOperatorsProbabilityBounds);
            double ups = operatorAndProbabilityMap.Where(e => e.Key.Arity == 1).Sum(e => e.Value);
            double bps = operatorAndProbabilityMap.Where(e => e.Key.Arity == 2).Sum(e => e.Value);
            double correctionCoef = ubp / (1 - ubp) * bps / ups;
            operatorAndProbabilityMap.Select(e => e.Key).Where(op => op.Arity == 1).ToArray().
                ForEach(op => operatorAndProbabilityMap[op] *= correctionCoef);

            return new FormulaGenerationArguments
            {
                DimensionsCount = random.Next(dimensionCountBounds),
                MinimalDepth = random.Next(minimalDepthBounds),
                LeafProbability = random.Next(leafProbabilityBounds),
                ConstantProbability = random.Next(constantProbabilityBounds),
                OperatorAndProbabilityMap = operatorAndProbabilityMap,
                CreateConstant = () =>
                {
                    double c = Math.Round(random.Next(constantBounds), 2);
                    return Math.Abs(c - 0) < 0.01 ? 0.01 : c;
                }
            };
        }
Ejemplo n.º 3
0
 private static string GetOpSymbolName(Operator op)
 {
     return op.Name;
 }
Ejemplo n.º 4
0
 private static string GetOpNodeSymbolName(Operator op)
 {
     return GetOpSymbolName(op) + "Node";
 }
Ejemplo n.º 5
0
        private static SymbolsSet<Operator> CreateSymbols(IEnumerable<Operator> operators)
        {
            List<string> nonTerminalsNames = new List<string>
            {
                "V", "C", "InfGuard", "RegOp2Operands", "OpOrOp0NodeOperands", "OpOrVNodeOperands", "OpOrVNode", "OpNode"
            };

            // Op0Node, Op1Node, ...
            nonTerminalsNames.AddRange(GetOpArityNodeSymbolNames(operators));

            // SumNode, SinNode, ...
            nonTerminalsNames.AddRange(operators.Where(op => op.Arity > 0).Select(GetOpNodeSymbolName));

            IEnumerable<Operator> terminalGuards = new Operator[] {OperatorsLibrary.Atan, OperatorsLibrary.Tanh, OperatorsLibrary.Sum, OperatorsLibrary.Abs};
            IEnumerable<Symbol<Operator>> terminals = operators.Concat(terminalGuards).Distinct().Select(op => new Symbol<Operator>(op, GetOpSymbolName(op)));
            IEnumerable<Symbol<Operator>> nonTerminals = nonTerminalsNames.Select(n => new Symbol<Operator>(n));
            return new SymbolsSet<Operator> { terminals, nonTerminals };
        }