Wednesday, March 30, 2016

sas nonlinear programming code The objective function is the total free energy of the mixture.

http://mathworld.wolfram.com/BivariateNormalDistribution.html


http://blogs.sas.com/content/iml/2013/09/18/compute-a-contour-level-curve-in-sas.html

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/viewer.htm#nonlinearoptexpls_sect15.htm

Example 14.1 Chemical Equilibrium :: SAS/IML(R) 12.3 ...

support.sas.com/documentation/cdl/en/.../viewer.htm#...
SAS Institute
number of moles for compound $j$ , $j=1,\ldots ,n$. $s$. total number of moles in the mixture, $s=\sum _{i=1}^ n x_ j$. $a_{ij}$. number of atoms of element $i$ ...



The problem is to determine the parameters x_j that minimize the objective function f(x) subject to the nonnegativity and linear balance constraints.


Moles of Compounds
Home Up Mole Concept Mole-Gram Calculations Moles of Compounds Moles of Molecular Elements Additional Calculations


Moles of Compounds

The concept of a mole can be applied to compounds as well as elements. A mole of a compound is what you have when you weigh out, in grams, the formula weight of that compound. (Use the molecular weight if the compound is a molecular material.) For example, the formula weight for HF is 20.0. That means that one mole of HF weighs 20.0 grams, and you can use that relationship to convert back and forth between grams and moles.
For example, if you needed to change 15.0 g of HF to moles, you would simply multiply by the conversion factor that changes from gHF to moles HF. The relationship we just figured out is that 1 mole of HF weighs 20.0 g. Carrying out the calculations, we get 0.750 moles of HF.15.0 g HF1 mole HF
    20.0 g HF
= 0.750 mole HF
To emphasize that this is the weight of one mole of that chemical, some chemists call it the molar formula weight or the mole weight or even the molar mass.


E-mail instructor: Sue Eggling
Clackamas Community College
©1998, 2002 Clackamas Community College, Hal Bender


What is the difference between linear and non-linear optimization?

What are the algorithms used for the different class of problems?
2 Answers


Jing Conan Wang
Jing Conan WangPh.D of Boston University Optimization, Machine Learning, Network Security
3.7k Views
In linear optimization, the boundary of feasible range is hyperplane and cost function is linear, too. If any of the constraints or the obj function is non-linear, the problem becomes non-linear optimization. 

In optimization, there is a big difference between convex optimization and non-convex optimization, however, there is no intrinsic difference  between linear programming and nonlinear programming.
Linear programming was studied first because it is easier to think in the pre-computer age. Simplex was popular mainly because it is easy to write down in paper (it is a tabular-based method). Note that complexity of Simplex is exponential.

Most of the polynomial-time algorithms (like interior point methods) work for both linear and non-linear programming.



Rasmus Bonnevie
Rasmus Bonnevie
2.7k Views • Upvoted by Justin Risingdata scientist
I am no expert, but here's some info:
In linear optimization the cost function is a hyperplane with some slope. Some features have a positive weight, and if you increase those you will always increase the objective function. On the other hand, some features have negative weight and will always reduce it. So it's quite easy to optimize. The interesting part is when you throw in constraints. If you have linear inequality constraints then you can move around the border trying to find a way downhill again, which is what the most prominent algorithm, the simplex algorithm, tries to do. Linear problems are very typical of planning problems and Operations Research and often involve an enormous number of features, leading to programs such as CPLEX branding themselves on being able to solve equations with billions of variables.

Non-linear optimization deals with, you guessed it, non-linear functions. Usually you distinguish between convex and non-convex optimization with the former being less ill-specified than the latter as it is unimodal. Typical methods of solving these problems are first-order methods such as gradient and conjugate gradient descent, and second order methods (and approximations thereof) such as Newton's method and Levenberg-Marquardt. One of the most prominent algorithms is the BFGS algorithm.

There are a ton of variations on the above, but these are amongst the typical topics covered in an optimization textbook, in my experience. Check out Nocedal and Wright's "Numerical Optimization" for a good if technical textbook.




Example 11.1: Chemical Equilibrium

The following example is used in many test libraries for nonlinear programming. It appeared originally in Bracken and McCormick (1968).
The problem is to determine the composition of a mixture of various chemicals that satisfy the mixture's chemical equilibrium state. The second law of thermodynamics implies that at a constant temperature and pressure, a mixture of chemicals satisfies its chemical equilibrium state when the free energy of the mixture is reduced to a minimum. Therefore, the composition of the chemicals satisfying its chemical equilibrium state can be found by minimizing the free energy of the mixture.
The following notation is used in this problem: 
mnumber of chemical elements in the mixture
nnumber of compounds in the mixture
x_jnumber of moles for compound jj=1, ... ,n
stotal number of moles in the mixture, s=\sum_{i=1}^n x_j
a_{ij}number of atoms of element i in a molecule of compound j
b_iatomic weight of element i in the mixture i=1, ... ,n
The constraints for the mixture are as follows. Each of the compounds must have a nonnegative number of moles.
x_j \geq 0 ,  j=1, ... ,n
There is a mass balance relationship for each element. Each relation is given by a linear equality constraint.
\sum_{j=1}^n a_{ij} x_j = b_i ,  i=1, ... ,m
The objective function is the total free energy of the mixture.
f(x) = \sum_{j=1}^n x_j [c_j +    \ln ( {x_j \over s} ) ]
where
c_j = ( {f^0 \over rt} )_j + \ln(p)
and ( f^0/rt )_j is the model standard free energy function for the jth compound. The value of ( f^0/rt )_j is found in existing tables. p is the total pressure in atmospheres.
The problem is to determine the parameters x_j that minimize the objective function f(x) subject to the nonnegativity and linear balance constraints. To illustrate this, consider the following situation. Determine the equilibrium composition of compound \frac{1}2 n_2 h_4 + \frac{1}2 o_2 at temperature t = 3500^{\circ} k and pressure p = 750  {psi}. The following table gives a summary of the information necessary to solve the problem.
 a_{ij}
 i=1i=2i=3
