示例#1
0
文件: ListsTest.cs 项目: vego1mar/PI
        public void Concat()
        {
            // given
            IList <double> set1 = new List <double>()
            {
                0
            };
            IList <double> set2 = new List <double>()
            {
                1, 2
            };
            IList <double> set3 = new List <double>()
            {
                3, 4, 5
            };
            IList <double> target   = new List <double>();
            IList <double> expected = new List <double>()
            {
                0, 3, 4, 5, 1, 2
            };

            IList <IList <double> > set4 = new List <IList <double> >()
            {
                set1, set2, set3
            };
            int targetLength4 = 3;
            int targetCounts4 = 10;
            IList <IList <double> > target4 = Lists.Get <double>(targetLength4, targetCounts4);

            // when
            Lists.Concat(target, set1);
            Lists.Concat(target, set3);
            Lists.Concat(target, set2);

            Lists.Concat(target4, set4);

            // then
            Assertions.SameValues(target, expected);

            Assert.IsTrue(target4.Count == targetLength4 + set4.Count);
            for (int i = 0; i < targetLength4; i++)
            {
                Assert.IsTrue(target4[i].Count == targetCounts4);
            }
            Assert.IsTrue(target4[targetLength4].Count == set1.Count);
            Assert.IsTrue(target4[targetLength4 + 1].Count == set2.Count);
            Assert.IsTrue(target4[targetLength4 + 2].Count == set3.Count);
            for (int i = 0; i < set4.Count; i++)
            {
                Assertions.SameValues(set4[i], target4[i + targetLength4]);
            }
        }
示例#2
0
文件: Smoothers.cs 项目: vego1mar/PI
        public static IList <double> NearestNeighbors(IList <IList <double> > orderedSet, int kNN = 8)
        {
            if (orderedSet == null || orderedSet.Count == 0 || kNN <= 0)
            {
                return(new List <double>().AsReadOnly());
            }

            IList <IList <double> > operative = new List <IList <double> >();

            Lists.Concat(operative, Lists.Get(kNN, 1, 0.0));
            Lists.Concat(operative, orderedSet);
            IList <double> neighbors = new List <double>();
            IList <double> currentSet;

            for (int i = kNN; i < orderedSet.Count + kNN; i++)
            {
                currentSet = Lists.GetCopyConcatenated(operative, i - kNN, i + 1);
                neighbors.Add(Averages.Median(currentSet).Value);
            }

            return(neighbors);
        }