/* Copyright (c) by respective owners including Yahoo!, Microsoft, and individual contributors. All rights reserved. Released under a BSD (revised) license as described in the file LICENSE. */ #pragma once #include "vw_clr.h" #include #include "vw_interface.h" #include "vw_arguments.h" using namespace System::Collections::Generic; namespace VW { ref class VowpalWabbitPrediction; ref class VowpalWabbitModel; /// /// A base wrapper around vowpal wabbit machine learning instance. /// /// /// Since the model class must delay diposal of until all referencing /// VowpalWabbit instances are disposed, the base class does not dispose . /// public ref class VowpalWabbitBase abstract { private: /// /// The settings used for this instance. /// initonly VowpalWabbitSettings^ m_settings; /// /// Handle to trace listener delegate, required to keep safe from garbage collection. /// GCHandle m_traceListener; /// /// An optional shared model. /// VowpalWabbitModel^ m_model; /// /// Extracted command line arguments. /// VowpalWabbitArguments^ m_arguments; /// /// Reference count to native data structure. /// System::Int32 m_instanceCount; internal: /// /// The native vowpal wabbit data structure. /// vw* m_vw; /// /// Thread-safe increment of reference count. /// void IncrementReference(); /// /// Thread-safe decrement of reference count. /// void DecrementReference(); protected: /// /// True if all nativedata structures are disposed. /// bool m_isDisposed; /// /// Example pool. Kept in base to simplify deallocation. /// IBag^ m_examples; /// /// Initializes a new instance. /// /// Command line arguments. VowpalWabbitBase(VowpalWabbitSettings^ settings); /// /// Cleanup. /// !VowpalWabbitBase(); /// /// Internal dipose using reference counting to delay disposal of shared native data structures. /// void InternalDispose(); void DisposeExample(VowpalWabbitExample^ ex); public: /// /// Cleanup. /// virtual ~VowpalWabbitBase(); /// /// The settings used for this instance. /// property VowpalWabbitSettings^ Settings { VowpalWabbitSettings^ get(); } /// /// Extracted command line arguments. /// property VowpalWabbitArguments^ Arguments { VowpalWabbitArguments^ get(); } /// /// The read/writable model id. /// property String^ ID { String^ get(); void set(String^ id); } /// /// Performs the following steps to reset the learning state: /// /// - Save model to in-memory buffer /// - Dispose existing instance /// - Initialize new instance from in-memory buffer /// void Reload([System::Runtime::InteropServices::Optional] String^ args); /// /// Compares features created by current instance are compatible to features created by . /// /// /// Null if compatible, otherwise the difference /// String^ AreFeaturesCompatible(VowpalWabbitBase^ other); /// /// Persist model to file specified by -i. /// void SaveModel(); /// /// Persist model to . /// /// The destination filename for the model. void SaveModel(String^ filename); /// /// Persist model to . /// /// The destination stream for the model. /// The stream is not closed to support embedded schemes. void SaveModel(Stream^ stream); }; }