1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from Numeric import dot, matrixmultiply
25
26
29 """Class for the creation of linear inequality constraint functions and gradients.
30
31 The constraints are in the form:
32
33 A.x >= b
34
35 where:
36 A is an m*n matrix where the rows are the transposed vectors, ai, of length
37 n. The elements of ai are the coefficients of the model parameters.
38
39 x is the vector of model parameters of dimension n.
40
41 b is the vector of scalars of dimension m.
42
43 m is the number of constraints.
44
45 n is the number of model parameters.
46
47
48 eg if 0 <= q <= 1, q >= 1 - 2r, and 0 <= r, then:
49
50 | 1 0 | | 0 |
51 | | | |
52 |-1 0 | | q | | -1 |
53 | | . | | >= | |
54 | 1 2 | | r | | 1 |
55 | | | |
56 | 0 1 | | 2 |
57 """
58
59
60 self.A = A
61 self.b = b
62
63
65 """The constraint function.
66
67 A vector containing the constraint values is returned.
68 """
69
70 return dot(self.A, x) - self.b
71
72
74 """The constraint gradient.
75
76 As the inequality constraints are linear, the gradient matrix is constant and equal to the
77 coefficient matrix A. Therefore this function simply returns the matrix.
78 """
79
80 return self.A
81