Skip to content

Commit

Permalink
Added monotonicConstraint.m and corresponding documentation.
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Nicholson <1058191+jasonnicholson@users.noreply.github.com>
  • Loading branch information
jasonnicholson committed Feb 23, 2021
1 parent a88069f commit 627fa0a
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/*
Binary file modified Examples/constraint_and_Mapping_Example.mlx
Binary file not shown.
45 changes: 21 additions & 24 deletions Examples/html/constraint_and_Mapping_Example.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion doc/html/helptoc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<toc version="2.0">
<tocitem target="index.html">regularizeNd Toolbox
<tocitem target="GettingStarted.html">Getting Started</tocitem>
<tocitem target="lsqConstrainedAlternativeDoc.html">lsqConstrainedAlternative</tocitem>
<tocitem target="monotonicConstraintDoc.html">monotonicConstraint</tocitem>
<tocitem target="regularizeNdDoc.html">regularizeNd</tocitem>
<tocitem target="regularizeNdMatricesDoc.html">regularizeNdMatrices</tocitem>
<tocitem target="lsqConstrainedAlternativeDoc.html">lsqConstrainedAlternative</tocitem>
</tocitem>
</toc>
3 changes: 2 additions & 1 deletion doc/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<H1>regularizeNd Toolbox</H1>
<ul>
<li><a href="GettingStarted.html">Getting Started</a></li>
<li><a href="lsqConstrainedAlternativeDoc.html">lsqConstrainedAlternative</a></li>
<li><a href="monotonicConstraintDoc.html">monotonicConstraint</a></li>
<li><a href="regularizeNdDoc.html">regularizeNd</a></li>
<li><a href="regularizeNdMatricesDoc.html">regularizeNdMatrices</a></li>
<li><a href="lsqConstrainedAlternativeDoc.html">lsqConstrainedAlternative</a></li>
</body>
</html>

91 changes: 91 additions & 0 deletions doc/html/monotonicConstraintDoc.html

Large diffs are not rendered by default.

Binary file added doc/monotonicConstraintDoc.mlx
Binary file not shown.
104 changes: 104 additions & 0 deletions source/monotonicConstraint.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
function [A,b] = monotonicConstraint(xGrid,dimension,dxMin)
% monotonicConstraint generates matrices for a monotonic increasing constraint of A*x<=b
%
%
% [A,b] = monotonicConstraint(xGrid)
% [A,b] = monotonicConstraint(xGrid,dimension)
% [A,b] = monotonicConstraint(xGrid,dimension,dxMin)
%
%% Inputs
% * xGrid - cell array of grid vectors
% dimension - The monotonic constraint is formed across this dimension.
% default: 1
% * dxMin - The minimum difference between different elements of x. x(i+l) >= x(i) + dxMin
% default: 0
%
%% Outputs
% * A - A matrix in A*x<=b
% * b - b vector in A*x<=b
%
%% Description
% This function is mainly used in conjunction with regularizeNdMatrices to create monotonic increasing constraints.
% Monotonicly decreasing constraints are just the negative of A, Aneg = -A and bneg = b.
%
% The main point of this function is to setup a monotonic increasing constraint in the Form A*x<=b that can be used
% in lsqlin or similar. To formulate this we start with
% x2 >= xl + dxMin
% x2-xl >= dxMin
% xl-x2 <= -dxMin
%
% Then generalize this to a matrix form: A*x<=b %
% A = [1 -1 0 0 ... 0;
% 0 1 -1 0 ... 0;
% 0 0 1 -1... 0;
% ...
% 0 0 0 0 1 -1];
%
% b = [-dxMin;
% -dxMin;
% ...
% -dxMin];
%
% Then we need to generalize this to expanding across an n-dimensional grid at the m dimension. This will produce a
% different structure in A. i.e. The 1 and -1 in a row mat not be adjacent to each other.
%
%% Example
% xGrid = {1:10};
% [A,b] = monotonicConstraint(xGrid)
% full(A)
%
% % 2d example
% xGrid2 = {1:5, 10:15};
% dimension = 2;
% bMax = 1e-3;
% [A,b] = monotonicConstraint(xGrid2,dimension, bMax)
% full(A)
%
% % monotonic decreasing
% Aneg = -A;
% bneg = b;
% full(Aneg)
%

narginchk(1,3);
if nargin < 3
dxMin =0;
if nargin <2
dimension =1;
end
end

% We want xGrid as a row vector
xGrid = reshape(xGrid,1,[]);

% makes sure we are dealing with column vectors
xGrid = cellfun(@(x) x(:),xGrid,"UniformOutput",false);

% calculate position in A matrix for lower points
subGrid = xGrid;
subGrid{dimension} = xGrid{dimension}(1:end-1);
A1 = helper(subGrid,xGrid);

% calculate position in A matrix for upper points
subGrid{dimension} = xGrid{dimension}(2:end);
A2 = helper(subGrid,xGrid);

% the difference between A1 and A2 is A
A = A1 - A2;

% Calculate b
b = -dxMin*ones(size(A,1),1);
end

function [A] = helper(subGrid,xGrid)

% expand the grid
x = cell(size(subGrid));
[x{:}] = ndgrid(subGrid{:});

% reshape all the matrices to vectors and then horizontally concatenate them.
x = cellfun(@(u) u(:), x,"UniformOutput",false); x = horzcat(x{:});

% run the points through regularizeNdMatrices to locate their index in the A matrix
A = regularizeNdMatrices(x, xGrid);
end
51 changes: 22 additions & 29 deletions toolbox generation/regularizeNd.prj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<deployment-project plugin="plugin.toolbox" plugin-version="1.0">
<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">
<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">
<param.appname>regularizeNd</param.appname>
<param.authnamewatermark>Jason Nicholson</param.authnamewatermark>
<param.email>jashale@yahoo.com</param.email>
Expand Down Expand Up @@ -31,7 +31,7 @@ For an introduction on how regularization of a lookup table works, start here: h
Acknowledgement
Special thanks to Peter Goldstein, author of RegularizeData3D, for his coaching and help through writing regularizeNd.</param.description>
<param.screenshot>${PROJECT_ROOT}\toolbox image.jpg</param.screenshot>
<param.version>2.3.1</param.version>
<param.version>2.4.0</param.version>
<param.output>${PROJECT_ROOT}\regularizeNd.mltbx</param.output>
<param.products.name />
<param.products.id />
Expand Down Expand Up @@ -122,11 +122,14 @@ toolbox</param.exclude.filters>
<param.demosxml />
<param.apps />
<param.registered.apps />
<param.docs>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\info.xml</param.docs>
<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>
<param.docs>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\info.xml</param.docs>
<param.getting.started.guide>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\doc\GettingStarted.mlx</param.getting.started.guide>
<param.matlabpath.excludes />
<param.javaclasspath.excludes />
<param.exported.on.package>false</param.exported.on.package>
<param.required.addons />
<param.matlab.project.id />
<param.matlab.project.name />
<param.release.start />
<param.release.end />
<param.release.current.only>false</param.release.current.only>
Expand Down Expand Up @@ -154,6 +157,9 @@ toolbox</param.exclude.filters>
<param.matlabpath.excludes />
<param.javaclasspath.excludes />
<param.exported.on.package />
<param.required.addons />
<param.matlab.project.id />
<param.matlab.project.name />
<param.release.start />
<param.release.end />
<param.release.current.only />
Expand All @@ -169,44 +175,31 @@ toolbox</param.exclude.filters>
<param.additional.sw.linux.url />
</unset>
<fileset.rootdir>
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build</file>
</fileset.rootdir>
<fileset.rootfiles>
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\demos.xml</file>
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\doc</file>
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\Examples</file>
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\info.xml</file>
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\lsqConstrainedAlternative.m</file>
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\regularizeNd.m</file>
<file>C:\Users\jlb6jxe\OneDrive-Deere&amp;Co\OneDrive - Deere &amp; Co\Documents\MATLAB\Projects\regularizeNd\build\regularizeNdMatrices.m</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\demos.xml</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\doc</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\Examples</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\info.xml</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\lsqConstrainedAlternative.m</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\monotonicConstraint.m</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\regularizeNd.m</file>
<file>C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\build\regularizeNdMatrices.m</file>
</fileset.rootfiles>
<fileset.depfun.included />
<fileset.depfun.excluded>
<file>${MATLAB_ROOT}\toolbox\matlab\demos\seamount.mat</file>
</fileset.depfun.excluded>
<fileset.depfun.excluded />
<fileset.package />
<build-deliverables>
<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>
<file location="${PROJECT_ROOT}" name="regularizeNd.mltbx" optional="false">C:\Users\jason\OneDrive\Documents\MATLAB\Projects\regularizeNd\toolbox generation\regularizeNd.mltbx</file>
</build-deliverables>
<workflow />
<matlab>
<root>C:\Program Files\MATLAB\R2018b</root>
<root>C:\Program Files\MATLAB\R2020a</root>
<toolboxes>
<toolbox name="matlabcoder" />
<toolbox name="embeddedcoder" />
<toolbox name="fixedpoint" />
<toolbox name="neuralnetwork" />
</toolboxes>
<toolbox>
<matlabcoder>
<enabled>true</enabled>
</matlabcoder>
</toolbox>
<toolbox>
<embeddedcoder>
<enabled>true</enabled>
</embeddedcoder>
</toolbox>
<toolbox>
<fixedpoint>
<enabled>true</enabled>
Expand Down

0 comments on commit 627fa0a

Please sign in to comment.