# Differential Evolution Step Sequence

**URL:** <https://community.wolfram.com/t/differential-evolution-step-sequence/1727>\
**Category:** Questions\
**Tags:** mathematica, tuning-and-debugging\
**Created:** [March 16, 2014, 6:08am UTC](https://community.wolfram.com/t/differential-evolution-step-sequence/1727 "2014-03-16T06:08:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![priyanfernando](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@priyanfernando](https://community.wolfram.com/u/priyanfernando)\
**Post date:** [March 16, 2014, 6:08am UTC](https://community.wolfram.com/t/differential-evolution-step-sequence/1727/1 "2014-03-16T06:08:10Z")

</div>

Hi!

I am try to run a portfolio optimization using the Differential Evolution method. The optimization runs, but there seems to be some problem in the output, when I store the steps used. My sample code is:

```auto
SeedRandom[1234]

numShares= 5; (*number of shares *)
allData = RandomReal[{-0.01,0.01},{10,numShares}]; (* create random share returns matrix *)

returnsVector =Mean[allData]; (* vector of average share returns *)
varianceMatrix = Covariance[allData]; (*covariance matrix *)
variables=Table[Subscript[x, i],{i,1,numShares}]; (*list of variables *)

Opt = NMinimize[{variables . varianceMatrix . variables, Dot[variables, returnsVector] == Mean[returnsVector], (Plus @@ variables) == 1,And @@ (LessEqual[0,#,1]& /@ variables)},variables] (* default optimization *)

Clear[deSteps];
deSteps= Reap[NMinimize[{variables . varianceMatrix . variables, Dot[variables, returnsVector] == Mean[returnsVector], (Plus @@ variables) == 1,And @@ (LessEqual[0,#,1]& /@ variables)},variables, Method->"DifferentialEvolution", StepMonitor :>Sow[variables]]] 

```

When I examine deSteps, I see something like:

 ![Capture.JPG](https://global.discourse-cdn.com/wolfram/original/3X/4/6/46756f5235d9d35a6adbd551cec3a0ca18036dd5.jpeg)  
I am wondering why the values for x2, x3 are not displayed? (See second line and after, of the Output). I want to see these values, so I can examine the step sequence used in the Differential Evolution optimization process. Thanks for any help!

Priyan.

---

<div class="post-metadata">

**Author:** ![brettc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/brettc/32/39223_2.png) [@brettc](https://community.wolfram.com/u/brettc)\
**Post date:** [March 17, 2014, 2:37pm UTC](https://community.wolfram.com/t/differential-evolution-step-sequence/1727/2 "2014-03-17T14:37:16Z")

</div>

x2 and x3 were eliminated using the linear equality constraints, so they don’t show up in the StepMonitor.

---

<div class="post-metadata">

**Author:** ![priyanfernando](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@priyanfernando](https://community.wolfram.com/u/priyanfernando)\
**Post date:** [March 17, 2014, 4:15pm UTC](https://community.wolfram.com/t/differential-evolution-step-sequence/1727/3 "2014-03-17T16:15:49Z")

</div>

That makes perfect sense! Thanks Brett!
