Example #1
0
        HsRangeCa CalculateHsRangeCa(string bucketCounts, int [] samplesCount, bool isVerbose)
        {
            ClusterTree rt         = new ClusterTree();
            Props       parameters = GetParams(bucketCounts);

            parameters.Set("IsCreatingClusterTree", "true");
            HsRangeCa ca = new HsRangeCa(parameters);

            CaMcGen gen = new CaMcGen
            {
                Clusterizer = ca,
                IsVerbose   = isVerbose,
                // IsVerboseSamples = true,
                RngSeed      = 0,
                SamplesCount = samplesCount
            };

            rt.Root = gen.Generate();
            string fileName = Path.Combine(_outDir, bucketCounts.Replace(' ', 'x')) + ".dat";

            rt.Write(fileName);

            parameters.Set("ClusterTreeFile", fileName);
            parameters.Set("IsCreatingClusterTree", "false");
            HsRangeCa ca1 = new HsRangeCa(parameters);

            return(ca1);
        }
        public void Test_ReadWrite()
        {
            ClusterTree rt1  = new ClusterTree();
            RangeNode   root = new RangeNode(5);

            rt1.Root = root;
            for (int i = 0; i < 5; ++i)
            {
                root.Children[i] = new RangeNode(0)
                {
                    UpperLimit = 0.1f * i
                };
            }
            rt1.Version.UserDescription = "Bla bla";

            string fileName = Path.Combine(_outDir, "ClusterTree.dat");

            rt1.Write(fileName);
            ClusterTree rt2 = ClusterTree.Read(fileName);

            Assert.AreEqual(rt1.Version, rt2.Version);
            Assert.IsTrue(CompareTrees <int, int> .Compare(rt1, rt1.Root, rt2, rt2.Root,
                                                           (t1, n1, t2, n2) =>
            {
                return(((RangeNode)n1).UpperLimit == ((RangeNode)n2).UpperLimit);
            }));
        }
Example #3
0
        HsSdKMeansAdaptiveCa CalculateCa(Props parameters, int[] samplesCount, int rngSeed)
        {
            ClusterTree rt = new ClusterTree();

            parameters.Set("IsCreatingClusterTree", "true");
            HsSdKMeansAdaptiveCa ca = new HsSdKMeansAdaptiveCa(parameters);

            CaMcGen gen = new CaMcGen
            {
                Clusterizer = ca,
                IsVerbose   = false,
                // IsVerboseSamples = true,
                RngSeed      = rngSeed,
                SamplesCount = samplesCount
            };

            rt.Root = gen.Generate();
            string fileName = Path.Combine(_outDir, "ca-hssd-km.dat");

            rt.Write(fileName);

            parameters.Set("ClusterTreeFile", fileName);
            parameters.Set("IsCreatingClusterTree", "false");
            HsSdKMeansAdaptiveCa ca1 = new HsSdKMeansAdaptiveCa(parameters);

            return(ca1);
        }
Example #4
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }
            if (_cmdLine.DebuggerLaunch)
            {
                Debugger.Launch();
            }
            Props caProps = XmlSerializerExt.Deserialize <Props>(_cmdLine.ChanceAbstractionFile);

            caProps.Set("IsCreatingClusterTree", "true");

            IChanceAbstraction ca = ChanceAbstractionHelper.CreateFromProps(caProps);

            Console.WriteLine("CA: {0}", ca.Name);

            List <int> samplesCount = new List <int>();

            foreach (string sc in  _cmdLine.SamplesCount.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                samplesCount.Add(int.Parse(sc));
            }

            int rngSeed = _cmdLine.RngSeed == 0 ? (int)DateTime.Now.Ticks : _cmdLine.RngSeed;

            Console.WriteLine("RNG seed: {0}", rngSeed);

            CaMcGen gen = new CaMcGen
            {
                Clusterizer = (IClusterizer)ca,
                IsVerbose   = true,
                // IsVerboseSamples = true,
                RngSeed      = rngSeed,
                SamplesCount = samplesCount.ToArray()
            };

            ClusterTree rt = new ClusterTree();

            rt.Root = gen.Generate();
            string dir      = Path.GetDirectoryName(_cmdLine.ChanceAbstractionFile);
            string file     = Path.GetFileNameWithoutExtension(_cmdLine.ChanceAbstractionFile) + ".dat";
            string fileName = Path.Combine(dir, file);

            Console.WriteLine("Writing range tree to {0}", fileName);
            rt.Write(fileName);

            return(0);
        }