Esempio n. 1
0
 //deserialize the object
 public CLabelFeatureData(BinaryReaderEx binReaderEx)
     : base(binReaderEx)
 {                       
     this.feature = binReaderEx.Read<DataMatrixSerialized<float>>();
 }		    
Esempio n. 2
0
        //deserialize the object
        public CLabelFeatureDataCoded(BinaryReaderEx binReaderEx)
            : base(binReaderEx)
        {
            this.codeBook = binReaderEx.Read<CodeBook>();

            bool featureCodedExist = binReaderEx.ReadBoolean();
            if (featureCodedExist)
            {                
                this.featureCoded = binReaderEx.Read<DataMatrixSerialized<ushort>>();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Load LabelFeatureData file - static function for both CLabelFeatureData and CLabelFeatureDataCoded
        /// load in the file and output a LabelFeatureData object that has the specified Type (type = {LabelFeatureData, LabelFeatureDataCode}
        /// </summary>
        /// <param name="inFileName">the name of the file: xxx.tsv == tsv file formation; xxx.bin == binary uncoded data format; xxx.dp == binary coded data format</param>
        /// <param name="featureParser">parser that understand the feature values</param>
        /// <param name="labelParser">parser that understand the label values</param>
        /// <param name="dataGroupBoundary">data group boundaries</param>
        /// <param name="outDatatype">the output data type LabelFeatureData or LabelFeatureDataCoded</param>
        /// <param name="activeFeatureNames">only these feature values are loaded</param>
        /// <param name="cThreads">number of threads used to code the original data</param>
        /// <returns>the desired LabelFeatureData if no errors in loading; otherwise, null</returns>
        static public LabelFeatureData Load(string inFileName, IParser<float> featureParser, IParser<float> labelParser, IGroupBoundary dataGroupBoundary,
                                            Type outDataType, string[] activeFeatureNames, int cThreads, bool fCacheCodedFeature, bool fSparseCoded)
        {
            if (inFileName == null)
            {
                return null;
            }

            string[] fields = inFileName.Split('.');
            if (fields.Length <= 0)
            {
                return null;
            }

            CLabelFeatureData labelFeatureData = null;

            string sufix = fields[fields.Length-1];
            
            if (string.Compare(sufix, "bin", true) == 0 || string.Compare(sufix, "dp", true) == 0)
            {
                BinaryReaderEx binReaderEx = new BinaryReaderEx(inFileName);
                Type t = binReaderEx.Read<Type>();
                labelFeatureData = (CLabelFeatureData)binReaderEx.Read(t);
                binReaderEx.Close();
                
                labelFeatureData.SetActiveFeatures(activeFeatureNames);
            }
            else // "tsv" or null
            {
                TsvFileLoader tsvFileLoader = new TsvFileLoader(inFileName, null, labelParser, featureParser, dataGroupBoundary);

                labelFeatureData = new CLabelFeatureData(tsvFileLoader.FeatureName, tsvFileLoader.Labels, tsvFileLoader.GroupId, tsvFileLoader.Feature);
            }

            if (outDataType.Equals(typeof(CLabelFeatureDataCoded)))
            {
                if (labelFeatureData.GetType().Equals(typeof(CLabelFeatureDataCoded)))
                {
                    if (fCacheCodedFeature)
                    {
                        ((CLabelFeatureDataCoded)labelFeatureData).EncodeFeatureValues(cThreads, fSparseCoded);
                    }
                }
                else
                {
                    //need to upgrade to coded                    
                    labelFeatureData = new CLabelFeatureDataCoded(labelFeatureData, cThreads, fCacheCodedFeature, fSparseCoded);
                }
            }           

            return labelFeatureData;
        }