Example #1
0
        private KNNClassifier InitClassifier(Parameters p)
        {
            KNNClassifier.Builder builder = KNNClassifier.GetBuilder();
            KNNClassifier         knn     = builder.Build();

            p.Apply(knn);

            return(knn);
        }
Example #2
0
        public void TestBuilder()
        {
            KNNClassifier.Builder builder = KNNClassifier.GetBuilder();

            builder.K(42)
            .Exact(true)
            .DistanceNorm(12.5)
            .DistanceMethod(DistanceMethod.PctInputOverlap)
            .DistanceThreshold(2.3)
            .DoBinarization(true)
            .BinarizationThreshold(3.0)
            .UseSparseMemory(true)
            .SparseThreshold(349.0)
            .RelativeThreshold(true)
            .NumWinners(100)
            .NumSVDSamples(4)
            .NumSVDDims((int)KnnMode.ADAPTIVE)
            .FractionOfMax(0.84)
            .MaxStoredPatterns(30)
            .ReplaceDuplicates(true)
            .CellsPerCol(32);

            KNNClassifier knn = builder.Build();

            Assert.AreEqual(42, knn.GetK());
            Assert.IsTrue(knn.IsExact());
            Assert.AreEqual(12.5, knn.GetDistanceNorm(), 0.0);
            Assert.AreEqual(DistanceMethod.PctInputOverlap, knn.GetDistanceMethod());
            Assert.AreEqual(2.3, knn.GetDistanceThreshold(), 0.0);
            Assert.IsTrue(knn.IsDoBinarization());
            Assert.AreEqual(3.0, knn.GetBinarizationThreshold(), 0.0);
            Assert.IsTrue(knn.IsRelativeThreshold());
            Assert.IsTrue(knn.IsUseSparseMemory());
            Assert.AreEqual(349.0, knn.GetSparseThreshold(), 0.0);
            Assert.AreEqual(100, knn.GetNumWinners());
            Assert.AreEqual(4, knn.GetNumSVDSamples());
            Assert.AreEqual((int)KnnMode.ADAPTIVE, knn.GetNumSVDDims());
            Assert.AreEqual(0.84, knn.GetFractionOfMax().GetValueOrDefault(), 0.0);
            Assert.AreEqual(30, knn.GetMaxStoredPatterns());
            Assert.IsTrue(knn.IsReplaceDuplicates());
            Assert.AreEqual(32, knn.GetCellsPerCol());
        }