Exemplo n.º 1
0
        /// <summary>
        /// Transfers namespace data to native space.
        /// </summary>
        /// <typeparam name="T">The feature type.</typeparam>
        /// <param name="namespaceDense">The dense namespace.</param>
        public void Visit <T>(INamespaceDense <T> namespaceDense)
        {
            Contract.Requires(namespaceDense != null);
            Contract.Requires(namespaceDense.DenseFeature != null);
            Contract.Requires(namespaceDense.DenseFeature.Value != null);

            this.featureGroup = namespaceDense.FeatureGroup ?? '\0';

            this.namespaceHash = namespaceDense.Name == null?
                                 this.vw.HashSpace(this.featureGroup.ToString()) :
                                     this.vw.HashSpace(this.featureGroup + namespaceDense.Name);

            this.namespaceBuilder = this.builder.AddNamespace(this.featureGroup);
            this.namespaceBuilder.PreAllocate(namespaceDense.DenseFeature.Value.Count);

            var i = 0;

            // support anchor feature
            if (namespaceDense.DenseFeature.AddAnchor)
            {
                this.namespaceBuilder.AddFeature(this.namespaceHash, 1);
                i++;
            }

            foreach (var v in namespaceDense.DenseFeature.Value)
            {
                this.namespaceBuilder.AddFeature(
                    (uint)(this.namespaceHash + i),
                    (float)Convert.ToDouble(v));
                i++;
            }
        }
Exemplo n.º 2
0
        public void Visit <T>(INamespaceDense <T> namespaceDense)
        {
            Contract.Requires(namespaceDense != null);

            this.builder.AppendFormat(
                CultureInfo.InvariantCulture,
                " |{0}{1}",
                namespaceDense.FeatureGroup,
                namespaceDense.Name);

            var i = 0;

            // support anchor feature
            if (namespaceDense.DenseFeature.AddAnchor)
            {
                this.builder.Append(" 0:1");
                i++;
            }

            foreach (var value in namespaceDense.DenseFeature.Value)
            {
                this.builder.AppendFormat(
                    CultureInfo.InvariantCulture,
                    " {0}:{1}",
                    i,
                    value);

                i++;
            }
        }
        /// <summary>
        /// Transfers namespace data to native space.
        /// </summary>
        /// <param name="namespaceDense">The dense namespace.</param>
        public void Visit(INamespaceDense <System.Double> namespaceDense)
        {
            this.featureGroup = namespaceDense.FeatureGroup ?? '\0';

            this.namespaceHash = namespaceDense.Name == null?
                                 this.vw.HashSpace(this.featureGroup.ToString()) :
                                     this.vw.HashSpace(this.featureGroup + namespaceDense.Name);

            this.namespaceBuilder = this.builder.AddNamespace(this.featureGroup);
            this.namespaceBuilder.PreAllocate(namespaceDense.DenseFeature.Value.Count);

            var i = 0;

            foreach (var v in namespaceDense.DenseFeature.Value)
            {
                                #if DEBUG
                if (v > float.MaxValue || v < float.MinValue)
                {
                    Trace.TraceWarning("Precision lost for feature value: " + v);
                }
                                #endif

                this.namespaceBuilder.AddFeature((uint)(this.namespaceHash + i), (float)v);
                i++;
            }
        }
        /// <summary>
        /// Transfers namespace data to native space.
        /// </summary>
        /// <param name="namespaceDense">The dense namespace.</param>
        public void Visit(INamespaceDense <System.SByte> namespaceDense)
        {
            this.featureGroup = namespaceDense.FeatureGroup ?? '\0';

            this.namespaceHash = namespaceDense.Name == null?
                                 this.vw.HashSpace(this.featureGroup.ToString()) :
                                     this.vw.HashSpace(this.featureGroup + namespaceDense.Name);

            this.namespaceBuilder = this.builder.AddNamespace(this.featureGroup);
            this.namespaceBuilder.PreAllocate(namespaceDense.DenseFeature.Value.Count);

            var i = 0;

            foreach (var v in namespaceDense.DenseFeature.Value)
            {
                this.namespaceBuilder.AddFeature((uint)(this.namespaceHash + i), v);
                i++;
            }
        }
Exemplo n.º 5
0
        public void Visit <T>(INamespaceDense <T> namespaceDense)
        {
            this.featureGroup = (byte)(namespaceDense.FeatureGroup ?? 0);

            this.namespaceHash = namespaceDense.Name == null?
                                 this.vw.HashSpace(this.featureGroup.ToString()) :
                                     this.vw.HashSpace(this.featureGroup + namespaceDense.Name);

            this.namespaceBuilder = this.builder.AddNamespace(this.featureGroup);

            var i = 0;

            foreach (var v in namespaceDense.DenseFeature.Value)
            {
                this.namespaceBuilder.AddFeature(
                    (uint)(this.namespaceHash + i),
                    (float)Convert.ToDouble(v));
                i++;
            }
        }