Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MWTExploreTests.h « tests « explore - github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c451fb4412b7d562266263725a6a01bf98b2a31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#pragma once

#include "MWTExplorer.h"
#include "utility.h"
#include <iomanip>
#include <iostream>
#include <sstream>

using namespace MultiWorldTesting;

class TestContext
{

};

template <class Ctx>
struct TestInteraction
{
	Ctx& Context;
	u32 Action;
	float Probability;
	string Unique_Key;
};

class TestPolicy : public IPolicy<TestContext>
{
public:
	TestPolicy(int params, int num_actions) : m_params(params), m_num_actions(num_actions) { }
	u32 Choose_Action(TestContext& context)
	{
		return m_params % m_num_actions + 1; // action id is one-based
	}
private:
	int m_params;
	int m_num_actions;
};

class TestScorer : public IScorer<TestContext>
{
public:
	TestScorer(int params, int num_actions, bool uniform = true) : 
		m_params(params), m_num_actions(num_actions), m_uniform(uniform) 
	{ }

	vector<float> Score_Actions(TestContext& context)
	{
		vector<float> scores;
		if (m_uniform)
		{
			for (u32 i = 0; i < m_num_actions; i++)
			{
				scores.push_back(m_params);
			}
		}
		else
		{
			for (u32 i = 0; i < m_num_actions; i++)
			{
				scores.push_back(m_params + i);
			}
		}
		return scores;
	}
private:
	int m_params;
	int m_num_actions;
	bool m_uniform;
};

class FixedScorer : public IScorer<TestContext>
{
public:
	FixedScorer(int num_actions, int value) :
		m_num_actions(num_actions), m_value(value)
	{ }

	vector<float> Score_Actions(TestContext& context)
	{
		vector<float> scores;
		for (u32 i = 0; i < m_num_actions; i++)
		{
			scores.push_back((float)m_value);
		}
		return scores;
	}
private:
	int m_num_actions;
	int m_value;
};

class TestSimpleScorer : public IScorer<SimpleContext>
{
public:
	TestSimpleScorer(int params, int num_actions) : m_params(params), m_num_actions(num_actions) { }
	vector<float> Score_Actions(SimpleContext& context)
	{
		vector<float> scores;
		for (u32 i = 0; i < m_num_actions; i++)
		{
			scores.push_back(m_params);
		}
		return scores;
	}
private:
	int m_params;
	int m_num_actions;
};

class TestSimplePolicy : public IPolicy<SimpleContext>
{
public:
	TestSimplePolicy(int params, int num_actions) : m_params(params), m_num_actions(num_actions) { }
	u32 Choose_Action(SimpleContext& context)
	{
		return m_params % m_num_actions + 1; // action id is one-based
	}
private:
	int m_params;
	int m_num_actions;
};

class TestSimpleRecorder : public IRecorder<SimpleContext>
{
public:
	virtual void Record(SimpleContext& context, u32 action, float probability, string unique_key)
	{
		m_interactions.push_back({ context, action, probability, unique_key });
	}

	vector<TestInteraction<SimpleContext>> Get_All_Interactions()
	{
		return m_interactions;
	}

private:
	vector<TestInteraction<SimpleContext>> m_interactions;
};

// Return action outside valid range
class TestBadPolicy : public IPolicy<TestContext>
{
public:
	u32 Choose_Action(TestContext& context)
	{
		return 100;
	}
};

class TestRecorder : public IRecorder<TestContext>
{
public:
	virtual void Record(TestContext& context, u32 action, float probability, string unique_key)
	{
		m_interactions.push_back({ context, action, probability, unique_key });
	}

	vector<TestInteraction<TestContext>> Get_All_Interactions()
	{
		return m_interactions;
	}

private:
	vector<TestInteraction<TestContext>> m_interactions;
};