Пример #1
0
        //辅助参考http://blog.csdn.net/zmq570235977/article/details/50392283
        //参考原文通过Measure & Arrange实现UWP瀑布流布局http://www.cnblogs.com/ms-uap/p/4715195.html
        protected override Size MeasureOverride(Size availableSize)
        {
            // 记录每个流的长度。因为我们用选取最短的流来添加下一个元素。
            KeyValuePair <double, int>[] flowLens = new KeyValuePair <double, int> [ColumnNum];
            if (Orientation == Orientation.Vertical)
            {
                foreach (int idx in Enumerable.Range(0, ColumnNum))
                {
                    flowLens[idx] = new KeyValuePair <double, int>(0.0, idx);
                }

                // 我们就用2个纵向流来演示,获取每个流的宽度。
                double flowWidth = availableSize.Width / ColumnNum;

                // 为子控件提供沿着流方向上,无限大的空间
                Size elemMeasureSize = new Size(flowWidth, double.PositiveInfinity);

                foreach (UIElement elem in Children)
                {
                    // 让子控件计算它的大小。
                    elem.Measure(elemMeasureSize);
                    Size elemSize = elem.DesiredSize;

                    double elemLen = elemSize.Height;
                    var    pair    = flowLens[0];

                    // 子控件添加到最短的流上,并重新计算最短流。
                    // 因为我们为了求得流的长度,必须在计算大小这一步时就应用一次布局。但实际的布局还是会在Arrange步骤中完成。
                    flowLens[0] = new KeyValuePair <double, int>(pair.Key + elemLen, pair.Value);
                    flowLens    = flowLens.OrderBy(p => p.Key).ToArray();
                }
                return(new Size(availableSize.Width, flowLens.Last().Key));//返回值是该元素本身实际需要的大小。
            }
            else
            {
                foreach (int idx in Enumerable.Range(0, ColumnNum))
                {
                    flowLens[idx] = new KeyValuePair <double, int>(0.0, idx);
                }

                double flowHeigh = 50;

                Size elemMeasureSize = new Size(double.PositiveInfinity, flowHeigh);

                foreach (UIElement elem in Children)
                {
                    elem.Measure(elemMeasureSize);
                    Size elemSize = elem.DesiredSize;

                    double elemLen = elemSize.Width;
                    var    pair    = flowLens[0];

                    flowLens[0] = new KeyValuePair <double, int>(pair.Key + elemLen, pair.Value);
                    flowLens    = flowLens.OrderBy(p => p.Key).ToArray();
                }
                return(new Size(flowLens.Last().Key, 50));//返回值是该元素本身实际需要的大小。
            }
        }
