-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
TestArguments.cs
131 lines (115 loc) · 5.46 KB
/
TestArguments.cs
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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using VW;
namespace cs_unittest
{
[TestClass]
public class TestArgumentsClass
{
[TestMethod]
[TestCategory("Vowpal Wabbit")]
public void TestArguments()
{
using (var vw = new VowpalWabbit(new VowpalWabbitSettings("--cb_explore_adf --epsilon 0.3 --interact ud") { Verbose = true }))
{
// --cb_explore_adf --epsilon 0.3 --interact ud --cb_adf--csoaa_ldf multiline --csoaa_rank
Console.WriteLine(vw.Arguments.CommandLine);
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--cb_explore_adf"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--epsilon 0.3"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--interact ud"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_ldf multiline"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_rank"));
vw.SaveModel("args.model");
}
using (var vw = new VowpalWabbit(new VowpalWabbitSettings { ModelStream = File.Open("args.model", FileMode.Open) }))
{
Console.WriteLine(vw.Arguments.CommandLine);
// --no_stdin--bit_precision 18--cb_explore_adf--epsilon 0.300000--cb_adf--cb_type ips --csoaa_ldf multiline--csoaa_rank--interact ud
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--no_stdin"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--bit_precision 18"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--cb_explore_adf"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--epsilon 0.3"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--interact ud"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_ldf multiline"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_rank"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--cb_type ips"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_ldf multiline"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--interact ud"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("--csoaa_rank"));
}
}
[TestMethod]
[TestCategory("Vowpal Wabbit")]
public void TestQuietAndTestArguments()
{
using (var vw = new VowpalWabbit("--quiet -t"))
{
vw.SaveModel("args.model");
}
using (var vw = new VowpalWabbitModel(new VowpalWabbitSettings { ModelStream = File.Open("args.model", FileMode.Open) }))
{
Assert.IsFalse(vw.Arguments.CommandLine.Contains("--quiet"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("-t"));
using (var vwSub = new VowpalWabbit(new VowpalWabbitSettings { Model = vw }))
{
Assert.IsTrue(vwSub.Arguments.CommandLine.Contains("--quiet"));
Assert.IsTrue(vwSub.Arguments.CommandLine.Contains("-t"));
}
}
using (var vw = new VowpalWabbit(""))
{
vw.SaveModel("args.model");
}
using (var vw = new VowpalWabbitModel(new VowpalWabbitSettings { ModelStream = File.Open("args.model", FileMode.Open) }))
{
Assert.IsFalse(vw.Arguments.CommandLine.Contains("--quiet"));
Assert.IsTrue(vw.Arguments.CommandLine.Contains("-t"));
using (var vwSub = new VowpalWabbit(new VowpalWabbitSettings { Model = vw }))
{
Assert.IsTrue(vwSub.Arguments.CommandLine.Contains("--quiet"));
Assert.IsTrue(vwSub.Arguments.CommandLine.Contains("-t"));
}
}
}
[TestMethod]
[TestCategory("Vowpal Wabbit")]
public void TestArgumentDeDup()
{
using (var vw = new VowpalWabbit("-l 0.3 -l 0.3 --learning_rate 0.3 -f model1 --save_resume -q ab"))
{
Assert.AreEqual(0.3f, vw.Native.Arguments.LearningRate);
}
try
{
using (var vw =
new VowpalWabbit(
"--cb 2 --cb_type ips --cb_type dm --learning_rate 0.1 -f model_bad --save_resume -q ab"))
{
Assert.AreEqual(0.1f, vw.Native.Arguments.LearningRate);
}
Assert.Fail("Disagreering arguments not detected");
}
catch (VowpalWabbitException)
{ }
using (var vw = new VowpalWabbit("-i model1 --save_resume"))
{
Assert.AreEqual(0.5f, vw.Native.Arguments.LearningRate);
}
using (var vw = new VowpalWabbit("-i model1 --save_resume -q ab -l 0.4"))
{
Assert.AreEqual(0.4f, vw.Native.Arguments.LearningRate);
}
// make sure different representations of arguments are matched
using (var vw = new VowpalWabbit("--cb_explore_adf --epsilon 0.1 -f model2"))
{ }
using (var vw = new VowpalWabbit("--cb_explore_adf --epsilon 0.1000 -i model2"))
{ }
}
}
}