예제 #1
0
        private PartitionScore SplitOnAxis(ContinuousAxis axis, List <Episode> episodes, double[] totalWeights)
        {
            List <EvaluatedEpisode> line =
                episodes
                .AsParallel()
                .Select(episode => EvaluateEpisode(episode, axis))
                .OrderBy(x => x.Value)
                .ToList();

            int lastIndex = 0;

            double[] tacticWeightsLeft = new double[NumTactics];
            int      bestSplitPosition = -1;
            double   bestEntropy       = double.MaxValue;

            for (int i = 1; i < line.Count; ++i)
            {
                bool sameAsPrevious = i > 0 && line[i - 1].Value == line[i].Value;
                if (sameAsPrevious)
                {
                    // Cannot create a split part way through the same number
                    continue;
                }

                while (lastIndex < i)
                {
                    Episode episode = line[lastIndex++].Episode;
                    tacticWeightsLeft[(int)episode.Tactic] += episode.Weight;
                }
                double[] tacticWeightsRight = TacticEntropy.Subtract(totalWeights, tacticWeightsLeft);

                double entropy = TacticEntropy.Entropy(tacticWeightsLeft, tacticWeightsRight);

                if (entropy < bestEntropy)
                {
                    bestEntropy       = entropy;
                    bestSplitPosition = i;
                }
            }

            if (bestSplitPosition == -1)
            {
                // Unable to find split - all values must be the same
                return(null);
            }

            return(new PartitionScore {
                Partitioner = new ContinuousPartitioner(axis, line[bestSplitPosition].Value),
                LeftEpisodes = line.Take(bestSplitPosition).Select(x => x.Episode).ToList(),
                RightEpisodes = line.Skip(bestSplitPosition).Select(x => x.Episode).ToList(),
                Entropy = bestEntropy,
            });
        }
예제 #2
0
        private EvaluatedEpisode EvaluateEpisode(Episode episode, ContinuousAxis axis)
        {
            var    key = Tuple.Create(episode, axis);
            double value;

            if (!_evaluateCache.TryGetValue(key, out value))
            {
                value = ContinuousAxisEvaluator.Evaluate(axis, episode.World, episode.Hero);
                _evaluateCache[key] = value;
            }
            return(new EvaluatedEpisode {
                Episode = episode,
                Value = value,
            });
        }
예제 #3
0
        public WindowCharting3()
        {
            Background = new SolidColorBrush()
            {
                Color = ColorHelper.StringToColor("#FF1C1D21")
            };
            var uri = $"/wallpaper_mikael_gustafsson.png";

            InitializeComponent();
            Grid grid = new Grid()
            {
            };

            axisX.IsInterregional = false;

            ContinuousAxis axisY = new ContinuousAxis(AxisPosition.Left)
            {
                ValueFormat = "G4", SplitValueFormat = "G4", ShowGridLine = true, AxisPen = new Pen(Brushes.Green, 1), Unit = "万"
            };

            //axisY.Range = new Range() { Max = new Value<double>(5000000), Min = new Value<double>(40000) };
            chart.Offsets = new PaddingOffset(60, 20, 10, 20);

            canvasContainer.DrawingCanvas.AddChild(chart);
            canvasContainer.DrawingCanvas.DataSource = chart.DataSource;
            AxisInteractionCanvas interaction = new AxisInteractionCanvas();

            RectInteractionGroup container = new RectInteractionGroup(interaction, 1, 1, canvasContainer);

            //container.Background = Brushes.GreenYellow;
            chart.AddAsixY(axisY);
            chart.AddAsixX(axisX);

            chart.AddSeries(lineSeries);
            chart.AddSeries(lineSeries2);

            grid.Children.Add(container);
            canvasContainer.DrawingCanvas.Visuals.Add(CreateDrawingImage());

            BlurryUserControl b = new BlurryUserControl()
            {
                Background = new SolidColorBrush(ColorHelper.StringToColor("#BE323337")).OfStrength(0.2d)
            };

            b.BlurContainer = canvasContainer;
            b.Magnification = 0.25;
            b.BlurRadius    = 30;

            interaction.Tip.Layers.Children.Insert(0, b);
            interaction.Tip.TextContainer.Margin   = new Thickness(10);
            interaction.Tip.FontSize               = 11;
            interaction.Tip.Border.BorderThickness = new Thickness(1);
            interaction.Tip.Border.Padding         = new Thickness(0);
            interaction.Tip.Border.BorderBrush     = Brushes.Black;
            interaction.Tip.Foreground             = Brushes.White;
            //interaction.Tip.Border.BorderBrush = Brushes.White;
            //interaction.Tip.Border.BorderThickness = new Thickness(2);
            Content           = grid;
            IsVisibleChanged += WindowCharting3_IsVisibleChanged;
            SizeChanged      += WindowCharting3_SizeChanged;
            //StartDataFeed();
            //Timer timer = new Timer(200);
            //timer.Elapsed += Timer_Elapsed;
            //timer.Start();
        }