Пример #2
0
        /// <summary>
        /// Generates card table.
        /// </summary>
        void Generate()
        {
            if (cards != null)
            {
                cards = new Card[0];
            }
            int cardCount = Mathf.RoundToInt(gridSize.x * gridSize.y);

            cards = new Card[cardCount];
            KeyValuePair <int, bool>[] mode = new KeyValuePair <int, bool> [cardCount];
            for (int i = 0; i < mode.Length; i++)
            {
                mode [i] = new KeyValuePair <int, bool> (Mathf.FloorToInt(i / 2), i % 2 == 0);
            }
            mode = mode.OrderBy(x => Random.Range(0f, 1f)).ToArray();

            int     k          = 0;
            Vector2 gridCenter = new Vector2(gridSize.x / 2f, gridSize.y / 2f);

            for (int i = 0; i < gridSize.x; i++)
            {
                for (int j = 0; j < gridSize.y; j++)
                {
                    Card card = Instantiate <Card> (cardPrefab, new Vector3((gridCenter.x - i - .5f) * cardSpacing.x, (gridCenter.y - j - .5f) * cardSpacing.y), Quaternion.identity);
                    card.SetDisplay(Configuration.CardsData [mode [k].Key], mode [k].Value);
                    card.Spawn(k * 0.1f);
                    cards [k] = card;
                    k++;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 当在派生类中重写时,请测量子元素在布局中所需的大小,然后确定 <see cref="T:System.Windows.FrameworkElement" /> 派生类的大小。
        /// 更新当前元素与其子元素的布局,以下处理都属于 测量 处理,并非实际布局
        /// </summary>
        /// <param name="availableSize">此元素可以赋给子元素的可用大小。可以指定无穷大值,这表示元素的大小将调整为内容的可用大小。</param>
        /// <returns>此元素在布局过程中所需的大小,这是由此元素根据对其子元素大小的计算而确定的。</returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            KeyValuePair <double, int>[] flowLens = new KeyValuePair <double, int> [ColumnCount];
            foreach (int idx in Enumerable.Range(0, ColumnCount))
            {
                flowLens[idx] = new KeyValuePair <double, int>(0.0, idx);
            }

            // 我们就用2个纵向流来演示,获取每个流的宽度。
            double flowWidth = availableSize.Width / ColumnCount;

            // 为子控件提供沿着流方向上,无限大的空间
            Size elemMeasureSize = new Size(flowWidth, double.PositiveInfinity);

            foreach (UIElement elem in Children)
            {
                // 让子控件计算它的大小。
                elem.Measure(elemMeasureSize);
                Size elemSize = elem.DesiredSize;

                double elemLen = elemSize.Height;
                var    pair    = flowLens[0];

                // 子控件添加到最短的流上,并重新计算最短流。
                // 因为我们为了求得流的长度,必须在计算大小这一步时就应用一次布局。但实际的布局还是会在Arrange步骤中完成。
                flowLens[0] = new KeyValuePair <double, int>(pair.Key + elemLen, pair.Value);
                flowLens    = flowLens.OrderBy(p => p.Key).ToArray();
            }

            return(new Size(availableSize.Width, flowLens.Last().Key));
        }
Пример #4
0
        private string get_DiskUsageInfo()
        {
            StringBuilder sb = new StringBuilder();

            KeyValuePair <string, string>[] dirs = new KeyValuePair <string, string>[]
            {
                new KeyValuePair <string, string>("Thumbnails", Program.thumb_save_dir),
                new KeyValuePair <string, string>("Full files", Program.file_save_dir),
                new KeyValuePair <string, string>("API Cached files", Program.api_cache_dir),
                new KeyValuePair <string, string>("Post files", Program.post_files_dir),
                // new KeyValuePair<string, string>("Temporary files", Program.temp_files_dir),
            };

            foreach (KeyValuePair <string, string> a in dirs.OrderBy(x => x.Key))
            {
                DirectoryStatsEntry ds = FileSystemStats.GetDirStats(a.Value);

                if (ds != null)
                {
                    sb.Append("<tr>");
                    sb.AppendFormat("<td>{0}</td>", ds.FileCount);
                    sb.AppendFormat("<td>{0}</td>", a.Key);
                    sb.AppendFormat("<td>{0}</td>", Program.format_size_string(ds.TotalSize));
                    sb.AppendFormat("<td>{0}</td>", Program.format_size_string(ds.AverageFileSize));
                    sb.AppendFormat("<td>{0}</td>", Program.format_size_string(ds.LargestFile));
                    sb.AppendFormat("<td>{0}</td>", Program.format_size_string(ds.SmallestFile));
                    sb.Append("</tr>");
                }
            }

            return(sb.ToString());
        }
Пример #5
0
        public IInterpolator1D[] Regress(IAssetFxModel model)
        {
            if (_regressors != null)
            {
                return(_regressors);
            }

            var o = new IInterpolator1D[_dateIndexes.Length];

            var nPaths         = _pathwiseValues.First().Length;
            var finalSchedules = _portfolio.Select(x => x.ExpectedFlowsByPath(model)).ToArray();

            ParallelUtils.Instance.For(0, _dateIndexes.Length, 1, d =>
            {
                var exposureDate      = _regressionDates[d];
                var sortedFinalValues = new KeyValuePair <double, double> [nPaths];

                for (var p = 0; p < nPaths; p++)
                {
                    var finalValue = 0.0;
                    foreach (var schedule in finalSchedules)
                    {
                        foreach (var flow in schedule[p].Flows)
                        {
                            if (flow.SettleDate > exposureDate)
                            {
                                finalValue += flow.Pv;
                            }
                        }
                    }
                    sortedFinalValues[p] = new KeyValuePair <double, double>(_pathwiseValues[d][p], finalValue);
                }

                sortedFinalValues = sortedFinalValues.OrderBy(q => q.Key).ToArray();

                if (_requireContinuity)
                {
                    o[d] = SegmentedLinearRegression.Regress(sortedFinalValues.Select(x => x.Key).ToArray(), sortedFinalValues.Select(y => y.Value).ToArray(), 5);
                }
                else
                {
                    o[d] = SegmentedLinearRegression.RegressNotContinuous(sortedFinalValues.Select(x => x.Key).ToArray(), sortedFinalValues.Select(y => y.Value).ToArray(), 5);
                }

                if (DebugMode)
                {
                    DumpDataToDisk(sortedFinalValues, o[d], $@"C:\temp\regData{d}.csv");
                }
            }).Wait();
            _regressors = o;
            return(o);
        }
Пример #6
0
        /**
         * Returns the top W coordinates by order.
         *
         * @param co			Implementation of {@link CoordinateOrder}
         * @param coordinates	A 2D array, where each element
         *                      is a coordinate
         * @param w				(int) Number of top coordinates to return
         * @return
         */
        public int[][] TopWCoordinates(ICoordinateOrder co, int[][] coordinates, int numberOfTopCoordinates)
        {
            KeyValuePair <double, int>[] pairs = new KeyValuePair <double, int> [coordinates.Length];
            for (int i = 0; i < coordinates.Length; i++)
            {
                pairs[i] = new KeyValuePair <double, int>(co.OrderForCoordinate(coordinates[i]), i);
            }

            pairs = pairs.OrderBy(kvp => kvp.Key).ThenBy(kvp => kvp.Value).ToArray();
            //Array.Sort(pairs);

            int[][] topCoordinates = new int[numberOfTopCoordinates][];
            for (int i = 0, wIdx = pairs.Length - numberOfTopCoordinates; i < numberOfTopCoordinates; i++, wIdx++)
            {
                int index = pairs[wIdx].Value;
                topCoordinates[i] = coordinates[index];
            }
            return(topCoordinates);
        }
Пример #7
0
        public void TestCopyToCopiesAllValues()
        {
            var dict = new Dictionary <int, string>()
            {
                { 1, "One" },
                { 2, "Two" },
                { 3, "Three" }
            };

            IDictionary <int, string> toTest = new ReadOnlyDictionary <int, string>(dict);

            Assert.IsTrue(toTest.IsReadOnly);

            var copy = new KeyValuePair <int, string> [3];

            toTest.CopyTo(copy, 0);

            Assert.IsTrue(copy.OrderBy(kv => kv.Key).SequenceEqual(dict.OrderBy(kv => kv.Key)));
        }
Пример #8
0
        public void ICollectionCopyTo(int n)
        {
            using (var lua = new Lua()) {
                ICollection <KeyValuePair <object, object> > table = lua.CreateTable();
                var table2 = (LuaTable)table;
                for (var i = 0; i < n; ++i)
                {
                    table2[i] = 0;
                }
                var array = new KeyValuePair <object, object> [n];

                table.CopyTo(array, 0);

                var expected = new List <KeyValuePair <object, object> >();
                for (var i = 0; i < n; ++i)
                {
                    expected.Add(new KeyValuePair <object, object>((long)i, 0L));
                }
                Assert.Equal(expected.OrderBy(kvp => kvp.Key), array.OrderBy(kvp => kvp.Key));
            }
        }
Пример #9
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            // 同样记录流的长度。
            KeyValuePair <double, int>[] flowLens = new KeyValuePair <double, int> [ColumnNum];

            double flowWidth = finalSize.Width / ColumnNum;

            // 要用到流的横坐标了,我们用一个数组来记录(其实最初是想多加些花样,用数组来方便索引横向偏移。不过本例中就只进行简单的乘法了)
            double[] xs = new double[ColumnNum];

            foreach (int idx in Enumerable.Range(0, ColumnNum))
            {
                flowLens[idx] = new KeyValuePair <double, int>(0.0, idx);
                xs[idx]       = idx * flowWidth;
            }

            foreach (UIElement elem in Children)
            {
                // 直接获取子控件大小。
                Size   elemSize = elem.DesiredSize;
                double elemLen  = elemSize.Height;

                var    pair          = flowLens[0];
                double chosenFlowLen = pair.Key;
                int    chosenFlowIdx = pair.Value;

                // 此时,我们需要设定新添加的空间的位置了,其实比measure就多了一个Point信息。接在流中上一个元素的后面。
                Point pt = new Point(xs[chosenFlowIdx], chosenFlowLen);

                // 调用Arrange进行子控件布局。并让子控件利用上整个流的宽度。
                elem.Arrange(new Rect(pt, new Size(flowWidth, elemSize.Height)));

                // 重新计算最短流。
                flowLens[0] = new KeyValuePair <double, int>(chosenFlowLen + elemLen, chosenFlowIdx);
                flowLens    = flowLens.OrderBy(p => p.Key).ToArray();
            }

            // 直接返回该方法的参数。
            return(finalSize);
        }
Пример #10
0
        public static int[] GetNotOverlapRandNumberArray(int min_range, int max_range, int array_num)
        {
            int[] value = new int[array_num];

            KeyValuePair <int, int>[] temp_rand_value = new KeyValuePair <int, int> [(max_range - min_range) + 1];

            int adjusted_max_range = max_range + 1;

            for (int i = 0; i < temp_rand_value.Length; ++i)
            {
                temp_rand_value[i] = new KeyValuePair <int, int>(i, Rand_.Next(min_range, adjusted_max_range));
            }

            temp_rand_value = temp_rand_value.OrderBy(kv => kv.Value).ToArray();

            for (int i = 0; i < array_num; ++i)
            {
                value[i] = temp_rand_value[i].Key;
            }

            return(value);
        }
        /// <summary>
        ///   Initializes the mmi groups with starting elements that have the highest unconditional entropy
        /// </summary>
        protected void InitializeGroups()
        {
            // Clear all groups
            for (int i = 0; i < minimalMutualInfoGroups.Length; i++)
            {
                minimalMutualInfoGroups[i].Clear();
            }

            // Compute unconditional entropy
            KeyValuePair <int, double>[] uncodEntropy = new KeyValuePair <int, double> [NeuralNetworkEnsembleDimensionality];
            for (int i = 0; i < NeuralNetworkEnsembleDimensionality; i++)
            {
                double uncodEntrpy = 0.0;
                List <MinimalMutualInfoPair> list = mmiPairs.FindAll(pair => pair.IndexFirst == i || pair.IndexSecond == i);
                foreach (MinimalMutualInfoPair pair in list)
                {
                    uncodEntrpy += pair.MutualInformation;
                }

                uncodEntropy[i] = new KeyValuePair <int, double>(i, uncodEntrpy);
            }

            List <KeyValuePair <int, double> > query = new List <KeyValuePair <int, double> >(uncodEntropy.OrderBy(kv => kv.Value));

            // Assign elements that have highest unconditional entropy
            for (int i = 0; i < minimalMutualInfoGroups.Length; i++)
            {
                minimalMutualInfoGroups[i].AddToGroup(query[i].Key);
                indexList.Remove(query[i].Key);
            }
        }
Пример #12
0
 protected void Start_Click(object sender, EventArgs e)
 {
     KeyValuePair<int, string>[] stubarray = new KeyValuePair<int, string>[4];
     for (int i = 0; i < stubarray.Length; i++)
     {
         stubarray[i] = colors[i + 1];
     }
     Label1.Text = "Turn: 0";
     Button1.CssClass = colors[0].Value;
     Button2.CssClass = colors[0].Value;
     Button3.CssClass = colors[0].Value;
     Button4.CssClass = colors[0].Value;
     Button1.Visible = true;
     Button2.Visible = true;
     Button3.Visible = true;
     Button4.Visible = true;
     Random rnd = new Random(System.DateTime.Now.Millisecond);
     KeyValuePair<int, string>[] MyRandomArray = stubarray.OrderBy(x => rnd.Next()).ToArray();
     Enigma0.CssClass = MyRandomArray[0].Value;
     Label6.Text = MyRandomArray[0].Key.ToString();
     Enigma1.CssClass = MyRandomArray[1].Value;
     Label7.Text = MyRandomArray[1].Key.ToString();
     Enigma2.CssClass = MyRandomArray[2].Value;
     Label8.Text = MyRandomArray[2].Key.ToString();
     Enigma3.CssClass = MyRandomArray[3].Value;
     Label9.Text = MyRandomArray[3].Key.ToString();
     GuessButton.Enabled = true;
     Enigma0.Visible = false;
     Enigma1.Visible = false;
     Enigma2.Visible = false;
     Enigma3.Visible = false;
     StartButton.Enabled = false;
 }
        protected override Size MeasureOverride(Size availableSize)
        {
            //横向瀑布流

            groupcount = (int)availableSize.Width / 256 >= 3 ? (int)availableSize.Width / 256 : 3;
            //三组流长度记录
            KeyValuePair<double, int>[] flowLength = new KeyValuePair<double, int>[groupcount];
            foreach (int index in Enumerable.Range(0, groupcount))
            {
                flowLength[index] = new KeyValuePair<double, int>(0.0, index);
            }

            //每组长度为总长度1/3
            double flowWidth = availableSize.Width / groupcount;

            //子控件宽为组宽,长无限制
            Size childMeasureSize = new Size(flowWidth, double.PositiveInfinity);

            //子控件遍历计算长度
            foreach (UIElement childElement in Children)
            {
                childElement.Measure(childMeasureSize);
                Size childSize = childElement.DesiredSize;
                //得到子控件长
                double childLength = childSize.Height;
                //暂存最短流长度
                var tempPair = flowLength[0];
                //最短流长度重新计算
                flowLength[0] = new KeyValuePair<double, int>(tempPair.Key + childLength, tempPair.Value);
                //重新按流长度排列键值对        这里以Key 的值作为排列依据,flowWidth[0]为Key最小的键值对,P可替换为任意字母
                flowLength = flowLength.OrderBy(P => P.Key).ToArray();
            }
            //返回 长:最长流的长;宽:传入的宽
            return new Size(availableSize.Width, flowLength.Last().Key);
        }
Пример #14
0
        public void FullOptionTest()
        {
            var args = new string[]
            {
                "Help=true",
                "FileName=name1",
                "IntValue=1",
                "OptionalIntValue=2",
                "BoolValue=true",
                "OptionalBoolValue=false",
                "Data1:Name=d1_name",
                "Data1:Value=1",
                "Data1:Type=Private",
                "Data2:Name=d2_name",
                "Data2:Value=2",
                "Data2:Type=Public",
                "Data2:Key=933B757C-CF76-4B0D-8912-BAAD5C0B02A8",
                "StartNames:0=Start1",
                "StartNames:1=Start2",
                "StartNames:2=Start3",
                "NotificationType=Team",
                "Properties:Value1=instance1",
                "Properties:Value2=instance2",
                "Properties:Value3=instance3",
            };

            IOption option = Option.Build(args);

            option.Should().NotBeNull();
            option.Help.Should().BeTrue();
            option.FileName.Should().Be("name1");
            option.StartNames.Should().NotBeNull();
            option.StartNames?.Count.Should().Be(3);
            option.StartNames
            .Zip(new string[] { "Start1", "Start2", "Start3" }, (o, i) => new { o, i })
            .All(x => x.o == x.i)
            .Should().BeTrue();

            option.Data1.Should().NotBeNull();
            option.Data1?.Name.Should().Be("d1_name");
            option.Data1?.Value.Should().Be(1);
            option.Data1?.Type.Should().Be(SectionType.Private);
            option.Data1?.Key.Should().BeNull();

            option.Data2.Should().NotBeNull();
            option.Data2?.Name.Should().Be("d2_name");
            option.Data2?.Value.Should().Be(2);
            option.Data2?.Type.Should().Be(SectionType.Public);
            option.Data2?.Key.Should().Be(Guid.Parse("933B757C-CF76-4B0D-8912-BAAD5C0B02A8"));

            option.NotificationType.Should().Be(NotificationType.Team);

            var expectedProperties = new KeyValuePair <string, string>[]
            {
                new KeyValuePair <string, string>("Value1", "instance1"),
                new KeyValuePair <string, string>("Value2", "instance2"),
                new KeyValuePair <string, string>("Value3", "instance3"),
            };

            option.Properties.OrderBy(x => x.Key)
            .Zip(expectedProperties.OrderBy(x => x.Key), (o, i) => (o, i))
            .All(x => x.o.Key == x.i.Key && x.o.Value == x.i.Value)
            .Should().BeTrue();
        }
Пример #15
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            // 同样记录流的长度。
            KeyValuePair <double, int>[] flowLens = new KeyValuePair <double, int> [ColumnNum];

            if (Orientation == Orientation.Vertical)
            {
                double flowWidth = finalSize.Width / ColumnNum;

                // 要用到流的横坐标了,我们用一个数组来记录(其实最初是想多加些花样,用数组来方便索引横向偏移。不过本例中就只进行简单的乘法了)
                double[] xs = new double[ColumnNum];

                foreach (int idx in Enumerable.Range(0, ColumnNum))
                {
                    flowLens[idx] = new KeyValuePair <double, int>(0.0, idx);
                    xs[idx]       = idx * flowWidth;
                }

                foreach (UIElement elem in Children)
                {
                    // 直接获取子控件大小。
                    Size   elemSize = elem.DesiredSize;
                    double elemLen  = elemSize.Height;

                    var    pair          = flowLens[0];
                    double chosenFlowLen = pair.Key;
                    int    chosenFlowIdx = pair.Value;

                    // 此时,我们需要设定新添加的空间的位置了,其实比measure就多了一个Point信息。接在流中上一个元素的后面。
                    Point pt = new Point(xs[chosenFlowIdx], chosenFlowLen);

                    // 调用Arrange进行子控件布局。并让子控件利用上整个流的宽度。
                    elem.Arrange(new Rect(pt, new Size(flowWidth, elemSize.Height)));

                    // 重新计算最短流。
                    flowLens[0] = new KeyValuePair <double, int>(chosenFlowLen + elemLen, chosenFlowIdx);
                    flowLens    = flowLens.OrderBy(p => p.Key).ToArray();
                }
            }
            else
            {
                List <Double> offsetX  = new List <Double>();
                List <Double> offsetY  = new List <Double>();
                int           minIndex = 0;

                for (int i = 0; i < ColumnNum; i++)
                {
                    offsetX.Add(0);
                    offsetY.Add(getoffsex(i));
                }

                foreach (var item in this.Children)
                {
                    double min = offsetX.Min();
                    minIndex = offsetX.IndexOf(min);

                    item.Arrange(new Rect(offsetX[minIndex], offsetY[minIndex], item.DesiredSize.Width, item.DesiredSize.Height));
                    offsetX[minIndex] += (item.DesiredSize.Width + 3);
                }
            }
            #region 备份
            //else
            //{
            //    //这里是控制横向显示有多少的,逻辑有问题
            //    double flowWidth = finalSize.Width / 10;

            //    // 要用到流的横坐标了,我们用一个数组来记录(其实最初是想多加些花样,用数组来方便索引横向偏移。不过本例中就只进行简单的乘法了)
            //    double[] xs = new double[ColumnNum];

            //    foreach (int idx in Enumerable.Range(0, ColumnNum))
            //    {
            //        flowLens[idx] = new KeyValuePair<double, int>(0.0, idx);
            //        xs[idx] = idx * flowWidth;
            //    }

            //    foreach (UIElement elem in Children)
            //    {
            //        // 直接获取子控件大小。
            //        Size elemSize = elem.DesiredSize;
            //        double elemLen = elemSize.Width;

            //        var pair = flowLens[0];
            //        double chosenFlowLen = pair.Key;
            //        int chosenFlowIdx = pair.Value;

            //        // 此时,我们需要设定新添加的空间的位置了,其实比measure就多了一个Point信息。接在流中上一个元素的后面。
            //        Point pt = new Point(xs[chosenFlowIdx], chosenFlowLen);

            //        // 调用Arrange进行子控件布局。并让子控件利用上整个流的宽度。
            //        elem.Arrange(new Rect(pt, new Size(elemSize.Width, elemSize.Height)));

            //        // 重新计算最短流。
            //        flowLens[0] = new KeyValuePair<double, int>(chosenFlowLen + elemLen, chosenFlowIdx);
            //        flowLens = flowLens.OrderBy(p => p.Key).ToArray();
            //    }

            //}

            #endregion


            // 直接返回该方法的参数。
            return(finalSize);
        }
        protected override Size ArrangeOverride(Size finalSize)
        {
            KeyValuePair<double, int>[] flowLength = new KeyValuePair<double, int>[groupcount];
            double flowWidth = finalSize.Width / groupcount;
            double[] xWidth = new double[groupcount];
            foreach (int index in Enumerable.Range(0, groupcount))
            {
                flowLength[index] = new KeyValuePair<double, int>(0.0, index);
                xWidth[index] = index * flowWidth;
            }

            foreach (UIElement childElem in Children)
            {
                // 获取子控件期望大小
                Size elemSize = childElem.DesiredSize;
                double elemLength = elemSize.Height;

                //得到最短流长度
                var pair = flowLength[0];
                double chosenFlowHeight = pair.Key;
                int chosenFlowIdx = pair.Value;

                // 设置即将放置的控件坐标
                Point pt = new Point(xWidth[chosenFlowIdx], chosenFlowHeight);

                // 调用Arrange进行子控件布局。并让子控件利用上整个流的长度。
                childElem.Arrange(new Rect(pt, new Size(flowWidth, elemSize.Height)));

                // 重新计算最短流。
                flowLength[0] = new KeyValuePair<double, int>(chosenFlowHeight + elemLength, chosenFlowIdx);
                flowLength = flowLength.OrderBy(p => p.Key).ToArray();
            }
            return finalSize;
        }
        /// <summary>
        ///   Initializes the mmi groups with starting elements that have the highest unconditional entropy
        /// </summary>
        protected void InitializeGroups()
        {
            // Clear all groups
            for (int i = 0; i < minimalMutualInfoGroups.Length; i++)
            {
                minimalMutualInfoGroups[i].Clear();
            }

            // Compute unconditional entropy
            KeyValuePair<int, double>[] uncodEntropy = new KeyValuePair<int, double>[NeuralNetworkEnsembleDimensionality];
            for (int i = 0; i < NeuralNetworkEnsembleDimensionality; i++)
            {
                double uncodEntrpy = 0.0;
                List<MinimalMutualInfoPair> list = mmiPairs.FindAll(pair => pair.IndexFirst == i || pair.IndexSecond == i);
                foreach (MinimalMutualInfoPair pair in list)
                {
                    uncodEntrpy += pair.MutualInformation;
                }

                uncodEntropy[i] = new KeyValuePair<int, double>(i, uncodEntrpy);
            }

            List<KeyValuePair<int, double>> query = new List<KeyValuePair<int, double>>(uncodEntropy.OrderBy(kv => kv.Value));

            // Assign elements that have highest unconditional entropy
            for (int i = 0; i < minimalMutualInfoGroups.Length; i++)
            {
                minimalMutualInfoGroups[i].AddToGroup(query[i].Key);
                indexList.Remove(query[i].Key);
            }
        }
