Skip to content

Commit 627fa0a

Browse files
Added monotonicConstraint.m and corresponding documentation.
Signed-off-by: Jason Nicholson <1058191+jasonnicholson@users.noreply.github.com>
1 parent a88069f commit 627fa0a

File tree

9 files changed

+243
-55
lines changed

9 files changed

+243
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/*
80.5 KB
Binary file not shown.

Examples/html/constraint_and_Mapping_Example.html

Lines changed: 21 additions & 24 deletions
Large diffs are not rendered by default.

doc/html/helptoc.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<toc version="2.0">
33
<tocitem target="index.html">regularizeNd Toolbox
44
<tocitem target="GettingStarted.html">Getting Started</tocitem>
5+
<tocitem target="lsqConstrainedAlternativeDoc.html">lsqConstrainedAlternative</tocitem>
6+
<tocitem target="monotonicConstraintDoc.html">monotonicConstraint</tocitem>
57
<tocitem target="regularizeNdDoc.html">regularizeNd</tocitem>
68
<tocitem target="regularizeNdMatricesDoc.html">regularizeNdMatrices</tocitem>
7-
<tocitem target="lsqConstrainedAlternativeDoc.html">lsqConstrainedAlternative</tocitem>
89
</tocitem>
910
</toc>

doc/html/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
<H1>regularizeNd Toolbox</H1>
99
<ul>
1010
<li><a href="GettingStarted.html">Getting Started</a></li>
11+
<li><a href="lsqConstrainedAlternativeDoc.html">lsqConstrainedAlternative</a></li>
12+
<li><a href="monotonicConstraintDoc.html">monotonicConstraint</a></li>
1113
<li><a href="regularizeNdDoc.html">regularizeNd</a></li>
1214
<li><a href="regularizeNdMatricesDoc.html">regularizeNdMatrices</a></li>
13-
<li><a href="lsqConstrainedAlternativeDoc.html">lsqConstrainedAlternative</a></li>
1415
</body>
1516
</html>
1617

doc/html/monotonicConstraintDoc.html

Lines changed: 91 additions & 0 deletions
Large diffs are not rendered by default.

doc/monotonicConstraintDoc.mlx

6.5 KB
Binary file not shown.

source/monotonicConstraint.m

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
function [A,b] = monotonicConstraint(xGrid,dimension,dxMin)
2+
% monotonicConstraint generates matrices for a monotonic increasing constraint of A*x<=b
3+
%
4+
%
5+
% [A,b] = monotonicConstraint(xGrid)
6+
% [A,b] = monotonicConstraint(xGrid,dimension)
7+
% [A,b] = monotonicConstraint(xGrid,dimension,dxMin)
8+
%
9+
%% Inputs
10+
% * xGrid - cell array of grid vectors
11+
% dimension - The monotonic constraint is formed across this dimension.
12+
% default: 1
13+
% * dxMin - The minimum difference between different elements of x. x(i+l) >= x(i) + dxMin
14+
% default: 0
15+
%
16+
%% Outputs
17+
% * A - A matrix in A*x<=b
18+
% * b - b vector in A*x<=b
19+
%
20+
%% Description
21+
% This function is mainly used in conjunction with regularizeNdMatrices to create monotonic increasing constraints.
22+
% Monotonicly decreasing constraints are just the negative of A, Aneg = -A and bneg = b.
23+
%
24+
% The main point of this function is to setup a monotonic increasing constraint in the Form A*x<=b that can be used
25+
% in lsqlin or similar. To formulate this we start with
26+
% x2 >= xl + dxMin
27+
% x2-xl >= dxMin
28+
% xl-x2 <= -dxMin
29+
%
30+
% Then generalize this to a matrix form: A*x<=b %
31+
% A = [1 -1 0 0 ... 0;
32+
% 0 1 -1 0 ... 0;
33+
% 0 0 1 -1... 0;
34+
% ...
35+
% 0 0 0 0 1 -1];
36+
%
37+
% b = [-dxMin;
38+
% -dxMin;
39+
% ...
40+
% -dxMin];
41+
%
42+
% Then we need to generalize this to expanding across an n-dimensional grid at the m dimension. This will produce a
43+
% different structure in A. i.e. The 1 and -1 in a row mat not be adjacent to each other.
44+
%
45+
%% Example
46+
% xGrid = {1:10};
47+
% [A,b] = monotonicConstraint(xGrid)
48+
% full(A)
49+
%
50+
% % 2d example
51+
% xGrid2 = {1:5, 10:15};
52+
% dimension = 2;
53+
% bMax = 1e-3;
54+
% [A,b] = monotonicConstraint(xGrid2,dimension, bMax)
55+
% full(A)
56+
%
57+
% % monotonic decreasing
58+
% Aneg = -A;
59+
% bneg = b;
60+
% full(Aneg)
61+
%
62+
63+
narginchk(1,3);
64+
if nargin < 3
65+
dxMin =0;
66+
if nargin <2
67+
dimension =1;
68+
end
69+
end
70+
71+
% We want xGrid as a row vector
72+
xGrid = reshape(xGrid,1,[]);
73+
74+
% makes sure we are dealing with column vectors
75+
xGrid = cellfun(@(x) x(:),xGrid,"UniformOutput",false);
76+
77+
% calculate position in A matrix for lower points
78+
subGrid = xGrid;
79+
subGrid{dimension} = xGrid{dimension}(1:end-1);
80+
A1 = helper(subGrid,xGrid);
81+
82+
% calculate position in A matrix for upper points
83+
subGrid{dimension} = xGrid{dimension}(2:end);
84+
A2 = helper(subGrid,xGrid);
85+
86+
% the difference between A1 and A2 is A
87+
A = A1 - A2;
88+
89+
% Calculate b
90+
b = -dxMin*ones(size(A,1),1);
91+
end
92+
93+
function [A] = helper(subGrid,xGrid)
94+
95+
% expand the grid
96+
x = cell(size(subGrid));
97+
[x{:}] = ndgrid(subGrid{:});
98+
99+
% reshape all the matrices to vectors and then horizontally concatenate them.
100+
x = cellfun(@(u) u(:), x,"UniformOutput",false); x = horzcat(x{:});
101+
102+
% run the points through regularizeNdMatrices to locate their index in the A matrix
103+
A = regularizeNdMatrices(x, xGrid);
104+
end

toolbox generation/regularizeNd.prj

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<deployment-project plugin="plugin.toolbox" plugin-version="1.0">
2-
<configuration build-checksum="3106798988" file="C:\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\toolbox generation\regularizeNd.prj" location="C:\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\toolbox generation" name="regularizeNd" target="target.toolbox" target-name="Package Toolbox">
2+
<configuration build-checksum="3106798988" file="C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\toolbox generation\regularizeNd.prj" location="C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\toolbox generation" name="regularizeNd" target="target.toolbox" target-name="Package Toolbox">
33
<param.appname>regularizeNd</param.appname>
44
<param.authnamewatermark>Jason Nicholson</param.authnamewatermark>
55
<param.email>jashale@yahoo.com</param.email>
@@ -31,7 +31,7 @@ For an introduction on how regularization of a lookup table works, start here: h
3131
Acknowledgement
3232
Special thanks to Peter Goldstein, author of RegularizeData3D, for his coaching and help through writing regularizeNd.</param.description>
3333
<param.screenshot>${PROJECT_ROOT}\toolbox image.jpg</param.screenshot>
34-
<param.version>2.3.1</param.version>
34+
<param.version>2.4.0</param.version>
3535
<param.output>${PROJECT_ROOT}\regularizeNd.mltbx</param.output>
3636
<param.products.name />
3737
<param.products.id />
@@ -122,11 +122,14 @@ toolbox</param.exclude.filters>
122122
<param.demosxml />
123123
<param.apps />
124124
<param.registered.apps />
125-
<param.docs>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\info.xml</param.docs>
126-
<param.getting.started.guide>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\doc\GettingStarted.mlx</param.getting.started.guide>
125+
<param.docs>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\info.xml</param.docs>
126+
<param.getting.started.guide>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\doc\GettingStarted.mlx</param.getting.started.guide>
127127
<param.matlabpath.excludes />
128128
<param.javaclasspath.excludes />
129129
<param.exported.on.package>false</param.exported.on.package>
130+
<param.required.addons />
131+
<param.matlab.project.id />
132+
<param.matlab.project.name />
130133
<param.release.start />
131134
<param.release.end />
132135
<param.release.current.only>false</param.release.current.only>
@@ -154,6 +157,9 @@ toolbox</param.exclude.filters>
154157
<param.matlabpath.excludes />
155158
<param.javaclasspath.excludes />
156159
<param.exported.on.package />
160+
<param.required.addons />
161+
<param.matlab.project.id />
162+
<param.matlab.project.name />
157163
<param.release.start />
158164
<param.release.end />
159165
<param.release.current.only />
@@ -169,44 +175,31 @@ toolbox</param.exclude.filters>
169175
<param.additional.sw.linux.url />
170176
</unset>
171177
<fileset.rootdir>
172-
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build</file>
178+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build</file>
173179
</fileset.rootdir>
174180
<fileset.rootfiles>
175-
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\demos.xml</file>
176-
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\doc</file>
177-
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\Examples</file>
178-
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\info.xml</file>
179-
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\lsqConstrainedAlternative.m</file>
180-
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\regularizeNd.m</file>
181-
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\regularizeNdMatrices.m</file>
181+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\demos.xml</file>
182+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\doc</file>
183+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\Examples</file>
184+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\info.xml</file>
185+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\lsqConstrainedAlternative.m</file>
186+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\monotonicConstraint.m</file>
187+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\regularizeNd.m</file>
188+
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\regularizeNdMatrices.m</file>
182189
</fileset.rootfiles>
183190
<fileset.depfun.included />
184-
<fileset.depfun.excluded>
185-
<file>${MATLAB_ROOT}\toolbox\matlab\demos\seamount.mat</file>
186-
</fileset.depfun.excluded>
191+
<fileset.depfun.excluded />
187192
<fileset.package />
188193
<build-deliverables>
189-
<file location="C:\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\toolbox generation" name="regularizeNd.mltbx" optional="false">C:\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\toolbox generation\regularizeNd.mltbx</file>
194+
<file location="${PROJECT_ROOT}" name="regularizeNd.mltbx" optional="false">C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\toolbox generation\regularizeNd.mltbx</file>
190195
</build-deliverables>
191196
<workflow />
192197
<matlab>
193-
<root>C:\Program Files\MATLAB\R2018b</root>
198+
<root>C:\Program Files\MATLAB\R2020a</root>
194199
<toolboxes>
195-
<toolbox name="matlabcoder" />
196-
<toolbox name="embeddedcoder" />
197200
<toolbox name="fixedpoint" />
198201
<toolbox name="neuralnetwork" />
199202
</toolboxes>
200-
<toolbox>
201-
<matlabcoder>
202-
<enabled>true</enabled>
203-
</matlabcoder>
204-
</toolbox>
205-
<toolbox>
206-
<embeddedcoder>
207-
<enabled>true</enabled>
208-
</embeddedcoder>
209-
</toolbox>
210203
<toolbox>
211204
<fixedpoint>
212205
<enabled>true</enabled>

0 commit comments

Comments
 (0)