/// <summary>
        /// Initializes a new instance of the <see cref="VowpalWabbit{TExample}"/> class.
        /// </summary>
        /// <param name="vw">The native instance to wrap.</param>
        /// <remarks>This instance takes ownership of <paramref name="vw"/> instance and disposes it.</remarks>
        public VowpalWabbit(VowpalWabbit vw)
        {
            if (vw == null)
            {
                throw new ArgumentNullException("vw");
            }
            Contract.Ensures(this.serializer != null);
            Contract.EndContractBlock();

            this.vw = vw;
            this.compiledSerializer = VowpalWabbitSerializerFactory.CreateSerializer <TExample>(vw.Settings);

            if (this.compiledSerializer == null)
            {
                throw new ArgumentException("No features found for " + typeof(TExample));
            }

            this.serializer = this.compiledSerializer.Create(vw);

            // have a 2nd member to throw NullReferenceException in release instead of silently producing wrong results.
            this.learnSerializer = this.serializer.CachesExamples ? null : this.serializer;

            // have a 3rd member to avoid cast everytime...
            this.singleLineSerializer = this.serializer as VowpalWabbitSingleExampleSerializer <TExample>;
        }
Beispiel #2
0
        /// <summary>
        /// Constructor using a memory stream.
        /// </summary>
        /// <param name="vwModelStream">The VW model memory stream.</param>
        public VWExplorer(Stream vwModelStream = null, ITypeInspector typeInspector = null, bool developmentMode = false)
            : base(vwModelStream, typeInspector, developmentMode)
        {
            this.serializer = VowpalWabbitSerializerFactory.CreateSerializer <TContext>(new VowpalWabbitSettings
            {
                TypeInspector = this.typeInspector,
                EnableStringExampleGeneration = this.developmentMode,
                EnableStringFloatCompact      = this.developmentMode
            });

            this.multiSerializer = this.serializer as IVowpalWabbitMultiExampleSerializerCompiler <TContext>;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VowpalWabbit{TExample}"/> class.
        /// </summary>
        /// <param name="vw">The native instance to wrap.</param>
        /// <param name="compiledSerializer">The per-compiled serializer.</param>
        /// <remarks>This instance takes ownership of <paramref name="vw"/> instance and disposes it.</remarks>
        public VowpalWabbit(VowpalWabbit vw, IVowpalWabbitSerializerCompiler <TExample> compiledSerializer)
        {
            if (vw == null)
            {
                throw new ArgumentNullException(nameof(vw));
            }
            if (compiledSerializer == null)
            {
                throw new ArgumentNullException(nameof(compiledSerializer));
            }
            Contract.Ensures(this.serializer != null);
            Contract.EndContractBlock();

            this.vw = vw;
            this.compiledSerializer = compiledSerializer;

            this.serializer = this.compiledSerializer.Create(vw);

            // have a 2nd member to throw NullReferenceException in release instead of silently producing wrong results.
            this.learnSerializer = this.serializer.CachesExamples ? null : this.serializer;

            // have a 3rd member to avoid cast everytime...
            this.singleLineSerializer = this.serializer as VowpalWabbitSingleExampleSerializer <TExample>;
        }