Answers.Body: <p>I tried to use this one: 1 / abs(logP - 9) as the fitness function. Also considering denominator is zero the corner case. If abs(logP - 9) = 0, then one can set it as very small number like 0.0000000001.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-20T15:02:09.373Z
Answers.Text: Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Answers.UserDisplayName: Community
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-20T12:33:40.323Z
Answers.LastActivityDate: 2022-09-20T15:21:52.513Z
Answers.LastEditDate: 2022-09-20T15:21:52.513Z
Answers.UserDisplayName: DavidK
Body: <p>I am learning about genetic algorithms (GA), but I encountered a question about the definition of the fitness function used in GA.</p>
  <p>I understand that the fitness function should return a scalar value (e.g. to make sure to return the maximum value for a given individual).</p>
  <p>For example, if one wanted to optimize a small molecule <span class="math-container">$logP$</span> (to ensure that the returned <span class="math-container">$logP$</span> has the maximum values), one can define the fitness value thusly: <span class="math-container">$J(m) = logP$</span>, and then use GA to optimize the <span class="math-container">$logP$</span>.</p>
  <p>But my question is that I want to make sure that the <span class="math-container">$logP$</span> has a value close to 9 (rather than the larger the better), the more closer to 9 the better.</p>
  <p>In this case how can I define the fitness function used in GA?</p>
  <p>Thanks.</p>
  
Tags: <optimization><genetic-algorithms><fitness-functions>
Title: How to define a fitness function to make sure the best fitness value is 'close to 9' in genetic algorithm
UserDisplayName: DavidK
ThreadText: # How to define a fitness function to make sure the best fitness value is 'close to 9' in genetic algorithm
  
  (Asked by: username_0 on 2022-09-17)
  
  I am learning about genetic algorithms (GA), but I encountered a question about the definition of the fitness function used in GA.
  
  I understand that the fitness function should return a scalar value (e.g. to make sure to return the maximum value for a given individual).
  
  For example, if one wanted to optimize a small molecule $logP$ (to ensure that the returned $logP$ has the maximum values), one can define the fitness value thusly: $J(m) = logP$, and then use GA to optimize the $logP$.
  
  But my question is that I want to make sure that the $logP$ has a value close to 9 (rather than the larger the better), the more closer to 9 the better.
  
  In this case how can I define the fitness function used in GA?
  
  Thanks.
  
  **Tags:** optimization, genetic-algorithms, fitness-functions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-09-20. Score: 0 | Accepted answer
  
  I tried to use this one: 1 / abs(logP - 9) as the fitness function. Also considering denominator is zero the corner case. If abs(logP - 9) = 0, then one can set it as very small number like 0.0000000001.
  
  > **Comments:**
  > **username_1**: Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer).  
  
  ---
  
  