/*
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 "vw_base.h"
#include "vw_model.h"
#include "vw_prediction.h"
#include "vw_interface.h"
namespace VW
{
ref class VowpalWabbitExampleBuilder;
ref struct VowpalWabbitFeature;
///
/// Simple string example based wrapper for vowpal wabbit.
///
/// If possible use VowpalWabbit{T} types as this wrapper suffers from marshalling performance wise.
public ref class VowpalWabbit : VowpalWabbitBase, IVowpalWabbitExamplePool
{
private:
///
/// Select the right hash method based on args.
///
Func^ GetHasher();
///
/// The selected hasher method.
///
///
/// Avoiding if-else for hash function selection. Delegates outperform function pointers according to http://stackoverflow.com/questions/13443250/performance-of-c-cli-function-pointers-versus-net-delegates
///
initonly Func^ m_hasher;
template
cli::array^>^ FillTopicAllocation(T& weights);
///
/// Write and empty line example to vw cache file.
///
///
/// This is used to emit empty lines to cache while handling multiline examples.
/// Used internally by Learn(IEnumerable<String> lines)
///
void CacheEmptyLine();
public:
///
/// Initializes a new instance.
///
/// The settings.
VowpalWabbit(VowpalWabbitSettings^ settings);
///
/// Initializes a new instance.
///
/// Command line arguments.
VowpalWabbit(String^ args);
///
/// Run multi-passe training.
///
void RunMultiPass();
///
/// Gets Collected performance statistics.
///
property VowpalWabbitPerformanceStatistics^ PerformanceStatistics
{ VowpalWabbitPerformanceStatistics^ get();
}
///
/// Parses using the C++ parser.
///
///
/// Returns a ready to be used for or .
///
VowpalWabbitExample^ ParseLine(String^ line);
///
/// Parses using the C++ parser.
/// TODO: this should return VowpalWabbitExampleCollection, but that would require moving VowpalWaabitExampleCollection to C++/CLI
///
///
/// Returns a ready to be used for or .
///
List^ ParseJson(String^ line);
///
/// Parses using the C++ parser and supports the extra wrapping introduced by Decision Service.
/// TODO: this should return VowpalWabbitExampleCollection, but that would require moving VowpalWaabitExampleCollection to C++/CLI
/// TODO: the header should be passed along with the List of VowpalWabbit examples, but that requires additional care wrt disposing items.
///
/// This needs to be null-terminated string.
/// If true the json array is copied prior to destructive parsing
///
/// Returns a ready to be used for or .
///
List^ VowpalWabbit::ParseDecisionServiceJson(cli::array^ json, int offset, int length, bool copyJson, [Out] VowpalWabbitDecisionServiceInteractionHeader^% header);
///
/// Hashes the given namespace .
///
/// String to be hashed.
/// The resulting hash code.
/// The hash code depends on the vowpal wabbit instance as different has functions can be configured.
uint64_t HashSpaceNative(String^ s);
///
/// Hashes the given namespace .
///
/// String to be hashed.
/// The resulting hash code.
/// The hash code depends on the vowpal wabbit instance as different has functions can be configured.
uint64_t HashSpace(String^ s);
///
/// Hash the given feature .
///
/// String to be hashed.
/// Hash offset.
/// The resulting hash code.
/// The hash code depends on the vowpal wabbit instance as different has functions can be configured.
uint64_t HashFeatureNative(String^ s, size_t u);
///
/// Hash the given feature .
///
/// String to be hashed.
/// Hash offset.
/// The resulting hash code.
/// The hash code depends on the vowpal wabbit instance as different has functions can be configured.
uint64_t HashFeature(String^ s, size_t u);
///
/// Return full topic allocation [topic, feature].
///
cli::array^>^ GetTopicAllocation();
///
/// Return the topic weights.
///
cli::array^>^ GetTopicAllocation(int top);
///
/// The associated instance learns from this example and returns the prediction result for this example.
///
/// The prediction result.
/// The prediction result type.
generic T Learn(VowpalWabbitExample^ example, IVowpalWabbitPredictionFactory^ predictionFactory);
///
/// Predicts for the given example.
///
/// The prediction type.
/// Example to predict for.
/// The prediction factory to be used. See .
/// The prediction for the given .
generic T Predict(VowpalWabbitExample^ example, IVowpalWabbitPredictionFactory^ predictionFactory);
///
/// Learns from the given example.
///
/// Example to learn from.
void Learn(VowpalWabbitExample^ example);
///
/// Learns from the given multiline example.
///
/// Example to learn from.
void Learn(List^ examples);
///
/// Predicts for the given example.
///
/// Example to predict for.
void Predict(VowpalWabbitExample^ example);
///
/// Predicts for the given multiline example.
///
/// Example to predict for.
void Predict(List^ examples);
///
/// Learns from string data.
///
/// Data in vw string format.
void Learn(String^ line);
///
/// Predicts for string data.
///
/// Data in vw string format.
void Predict(String^ line);
///
/// Learns from string data.
///
/// The prediction type.
/// Data in vw string format.
/// The prediction factory to be used. See .
/// The prediction for the given .
generic T Learn(String^ line, IVowpalWabbitPredictionFactory^ predictionFactory);
///
/// Predicts for string data.
///
/// The prediction type.
/// Data in vw string format.
/// The prediction factory to be used. See .
/// The prediction for the given .
generic T Predict(String^ line, IVowpalWabbitPredictionFactory^ predictionFactory);
///
/// Learns from multi-line examples.
///
/// Data in vw string format.
void Learn(IEnumerable^ lines);
///
/// Predicts for multi-line examples.
///
/// Data in vw string format.
void Predict(IEnumerable^ lines);
///
/// Learns from multi-line examples.
///
/// The prediction type.
/// Data in vw string format.
/// The prediction factory to be used. See .
/// The prediction for the given .
generic T Learn(IEnumerable^ lines, IVowpalWabbitPredictionFactory^ predictionFactory);
///
/// Predicts for the given lines.
///
/// The prediction type.
/// Data in vw string format.
/// The prediction factory to be used. See .
/// The prediction for the given .
generic T Predict(IEnumerable^ lines, IVowpalWabbitPredictionFactory^ predictionFactory);
///
/// Signals the end of a pass.
///
void EndOfPass();
///
/// Invokes the driver.
///
void Driver();
virtual property VowpalWabbit^ Native
{ virtual VowpalWabbit^ get() sealed;
}
///
/// Gets or creates a native example from a CLR maintained, but natively allocated pool.
///
/// A ready to use cleared native example data structure.
virtual VowpalWabbitExample^ GetOrCreateNativeExample() sealed;
///
/// Puts a native example data structure back into the pool.
///
/// The example to be returned.
virtual void ReturnExampleToPool(VowpalWabbitExample^ example) sealed;
};
}