Пример #18
0
        private string get_DiskUsageInfo()
        {
            StringBuilder sb = new StringBuilder();

            KeyValuePair<string, string>[] dirs = new KeyValuePair<string, string>[]
            {
                new KeyValuePair<string, string>("Thumbnails", Program.thumb_save_dir),
                new KeyValuePair<string, string>("Full files", Program.file_save_dir),
                new KeyValuePair<string, string>("API Cached files", Program.api_cache_dir ),
                new KeyValuePair<string, string>("Post files", Program.post_files_dir),
               // new KeyValuePair<string, string>("Temporary files", Program.temp_files_dir),
            };

            foreach (KeyValuePair<string, string> a in dirs.OrderBy(x => x.Key))
            {
                DirectoryStatsEntry ds = FileSystemStats.GetDirStats(a.Value);

                if (ds != null)
                {
                    sb.Append("<tr>");
                    sb.AppendFormat("<td>{0}</td>", ds.FileCount);
                    sb.AppendFormat("<td>{0}</td>", a.Key);
                    sb.AppendFormat("<td>{0}</td>", Program.format_size_string(ds.TotalSize));
                    sb.AppendFormat("<td>{0}</td>", Program.format_size_string(ds.AverageFileSize));
                    sb.AppendFormat("<td>{0}</td>", Program.format_size_string(ds.LargestFile));
                    sb.AppendFormat("<td>{0}</td>", Program.format_size_string(ds.SmallestFile));
                    sb.Append("</tr>");
                }
            }

            return sb.ToString();
        }