/
test_exp.jl
81 lines (68 loc) · 1.88 KB
/
test_exp.jl
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
using Convex
using FactCheck
TOL = 1e-3
facts("Exp Atoms") do
context("exp atom") do
y = Variable()
p = minimize(exp(y), y>=0)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(1, TOL)
@fact evaluate(exp(y)) => roughly(1, TOL)
y = Variable()
p = minimize(exp(y), y>=1)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(exp(1), TOL)
@fact evaluate(exp(y)) => roughly(exp(1), TOL)
y = Variable(5)
p = minimize(sum(exp(y)), y>=0)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(5, TOL)
@fact evaluate(sum(exp(y))) => roughly(5, TOL)
y = Variable(5)
p = minimize(sum(exp(y)), y>=0)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(5, TOL)
end
context("log atom") do
y = Variable()
p = maximize(log(y), y<=1)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(0, TOL)
y = Variable()
p = maximize(log(y), y<=2)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(log(2), TOL)
y = Variable()
p = maximize(log(y), [y<=2, exp(y)<=10])
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(log(2), TOL)
end
context("log sum exp atom") do
y = Variable(5);
p = minimize(logsumexp(y), y>=1)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(log(exp(1)*5), TOL)
end
context("logistic loss atom") do
y = Variable(5);
p = minimize(logistic_loss(y), y>=1)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(log(exp(1)+1)*5, TOL)
end
context("entropy atom") do
y = Variable(5, Positive());
p = maximize(entropy(y), sum(y)<=1)
@fact vexity(p) => ConvexVexity()
solve!(p)
@fact p.optval => roughly(-log(1/5), TOL)
end
end