jCompound(f^0/rt)_jc_jHNO
1h -10.021-6.0891  
2h_2-21.096-17.1642  
3h_2o-37.986-34.0542 1
4n-9.846-5.914 1 
5n_2-28.653-24.721 2 
6nh-18.918-14.98611 
7no-28.032-24.100 11
8o-14.640-10.708  1
9o_2-30.594-26.662  2
10oh-26.111-22.1791 1
The following statements solve the minimization problem:
  
    proc iml; 
       c = { -6.089 -17.164 -34.054  -5.914 -24.721 
             -14.986 -24.100 -10.708 -26.662 -22.179 }; 
       start F_BRACK(x) global(c); 
          s = x[+]; 
          f = sum(x # (c + log(x / s))); 
          return(f); 
       finish F_BRACK; 
  
       con = { .  .  .  .  .  .  .  .  .  .    .   .  , 
               .  .  .  .  .  .  .  .  .  .    .   .  , 
               1. 2. 2. .  .  1. .  .  .  1.   0.  2. , 
               .  .  .  1. 2. 1. 1. .  .  .    0.  1. , 
               .  .  1. .  .  .  1. 1. 2. 1.   0.  1. }; 
       con[1,1:10] = 1.e-6; 
  
       x0 = j(1,10, .1); 
       optn = {0 3}; 
  
       title 'NLPTR subroutine: No Derivatives'; 
       call nlptr(xres,rc,"F_BRACK",x0,optn,con);
 

The F_BRACK module specifies the objective function, f(x). The matrix CON specifies the constraints. The first row gives the lower bound for each parameter, and to prevent the evaluation of the \log(x) function for values of x that are too small, the lower bounds are set here to 1E-6. The following three rows contain the three linear equality constraints.
The starting point, which must be given to specify the number of parameters, is represented by X0. The first element of the OPTN vector specifies a minimization problem, and the second element specifies the amount of printed output.
The CALL NLPTR statement runs trust-region minimization. In this case, since no analytic derivatives are specified, the F_BRACK module is used to generate finite-difference approximations for the gradient vector and Hessian matrix.
The output is shown in the following figures. The iteration history does not show any problems.
Optimization Start
Active Constraints3Objective Function-45.05516448
Max Abs Gradient Element4.4710303342Radius1
Iteration RestartsFunction
Calls
Active
Constraints
 Objective
Function
Objective
Function
Change
Max Abs
Gradient
Element
LambdaTrust
Region
Radius
1 023'-47.334132.27904.36132.4561.000
2 033'-47.700510.36647.00440.9080.418
3 043 -47.731170.03075.305100.359
4 053 -47.734260.003103.701500.118
5 063 -47.739820.005552.305400.0169
6 073 -47.748460.008641.302990.1840.00476
7 093 -47.757960.009500.507300.0134
8 0103 -47.760940.002970.098800.0124
9 0113 -47.761090.0001550.0044700.0111
10 0123 -47.761093.385E-70.00001100.00332
Optimization Results
Iterations10Function Calls13
Hessian Calls11Active Constraints3
Objective Function-47.76109086Max Abs Gradient Element7.3901293E-6
Lambda0Actual Over Pred Change0
Radius0.0033214552  


The output lists the optimal parameters with the gradient.
Optimization Results
Parameter Estimates
NParameterEstimateGradient
Objective
Function
1X10.040668-9.785055
2X20.147730-19.570111
3X30.783154-34.792170
4X40.001414-12.968920
5X50.485247-25.937841
6X60.000693-22.753976
7X70.027399-28.190992
8X80.017947-15.222060
9X90.037314-30.444119
10X100.096871-25.007115
Value of Objective Function = -47.76109086


The three equality constraints are satisfied at the solution.
Linear Constraints Evaluated at Solution
1ACT-3.053E-16=-2.0000+1.0000*X1+2.0000*X2+2.0000*X3+1.0000*X6+1.0000*X10
2ACT-1.735E-17=-1.0000+1.0000*X4+2.0000*X5+1.0000*X6+1.0000*X7    
3ACT-1.527E-16=-1.0000+1.0000*X3+1.0000*X7+1.0000*X8+2.0000*X9+1.0000*X10


The Lagrange multipliers and the projected gradient are also printed. The elements of the projected gradient must be small to satisfy a first-order optimality condition.
First Order Lagrange Multipliers
Active ConstraintLagrange
Multiplier
Linear EC[1]-9.785055
Linear EC[2]-12.968922
Linear EC[3]-15.222061
Projected Gradient
Free
Dimension
Projected
Gradient
10.000000328
2-9.703359E-8
33.2183113E-8
4-0.000007390
5-0.000005172
6-0.000005669
7-0.000000937



No comments:

Post a Comment