Esempio 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++;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new <see cref="VowpalWabbitInterfaceVisitor"/> instance.
 /// </summary>
 /// <param name="vw">The associated vowpal wabbit instance.</param>
 public VowpalWabbitInterfaceVisitor(VowpalWabbit vw)
 {
     this.vw               = vw;
     this.builder          = null;
     this.namespaceBuilder = null;
     this.featureGroup     = '\0';
     this.namespaceHash    = 0;
 }
Esempio n. 3
0
        public void Visit(INamespaceSparse namespaceSparse)
        {
            // compute shared namespace hash
            this.namespaceHash = namespaceSparse.Name == null?
                                 this.vw.HashSpace(namespaceSparse.FeatureGroup.ToString()) :
                                     this.vw.HashSpace(namespaceSparse.FeatureGroup + namespaceSparse.Name);

            this.featureGroup = (byte)(namespaceSparse.FeatureGroup ?? 0);

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

            // Visit each feature
            foreach (var element in namespaceSparse.Features)
            {
                element.Visit();
            }
        }
Esempio n. 4
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++;
            }
        }