<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: HELP - I Got the Wrong Answer for My Optimization!</title>
	<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/</link>
	<description>Loren Shure  works on design of the MATLAB language at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62;. She writes here about once a week on MATLAB programming and related topics. &#60;br&#62;&#60;br&#62;&#60;a href="/images/loren-full.jpg"&#62;&#60;img src="/images/loren.jpg"&#62;&#60;/a&#62;</description>
	<pubDate>Sun, 22 Nov 2009 23:12:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29871</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 18 Nov 2008 12:49:58 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29871</guid>
		<description>Ben-

What you mention is not about the quality of the objective function itself.  In fact, when I run the problem in R2008b, I get a warning before I get my answer:

&lt;pre class='code'&gt;
Warning: Trust-region-reflective method does not currently solve this type of problem,
 using active-set (line search) instead. 
&gt; In fmincon at 437
Optimization terminated: first-order optimality measure less
 than options.TolFun and maximum constraint violation is less
 than options.TolCon.
&lt;/pre&gt;

which hints at the answer (and the problem as posed, perhaps) needing scrutiny. 

--loren</description>
		<content:encoded><![CDATA[<p>Ben-</p>
<p>What you mention is not about the quality of the objective function itself.  In fact, when I run the problem in R2008b, I get a warning before I get my answer:</p>
<pre class='code'>
Warning: Trust-region-reflective method does not currently solve this type of problem,
 using active-set (line search) instead.
> In fmincon at 437
Optimization terminated: first-order optimality measure less
 than options.TolFun and maximum constraint violation is less
 than options.TolCon.
</pre>
<p>which hints at the answer (and the problem as posed, perhaps) needing scrutiny. </p>
<p>&#8211;loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29870</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Tue, 18 Nov 2008 09:17:54 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29870</guid>
		<description>It's worth pointing out that fmincon (R2007b) can get stuck at the initial point even for "nice" functions, like

&#62;&#62;fmincon(@cos,0,[],[],[],[],-1,1)

which returns 0 the local maximum.  Not that we'd do that in practice though :)</description>
		<content:encoded><![CDATA[<p>It&#8217;s worth pointing out that fmincon (R2007b) can get stuck at the initial point even for &#8220;nice&#8221; functions, like</p>
<p>&gt;&gt;fmincon(@cos,0,[],[],[],[],-1,1)</p>
<p>which returns 0 the local maximum.  Not that we&#8217;d do that in practice though :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Kozola</title>
		<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29582</link>
		<dc:creator>Stuart Kozola</dc:creator>
		<pubDate>Mon, 14 Jul 2008 10:47:55 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29582</guid>
		<description>Loren is probably right that the user was reading in a text file.  I've run into a similar problem when reading in input/output files from an external program.  The rounding and truncation that occurs in the file i/o operations can cause the same problem as the strrep function did in this example.  In my case, I used DiffMinChange (fmincon) to keep the solver getting stuck.

-Stu</description>
		<content:encoded><![CDATA[<p>Loren is probably right that the user was reading in a text file.  I&#8217;ve run into a similar problem when reading in input/output files from an external program.  The rounding and truncation that occurs in the file i/o operations can cause the same problem as the strrep function did in this example.  In my case, I used DiffMinChange (fmincon) to keep the solver getting stuck.</p>
<p>-Stu</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29581</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 10 Jul 2008 20:34:35 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29581</guid>
		<description>Brian-

I wonder if the user had the numbers in strings from reading in a text file in some way.  In any case, their "solution" certainly led to difficulties on multiple levels.

--Loren</description>
		<content:encoded><![CDATA[<p>Brian-</p>
<p>I wonder if the user had the numbers in strings from reading in a text file in some way.  In any case, their &#8220;solution&#8221; certainly led to difficulties on multiple levels.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29579</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Wed, 09 Jul 2008 16:21:24 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29579</guid>
		<description>I am in awe of the original code. I can't understand how someone ends up thinking that's the way to go. It's totally missing a basic idea of Matlab (and programming in general): you can assign numbers to variables.</description>
		<content:encoded><![CDATA[<p>I am in awe of the original code. I can&#8217;t understand how someone ends up thinking that&#8217;s the way to go. It&#8217;s totally missing a basic idea of Matlab (and programming in general): you can assign numbers to variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan K</title>
		<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29576</link>
		<dc:creator>Dan K</dc:creator>
		<pubDate>Wed, 09 Jul 2008 13:14:17 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29576</guid>
		<description>Loren,
Thank you once again for a post on a topic of great interest.  Two thoughts:  First, why on earth would somebody want to use the code you described as the original.  Won't using the string replacements and eval vastly increase processing time?  Second, in answer to your question,the problem which I had a great deal of difficulty with was a case where I had a huge number of local minima.  I was trying to fit a noisy sinusoid, with unknown frequency, amplitudes, phase, and offset.  Of course for any test frequency you get a local minima when you adjust the phase.  I finally ended up having to drop the direct approach, and set up a genetic optimizer with a godawful mutation function (which occasionally would calculate the frequency change to effect exactly 2 pi equivalent phase jump).  
Dan</description>
		<content:encoded><![CDATA[<p>Loren,<br />
Thank you once again for a post on a topic of great interest.  Two thoughts:  First, why on earth would somebody want to use the code you described as the original.  Won&#8217;t using the string replacements and eval vastly increase processing time?  Second, in answer to your question,the problem which I had a great deal of difficulty with was a case where I had a huge number of local minima.  I was trying to fit a noisy sinusoid, with unknown frequency, amplitudes, phase, and offset.  Of course for any test frequency you get a local minima when you adjust the phase.  I finally ended up having to drop the direct approach, and set up a genetic optimizer with a godawful mutation function (which occasionally would calculate the frequency change to effect exactly 2 pi equivalent phase jump).<br />
Dan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29573</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 08 Jul 2008 20:14:32 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29573</guid>
		<description>Sure, Arthur, sorry for the oversight!  Here it is:

&lt;pre class="code"&gt;
function f = myOptFunFixed(X)
f = X(1,:).^2+X(2,:).^2;
&lt;/pre&gt;

--Loren</description>
		<content:encoded><![CDATA[<p>Sure, Arthur, sorry for the oversight!  Here it is:</p>
<pre class="code">
function f = myOptFunFixed(X)
f = X(1,:).^2+X(2,:).^2;
</pre>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arthur</title>
		<link>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29572</link>
		<dc:creator>Arthur</dc:creator>
		<pubDate>Tue, 08 Jul 2008 20:11:10 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/07/08/help-i-got-the-wrong-answer-for-my-optimization/#comment-29572</guid>
		<description>Can you post the code for myOptFunFixed, so we can see how you decided to rewrite the function?

I've had similar problems: I was trying to minimize a complex function that was just a little noisy. My function was noisy because it required solving a nonlinear equation and approximating an integral. Solving them to many decimal places was very time-consuming, but relaxing the solvers was causing problems with the optimization.

That's when I discovered DiffMinChange, which let me ensure that the finite differencing was larger than the magnitude of the noise.</description>
		<content:encoded><![CDATA[<p>Can you post the code for myOptFunFixed, so we can see how you decided to rewrite the function?</p>
<p>I&#8217;ve had similar problems: I was trying to minimize a complex function that was just a little noisy. My function was noisy because it required solving a nonlinear equation and approximating an integral. Solving them to many decimal places was very time-consuming, but relaxing the solvers was causing problems with the optimization.</p>
<p>That&#8217;s when I discovered DiffMinChange, which let me ensure that the finite differencing was larger than the magnitude of the noise.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
