Home > src > generateEQ.m

generateEQ

PURPOSE ^

% Generating the Equations

SYNOPSIS ^

function [ output ] = generateEQ(M, subM, forceM, initFM, alpha_c)

DESCRIPTION ^

% Generating the Equations
 @author Mazurek/Bartalsky
 This method is generating the optimization-problem equation between two
 coordinates.
% generateEQ.m parameters

 * *Input:*  
 * _M_ ... two neighbouring parallel coordinates of a dataset
 * _m_ ... number of subCoordinates
 * _alpha_c_ ... The share of the two energy terms.
 * _forceM_ ... The computed force.
 * _initFM_ ... The initial force position.
 * *Ouput:*
 * _output_ ... the computed subCoords after the computation

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Generating the Equations
0002 % @author Mazurek/Bartalsky
0003 % This method is generating the optimization-problem equation between two
0004 % coordinates.
0005 %% generateEQ.m parameters
0006 %
0007 % * *Input:*
0008 % * _M_ ... two neighbouring parallel coordinates of a dataset
0009 % * _m_ ... number of subCoordinates
0010 % * _alpha_c_ ... The share of the two energy terms.
0011 % * _forceM_ ... The computed force.
0012 % * _initFM_ ... The initial force position.
0013 % * *Ouput:*
0014 % * _output_ ... the computed subCoords after the computation
0015 
0016 function [ output ] = generateEQ(M, subM, forceM, initFM, alpha_c)
0017 
0018 % Step 1 - Get the descend order of the subCoords in another matrix
0019 % These needs to be done to set the constraints correctly, otherwise the
0020 % order wouldn't be guaranteed. We need the indices of the correct order.
0021 
0022 [subs, indices] = sort(subM,1,'descend');
0023 
0024 % The indices matrix shows us the constraints. In the descending order, the
0025 % first must be higherOrequal than the second, ... . This order has to be
0026 % now interpreted in lp_solve as constraints for each subcoords column,
0027 % independent from the other subcoords columns.
0028 
0029 m = size(subM,2);
0030 n = size(subM,1);
0031 
0032 rh = 0;
0033 f = zeros(m, n);
0034 A = 0;
0035 % This loop iterates through the columns and adds it to the function f.
0036 % Furthermore it prepares the constraint matrix A, which checks the
0037 % boundings of the EQ.
0038 for j=1:m
0039     for i=1:n
0040         % This is the E_Gravitation term:
0041         % f(j,i) and not f(i,j) because the variable names start from
0042         % x1,x2 column by column (and not row by row)
0043         f(j,i) = forceM(i,j)*initFM(i,j);
0044         rh = rh + initFM(i,j)*subM(i,j);
0045         % This part generates the constraint Matrix, which is E_ij;
0046         if(i < n)
0047             temp = zeros(1, n*m);
0048             
0049             temp((j-1)*n + indices(i,j)) = 1;
0050             temp((j-1)*n + indices(i+1,j)) = -1;
0051 
0052             if(A == 0)
0053               A = temp; 
0054             else 
0055               A = [A;temp];
0056             end
0057         end
0058     end
0059 end
0060 
0061 % the constraint for the object function
0062 temp=(-1)*ones(1, n*m);
0063 A = [A;temp];
0064 
0065 %Make one long row. (format)
0066 temp = 0;
0067 for i=1:m
0068     if(i == 1)
0069        temp = f(i,:); 
0070     else
0071         temp = [temp f(i,:)];
0072     end  
0073 end
0074 
0075 B=reshape(subM,numel(subM),1);
0076 C=reshape(forceM,numel(forceM),1);
0077 
0078 % Set the bounds of each variable L and U
0079 Lt=zeros(size(C));
0080 Ut=ones(size(C));
0081 L= B-(abs(C).*(1-alpha_c));
0082 LB=L;
0083 LB(Lt>L)=0;
0084 U= B+(abs(C).*(1-alpha_c));
0085 UB=U;
0086 UB(Ut<U)=1;
0087 
0088 f = temp;
0089 b = zeros(size(A,1),1);
0090 e = ones(size(A,1),1);
0091 b(end)=-rh;
0092 
0093 
0094 % This function creates the optimization problem for lp_solve.
0095 lp = lp_maker(f, A, b, e, LB, UB, [], 0, 1, rh);
0096 % f ... is the function
0097 % A ... is the constraint matrix, which guarantees that the non-intersecting
0098 % sample points do not cross
0099 % b ... is the right side of the constraints (in our case it is always 0)
0100 % e ... is the definition, if it is >, = or <
0101 % 3x [] bounderies (lowerbound, upperbound, integer)
0102 % two last paramters: scale_0 and 1 because of finding the minimum
0103 % rh is the right side of the objective function
0104 
0105 
0106 % lp_solve commands for computing the optimization problem and getting the
0107 % variables.
0108 solvestat = mxlpsolve('solve', lp);
0109 variables = mxlpsolve('get_variables', lp);
0110 constraints = mxlpsolve('get_constraints', lp);
0111 objective = mxlpsolve('get_objective',lp);
0112 
0113 
0114 % Put the results into the previous subCoords shape.
0115 output = reshape(variables,[n,m]);
0116 
0117 % deallocate
0118 mxlpsolve('delete_lp', lp);
0119 
0120 end
0121

Generated on Tue 31-May-2016 19:24:56 by m2html © 2005