예제 #1
0
        public void sparse_features_medium()
        {
            // Cluster generator settings
            var maxRadius    = 100;
            var minRadius    = 10;
            var clusterCount = 10;

            // Data size
            var featureDim = 100;
            var obsCount   = 2000;

            var inputFeaturesTypes = new InputFeatureTypes[featureDim];

            for (var i = 0; i < featureDim; i++)
            {
                inputFeaturesTypes[i] = InputFeatureTypes.Ordinal;
            }

            var sparseOrdinalSet = new InstanceRepresentation(
                inputFeaturesTypes,
                sparse: true);

            var clusterGenerator  = new SyntheticDataGenerator(maxRadius, minRadius, obsCount, clusterCount, featureDim);
            var trueClusterLabels = new List <int>();

            using (var obsGetter = clusterGenerator.GenerateClusterObservations().GetEnumerator())
            {
                var isNextObservation = obsGetter.MoveNext();

                while (isNextObservation)
                {
                    var cluster = obsGetter.Current.Item1;
                    var obs     = obsGetter.Current.Item2;
                    trueClusterLabels.Add(cluster);
                    sparseOrdinalSet.AddInstance(obs);

                    isNextObservation = obsGetter.MoveNext();
                }
            }

            var clustering = new MiniBatchClustering(clusterCount, 100, 2000);

            clustering.Train(sparseOrdinalSet);
            var categories = clustering.Cluster(sparseOrdinalSet);

            var metricsGenerator = new MetricsGenerator();

            metricsGenerator.Add(Metrics.Purity);
            for (var i = 0; i < categories.Length; i++)
            {
                metricsGenerator.AddResult(categories[i], trueClusterLabels[i]);
                metricsGenerator.UpdateMetrics();
            }

            var purity = metricsGenerator.GetMetric(Metrics.Purity);

            Assert.True(purity + Epsilon - 0.6 > 0);
        }
        public void place_clusters()
        {
            var maxRadius    = 100;
            var minRadius    = 10;
            var clusterCount = 10;
            var featureDim   = 20;
            var obsCount     = 1000;

            var clusterGenerator = new SyntheticDataGenerator(maxRadius, minRadius, obsCount, clusterCount, featureDim);

            //using (var textWriter = new StreamWriter(path + csvFileName))
            using (var obsGetter = clusterGenerator.GenerateClusterObservations().GetEnumerator())
            {
                var isNextObservation = obsGetter.MoveNext();

                while (isNextObservation)
                {
                    var obs = obsGetter.Current.Item2;
                    //textWriter.WriteLine(string.Join(',', obs));
                    isNextObservation = obsGetter.MoveNext();
                }
            }
        }
예제 #3
0
 public void Load(SyntheticDataGenerator dataGenerator)
 {
     dataGenerator.LoadSequence(this, clipID.ToString(), datasetName);
 }