Пример #1
0
        //Regenerate feature id and shrink features with lower frequency
        public void Shrink(EncoderTagger[] xList, int freq)
        {
            var old2new = new CRFLite.Utils.BTreeDictionary <long, long>();

            featureLexicalDict.Shrink(freq);
            maxid_ = featureLexicalDict.RegenerateFeatureId(old2new, y_.Count);
            var feature_count = xList.Length;

            //Update feature ids
            Parallel.For(0, feature_count, parallelOption, i =>
            {
                for (var j = 0; j < xList[i].feature_cache_.Count; j++)
                {
                    var newfs     = new List <long>();
                    long rstValue = 0;
                    for (int index = 0; index < xList[i].feature_cache_[j].Length; index++)
                    {
                        var v = xList[i].feature_cache_[j][index];
                        if (old2new.TryGetValue(v, out rstValue) == true)
                        {
                            newfs.Add(rstValue);
                        }
                    }
                    xList[i].feature_cache_[j] = newfs.ToArray();
                }
            });
        }
Пример #2
0
        //Regenerate feature id and shrink features with lower frequency
        public void Shrink(EncoderTagger[] xList, int freq)
        {
            BTreeDictionary<long, long> old2new = new BTreeDictionary<long, long>();
            featureLexicalDict.Shrink(freq);
            maxid_ = featureLexicalDict.RegenerateFeatureId(old2new, y_.Count);
            int feature_count = xList.Length;

            //Update feature ids
#if NO_SUPPORT_PARALLEL_LIB
            for (int i = 0;i < feature_cache_.Count;i++)
#else
            Parallel.For(0, feature_count, parallelOption, i =>
#endif
            {
                for (int j = 0; j < xList[i].feature_cache_.Count; j++)
                {
                    List<long> newfs = new List<long>();
                    long rstValue = 0;
                    foreach (long v in xList[i].feature_cache_[j])
                    {
                        if (old2new.TryGetValue(v, out rstValue) == true)
                        {
                            newfs.Add(rstValue);
                        }
                    }
                    xList[i].feature_cache_[j] = newfs.ToArray();
                }
            }
#if NO_SUPPORT_PARALLEL_LIB
#else
            );
#endif

            Console.WriteLine("Feature size in total : {0}", maxid_);
        }