120.

 C++ Neural Networks and Fuzzy Logic by Valluru B. Rao M&T Books, IDG Books Worldwide, Inc. ISBN: 1558515526   Pub Date: 06/01/95

Output from a Sample Program Run

The program, as mentioned, is created for the Kohonen approach to the traveling salesperson problem for five cities. There is no user input from the keyboard. All parameter values are given to the program with appropriate statements in the function main. A scale factor of 0.05 is given to apply to the gain parameter, which is given as 1. Initially, the distance of each neuron weight vector from an input vector is set at 1000, to facilitate finding the closest for the first time. The cities with coordinates (7,3), (4,6), (14,13), (0,12), (5,10) are specified for input vectors.

The tour found is not the one in natural order, namely 0 → 1 → 2 → 3 → 4 → 0, with a distance of 43.16. The tour found has the order 0 → 3 → 1 → 4 → 2 → 0, which covers a distance of 44.43, which is slightly higher, as shown in Figure 15.2. The best tour, 0 → 2 → 4 → 3 → 1 → 0 has a total distance of 38.54.

Figure 15.2  City placement and tour found for TSP.

Table 15.2 gives for the five-city example, the 12 (5!/10) distinct tour distances and corresponding representative tours. These are not generated by the program, but by enumeration and calculation by hand. This table is provided here for you to see the different solutions for this five-city example of the traveling salesperson problem.

Table 15.2 Distances and Representative Tours for Five-City Example

Distance Tour Comment
49.05 0-3-2-1-4-0 worst case
47.59 0-3-1-2-4-0
45.33 0-2-1-4-3-0
44.86 0-2-3-1-4-0
44.43 0-3-1-4-2-0 tour given by the program
44.30 0-2-1-3-4-0
43.29 0-1-4-2-3-0
43.16 0-1-2-3-4-0
42.73 0-1-2-4-3-0
42.26 0-1-3-2-4-0
40.00 0-1-4-3-2-0
38.54 0-2-4-3-1-0 optimal tour

There are 12 different distances you can get for tours with these cities by hand calculation, and four of these are higher and seven are lower than the one you find from this program. The worst case tour (0 [rarr] 3 [rarr] 2 [rarr] 1 [rarr] 4 [rarr] 0) gives a distance of 49.05, and the best, as you saw above, 38.54. The solution from the program is at about the middle of the best and worst, in terms of total distance traveled.

The output of the program being all computer generated is given below as follows:

` d: 0   1   2   3   4 d: 1   0   1   2   3 d: 2   1   0   1   2 d: 3   2   1   0   1 d: 4   3   2   1   0 input : 7   3 input : 4   6 input : 14  13 input : 0   12 input : 5   10 weight: 1.595769   2.393654 weight: 3.289125e-09   4.933688e-09 weight: 2.880126e-35   4.320189e-35 weight: 1.071429e-78   1.607143e-78 weight: 1.693308e-139  2.539961e-139 weight: 1.595769   2.393654 weight: 5.585192   5.18625 weight: 2.880126e-35   4.320189e-35 weight: 1.071429e-78   1.607143e-78 weight: 1.693308e-139  2.539961e-139 weight: 1.595769   2.393654 weight: 5.585192   5.18625 weight: 5.585192   5.18625 weight: 1.071429e-78   1.607143e-78 weight: 1.693308e-139  2.539961e-139 weight: 1.595769   2.393654 weight: 5.585192   5.18625 weight: 5.585192   5.18625 weight: 5.585192   5.18625 weight: 1.693308e-139   2.539961e-139 weight: 1.595769   2.393654 weight: 5.585192   5.18625 weight: 5.585192   5.18625 weight: 5.585192   5.18625 weight: 5.585192   5.18625 tour : 0 –> 3–> 1 –> 4 –> 2–> 0 (7, 3) –> (0, 12) –> (4, 6) –> (5, 10) –> (14, 13) –> (7, 3) `

Optimizing a Stock Portfolio

Development of a neural network approach to a stock selection process in securities trading is similar to the application of neural networks to nonlinear optimization problems. The seminal work of Markowitz in making a mathematical formulation of an objective function in the context of portfolio selection forms a basis for such a development. There is risk to be minimized or put a cap on, and there are profits to be maximized. Investment capital is a limited resource naturally.

The objective function is formulated in such a way that the optimal portfolio minimizes the objective function. There would be a term in the objective function involving the product of each pair of stock prices. The covariance of that pair of prices is also used in the objective function. A product renders the objective function a quadratic. There would of course be some linear terms as well, and they represent the individual stock prices with the stock’s average return as coefficient in each such term. You already get the idea that this optimization problem falls into the category of quadratic programming problems, which result in real number values for the variables in the optimal solution. Some other terms would also be included in the objective function to make sure that the constraints of the problem are satisfied.

A practical consideration is that a real number value for the amount of a stock may be unrealistic, as fractional numbers of stocks may not be purchased. It makes more sense to ask that the variables be taking 0 or 1 only. The implication then is that either you buy a stock, in which case you include it in the portfolio, or you do not buy at all. This is what is usually called a zero-one programming problem. You also identify it as a combinatorial problem.

You already saw a combinatorial optimization problem in the traveling salesperson problem. The constraints were incorporated into special terms in the objective function, so that the only function to be computed is the objective function.

Deeming the objective function as giving the energy of a network in a given state, the simulated annealing paradigm and the Hopfield network can be used to solve the problem. You then have a neural network in which each neuron represents a stock, and the size of the layer is determined by the number of stocks in the pool from which you want to build your stock portfolio. The paradigm suggested here strives to minimize the energy of the machine. The objective function needs therefore to be stated for minimization to get the best portfolio possible.