<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240570</link>
    <title>MATLAB Central Newsreader - GA: extra parameters for fitness function</title>
    <description>Feed for thread: GA: extra parameters for fitness function</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 06 Dec 2008 18:13:32 -0500</pubDate>
      <title>GA: extra parameters for fitness function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240570#615453</link>
      <author>SabbeRubbish</author>
      <description>Hi,&lt;br&gt;
I'm new to the forums, I hope you can help me.&lt;br&gt;
Is there any way to give ga (or gatool) an extra parameter/argument other than the variables to be optimized?&lt;br&gt;
&lt;br&gt;
For example, I have a fitness function that calculates the contrast of an image.  I want to maximize the contrast of a grayscale image based on the color image, using the R, G and B factors as multipliers for the red, green and blue subimages respectively.&lt;br&gt;
&lt;br&gt;
It works fine if I hardcode the image file into the fitness function, but I'd rather be able to parametrize like e.g.:&lt;br&gt;
&lt;br&gt;
ga(@optimizeGrayscale(3, [], [], ones(3,3), [1 1 1], [0 0 0], [1 1 1], 'firstParam', 'fileName')&lt;br&gt;
&lt;br&gt;
Where [] is A and b, ones(3,3) is Aeq, [1 1 1] is beq, [0 0 0] is LB and [1 1 1] is UB.&lt;br&gt;
&lt;br&gt;
Is it possible to give an extra parameters when referencing functions like @function?&lt;br&gt;
&lt;br&gt;
Thanks for any help.&lt;br&gt;
&lt;br&gt;
SabbeRubbish</description>
    </item>
    <item>
      <pubDate>Sun, 07 Dec 2008 15:07:29 -0500</pubDate>
      <title>Re: GA: extra parameters for fitness function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240570#615528</link>
      <author>SabbeRubbish</author>
      <description>I've found a solution to this problem, albeit not a very pretty one: using global variables (I know, it's bad practice but in this particular case I couldn't get around it, on such short notice).&lt;br&gt;
&lt;br&gt;
So I just declare my fileName or colorImage as global:&lt;br&gt;
global colorImage;&lt;br&gt;
in both files (calling function and called fitness function).</description>
    </item>
    <item>
      <pubDate>Sun, 07 Dec 2008 21:34:02 -0500</pubDate>
      <title>Re: GA: extra parameters for fitness function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240570#615561</link>
      <author>Dave Brackett</author>
      <description>SabbeRubbish &amp;lt;SabbeRubbish@gmail.com&amp;gt; wrote in message &amp;lt;19810651.1228662479564.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I've found a solution to this problem, albeit not a very pretty one: using global variables (I know, it's bad practice but in this particular case I couldn't get around it, on such short notice).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So I just declare my fileName or colorImage as global:&lt;br&gt;
&amp;gt; global colorImage;&lt;br&gt;
&amp;gt; in both files (calling function and called fitness function).&lt;br&gt;
&lt;br&gt;
Try to avoid using global variables where possible as they can cause problems depending on what your code does. To pass variables to a GA the fitness function must be specified as shown in the example below:&lt;br&gt;
&lt;br&gt;
FitnessFcn=@(x)m_file_fitness_calc(x,other variables...)&lt;br&gt;
&lt;br&gt;
then the ga is called using as: ga(FitnessFcn,other options...) etc.&lt;br&gt;
&lt;br&gt;
hope that helps.</description>
    </item>
    <item>
      <pubDate>Mon, 08 Dec 2008 02:47:02 -0500</pubDate>
      <title>Re: GA: extra parameters for fitness function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240570#615587</link>
      <author>Alan Weiss</author>
      <description>SabbeRubbish wrote:&lt;br&gt;
&amp;gt; I've found a solution to this problem, albeit not a very pretty one: using global variables (I know, it's bad practice but in this particular case I couldn't get around it, on such short notice).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So I just declare my fileName or colorImage as global:&lt;br&gt;
&amp;gt; global colorImage;&lt;br&gt;
&amp;gt; in both files (calling function and called fitness function).&lt;br&gt;
&lt;br&gt;
Hi, I'm really sorry you are having this problem. I tried to make it &lt;br&gt;
much more clear how to do this in the function reference page for ga. &lt;br&gt;
There is a big note there that points out a section in the Optimization &lt;br&gt;
Toolbox(TM) User's Guide on how to use anonymous functions or nested &lt;br&gt;
functions to do this without using global variables:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Can you please tell me how I might make this information more visible to &lt;br&gt;
customers? It is a common problem, and I struggle with informing people.&lt;br&gt;
&lt;br&gt;
Alan Weiss&lt;br&gt;
MATLAB mathematical toolbox documentation</description>
    </item>
    <item>
      <pubDate>Mon, 08 Dec 2008 16:25:32 -0500</pubDate>
      <title>Re: GA: extra parameters for fitness function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240570#615706</link>
      <author>SabbeRubbish</author>
      <description>Maybe state what davebracket replied to my post.&lt;br&gt;
It helps to see an extra example to show how you can use it in ga.  Global variables did do the trick and it's not a very critical application.&lt;br&gt;
&lt;br&gt;
Thanks for your concerns :)&lt;br&gt;
&lt;br&gt;
SabbeRubbish</description>
    </item>
  </channel>
</rss>

