/* 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" namespace VW { ref class VowpalWabbitExample; ref class VowpalWabbit; using namespace System::Collections::Generic; /// /// Interface for prediction factories enabling read-out of various prediction results in an extendable manner. /// generic public interface class IVowpalWabbitPredictionFactory { public: /// /// Creates a new prediction result from an example and the associated VW instance. /// /// A prediction result. /// Implementation must be thread-safe. T Create(vw* vw, example* ex); /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { prediction_type::prediction_type_t get(); } }; /// /// A scalar prediction result. /// public ref class VowpalWabbitDynamicPredictionFactory sealed : IVowpalWabbitPredictionFactory { public: /// /// Extracts prediction results from example. /// virtual System::Object^ Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { throw gcnew NotSupportedException("Prediction type is not available."); } } }; /// /// A scalar prediction result. /// public ref class VowpalWabbitScalarPredictionFactory sealed : IVowpalWabbitPredictionFactory { public: /// /// Extracts prediction results from example. /// virtual float Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { return prediction_type::scalar; } } }; public value struct VowpalWabbitScalar { public: float Value; float Confidence; }; /// /// A scalar prediction result. /// public ref class VowpalWabbitScalarConfidencePredictionFactory sealed : IVowpalWabbitPredictionFactory { public: /// /// Extracts prediction results from example. /// virtual VowpalWabbitScalar Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { return prediction_type::scalar; } } }; /// /// A scalar prediction result. /// public ref class VowpalWabbitScalarsPredictionFactory sealed : IVowpalWabbitPredictionFactory^> { public: /// /// Extracts prediction results from example. /// virtual cli::array^ Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { return prediction_type::scalars; } } }; /// /// A scalar prediction result. /// public ref class VowpalWabbitProbabilityPredictionFactory sealed : IVowpalWabbitPredictionFactory { public: /// /// Extracts prediction results from example. /// virtual float Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { return prediction_type::prob; } } }; /// /// A cost sensitive prediction result. /// public ref class VowpalWabbitCostSensitivePredictionFactory sealed : IVowpalWabbitPredictionFactory { public: /// /// Extracts cost sensitive prediction results from example. /// virtual float Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { return prediction_type::multiclass; } } }; /// /// A cost sensitive prediction result. /// public ref class VowpalWabbitMulticlassPredictionFactory sealed : IVowpalWabbitPredictionFactory { public: /// /// Extracts cost sensitive prediction results from example. /// virtual uint32_t Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { return prediction_type::multiclass; } } }; /// /// A cost sensitive prediction result with associated confidence score /// For -oaa --probabilities /// public ref class VowpalWabbitMulticlassProbabilitiesPredictionFactory sealed : IVowpalWabbitPredictionFactory^> { public: /// /// Extracts cost sensitive prediction results from example, including confidence score. /// virtual Dictionary^ Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { return prediction_type::multiclassprobs; } } }; /// /// A multi label prediction result. /// public ref class VowpalWabbitMultilabelPredictionFactory sealed : IVowpalWabbitPredictionFactory^> { public: /// /// Extracts multilabel prediction results from example. /// virtual cli::array^ Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { return prediction_type::multilabels; } } }; [System::Diagnostics::DebuggerDisplay("{Action}:{Score}")] public value struct ActionScore sealed { public: property uint32_t Action; property float Score; }; /// /// A action score/probability result. /// public ref class VowpalWabbitActionScoreBasePredictionFactory abstract : IVowpalWabbitPredictionFactory^> { public: /// /// Extracts multilabel prediction results from example. /// virtual cli::array^ Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() abstract; } }; /// /// A action score prediction result. /// public ref class VowpalWabbitActionScorePredictionFactory sealed : public VowpalWabbitActionScoreBasePredictionFactory { public: /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() override sealed { return prediction_type::action_scores; } } }; /// /// A multi label prediction result. /// public ref class VowpalWabbitActionProbabilitiesPredictionFactory sealed : public VowpalWabbitActionScoreBasePredictionFactory { public: /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() override sealed { return prediction_type::action_probs; } } }; /// /// A topic prediction result. /// public ref class VowpalWabbitTopicPredictionFactory sealed : IVowpalWabbitPredictionFactory^> { public: /// /// Extracts prediction results from example. The predicted topics. /// virtual cli::array^ Create(vw* vw, example* ex) sealed; /// /// Returns the supported prediction type. /// property prediction_type::prediction_type_t PredictionType { virtual prediction_type::prediction_type_t get() sealed { throw gcnew NotSupportedException("Prediction type is not available."); } } }; /// /// Provides convenient collection of all prediction types. /// public ref class VowpalWabbitPredictionType sealed abstract { public: /// /// Use for scalar predictions. /// static initonly VowpalWabbitScalarPredictionFactory^ Scalar = gcnew VowpalWabbitScalarPredictionFactory; /// /// Use for scalar predictions. /// static initonly VowpalWabbitScalarConfidencePredictionFactory^ ScalarConfidence = gcnew VowpalWabbitScalarConfidencePredictionFactory; /// /// Use for scalar predictions. /// static initonly VowpalWabbitScalarsPredictionFactory^ Scalars = gcnew VowpalWabbitScalarsPredictionFactory; /// /// Use for cost sensitive predictions. /// static initonly VowpalWabbitCostSensitivePredictionFactory^ CostSensitive = gcnew VowpalWabbitCostSensitivePredictionFactory; /// /// Use for multi label predictions. /// static initonly VowpalWabbitMultilabelPredictionFactory^ Multilabel = gcnew VowpalWabbitMultilabelPredictionFactory; /// /// Use for multi class predictions. /// static initonly VowpalWabbitMulticlassPredictionFactory^ Multiclass = gcnew VowpalWabbitMulticlassPredictionFactory; /// /// Use for action score predictions. /// static initonly VowpalWabbitActionScorePredictionFactory^ ActionScore = gcnew VowpalWabbitActionScorePredictionFactory; /// /// Use for action score predictions. /// static initonly VowpalWabbitActionProbabilitiesPredictionFactory^ ActionProbabilities = gcnew VowpalWabbitActionProbabilitiesPredictionFactory; /// /// Use for LDA topic predictions. /// static initonly VowpalWabbitTopicPredictionFactory^ Topic = gcnew VowpalWabbitTopicPredictionFactory; /// /// Use for dynamicially determined predictions. /// static initonly VowpalWabbitDynamicPredictionFactory^ Dynamic = gcnew VowpalWabbitDynamicPredictionFactory; /// /// Use for dynamicially determined predictions. /// static initonly VowpalWabbitProbabilityPredictionFactory^ Probability = gcnew VowpalWabbitProbabilityPredictionFactory; /// /// Use for multiclass predictions with probabilities /// static initonly VowpalWabbitMulticlassProbabilitiesPredictionFactory^ MultiClassProbabilities = gcnew VowpalWabbitMulticlassProbabilitiesPredictionFactory; }; }