Answers.Body: <blockquote>
  <p>Is it possible to train a neural network to find the global maximum value of unknown functions like f(x,y)=z with reinforcement learning?</p>
  </blockquote>
  <p>In short, no, and this is technically an impossible task for any known optimisation technique.</p>
  <p>The main objection that you already note in the question is true:</p>
  <blockquote>
  <p>I do not really know if this will work because the maximum value could be very far away from the starting point of the agent. Image if the agent starts at something like f(2,5) and the global maximum is located at f(9328193,32929549). Is something like this even possible with reinforcement learning and a neural network? There are litteraly infinite random functions that can generate terrain.</p>
  </blockquote>
  <p>It's also worth noting that many functions don't have global maximums. E.g. <span class="math-container">$z = x + y$</span> has no maximum value for <span class="math-container">$z$</span>. Although very common, we can assume that your search is somehow constrained only to functions that do have finite global maximums, and the problem you raise about difficulty of the search is still an issue.</p>
  <p>In addition, your reward scheme pre-supposes that either the agent or the environment can reliably detect that the input parameters represent a global maximimum, in order to terminate the search. This is possible to construct as a toy problem when you design a test or training environment, and <em>already</em> know the maximising input parameters, but there is no corresponding real environment or real way to detect global maximum function points in general for arbitrary functions sampled through experience only (so called &quot;black box&quot; functions).</p>
  <p>In practice, there are lots of computing methods to search for maximising input parameters to functions of interest in different problem domains. Which approaches work best depends critically on the nature of the functions. You could start by looking at <a href="https://en.wikipedia.org/wiki/Global_optimization" rel="nofollow noreferrer">broad categories of global optimisation approaches</a>.</p>
  <p>Completely arbitrary functions are impossible to solve in this way because there could simply be an arbitrary spike at any co-ordinate, and task becomes an infinitely long search. So it is not possible to construct a general purpose solve-all-maximising-problems AI method.</p>
  <p>However, most real world problems that you may wish to solve are more tractable. They usually are constrained in some way, e.g. to a finite search space, and/or conforming to model some real system. Such problems tend not to have semi-random spikes that cause global minimums or maximums at unpredictable parameters, and also often have function spaces that can be characterised and allowed for when considering search strategies.</p>
  <p>Once the function space is constrained by some kind of model of the problem, there are often one or more techniques that can be applied for effective - or at least efficient - search. Also, often an approximate maximum (or minimum) is acceptable, especially if it can be shown to be within some reasonable bound of a best case global theoretical maximum.</p>
  <p>Would a reinforcement learning algorithm as outlined in the question be useful in a more constrained problem space? Perhaps, if anything can be learned by the agent about <em>how</em> to search because there is some common theme for searching for maximums for the kind of problem you are interested in. However, in general, Reinforcement Learning methods are designed for learning through trial and error, and they are not designed to be efficient search methods for solving optimisation problems. So there will often be a better way, depending on the problem space.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-10T10:43:42.830Z
Answers.Text: _"In short, no, and this is technically an impossible task for any known optimisation technique."_... well technically yes, it can, the actual point is "can it do it in an polynomial amount of time"?  
  There are optimization algorithms that can give you the global max, just think about an extensive grid search... the problem is that they require an exponential amount of time/resources.  
  About the rest, I agree with you
Answers.UserDisplayName: Alberto
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-10T12:38:36.283Z
Answers.Text: @Alberto This is not about polynomial time or search efficiency, just that the general case is immediately infinite, there's no N to consider scaling issues by. If you were talking about a system that was bound in some way, eg a finite grid, then search efficiency does come into play, and the problem tractable in theory. The OP doesn't specify any such bounds, and implies there are none with their example
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-18T07:53:55.153Z
Answers.Text: @NeilSlater Thank you for helping me out! Your answer is very useful. :)
Answers.UserDisplayName: Bubble
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-09T15:46:47.240Z
Answers.LastActivityDate: 2023-09-10T14:21:36.533Z
Answers.LastEditDate: 2023-09-10T14:21:36.533Z
Answers.UserDisplayName: Neil Slater
Body: <p>is it possible to train a neural network to find the global maximum value of <strong>unknown</strong> functions like f(x,y)=z with reinforcement learning?</p>
  <p>Up until now I had only had experience with simple environments (for example: <a href="https://www.gymlibrary.dev/environments/toy_text/" rel="nofollow noreferrer">gym library</a>).</p>
  <p>I thought about an agent that is like a hiker who walks on the terrain. I mean two-dimensional functions output different heights (z) which you could see as a terrain.</p>
  <p>My thoughts so far for the agent:</p>
  <p>The agent always starts at a random location (random x,y values). When the agent reaches the global maximum value the environment (terrain) should reset. This means a new unknown random functions will generate the terrain (z height map).</p>
  <p><strong>Actions that the agent can perform:</strong></p>
  <ul>
  <li>move left (input values: x=x-1 , y=y)</li>
  <li>move right (input values: x=x+1 , y=y)</li>
  <li>move up (input values: x=x , y=y+1)</li>
  <li>move down (input values: x=x , y=y-1)</li>
  </ul>
  <p><strong>Rewards for the agent:</strong></p>
  <ul>
  <li><p>-1 per step unless other rewards are triggered</p>
  </li>
  <li><p>+10 if the global maximum value was found</p>
  </li>
  </ul>
  <p>I do not really know if this will work because the maximum value could be very far away from the starting point of the agent. Image if the agent starts at something like f(2,5) and the global maximum is located at f(9328193,32929549). Is something like this even possible with reinforcement learning and a neural network? There are litteraly infinite random functions that can generate terrain.</p>
  
Tags: <neural-networks><reinforcement-learning><machine-learning><q-learning>
Title: Find maximum value of unknown functions f(x,y)=z using reinforcement learning & neural network
UserDisplayName: Bubble
ThreadText: # Find maximum value of unknown functions f(x,y)=z using reinforcement learning & neural network
  
  (Asked by: username_0 on 2023-09-08)
  
  is it possible to train a neural network to find the global maximum value of **unknown** functions like f(x,y)=z with reinforcement learning?
  
  Up until now I had only had experience with simple environments (for example: [gym library](https://www.gymlibrary.dev/environments/toy_text/)).
  
  I thought about an agent that is like a hiker who walks on the terrain. I mean two-dimensional functions output different heights (z) which you could see as a terrain.
  
  My thoughts so far for the agent:
  
  The agent always starts at a random location (random x,y values). When the agent reaches the global maximum value the environment (terrain) should reset. This means a new unknown random functions will generate the terrain (z height map).
  
  **Actions that the agent can perform:**
  
  * move left (input values: x=x-1 , y=y)
  * move right (input values: x=x+1 , y=y)
  * move up (input values: x=x , y=y+1)
  * move down (input values: x=x , y=y-1)
  
  **Rewards for the agent:**
  
  * -1 per step unless other rewards are triggered
  * +10 if the global maximum value was found
  
  I do not really know if this will work because the maximum value could be very far away from the starting point of the agent. Image if the agent starts at something like f(2,5) and the global maximum is located at f(9328193,32929549). Is something like this even possible with reinforcement learning and a neural network? There are litteraly infinite random functions that can generate terrain.
  
  **Tags:** neural-networks, reinforcement-learning, machine-learning, q-learning
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-09-09. Score: 2 | Accepted answer
  
  > Is it possible to train a neural network to find the global maximum value of unknown functions like f(x,y)=z with reinforcement learning?
  
  In short, no, and this is technically an impossible task for any known optimisation technique.
  
  The main objection that you already note in the question is true:
  
  > I do not really know if this will work because the maximum value could be very far away from the starting point of the agent. Image if the agent starts at something like f(2,5) and the global maximum is located at f(9328193,32929549). Is something like this even possible with reinforcement learning and a neural network? There are litteraly infinite random functions that can generate terrain.
  
  It's also worth noting that many functions don't have global maximums. E.g. $z = x + y$ has no maximum value for $z$. Although very common, we can assume that your search is somehow constrained only to functions that do have finite global maximums, and the problem you raise about difficulty of the search is still an issue.
  
  In addition, your reward scheme pre-supposes that either the agent or the environment can reliably detect that the input parameters represent a global maximimum, in order to terminate the search. This is possible to construct as a toy problem when you design a test or training environment, and *already* know the maximising input parameters, but there is no corresponding real environment or real way to detect global maximum function points in general for arbitrary functions sampled through experience only (so called "black box" functions).
  
  In practice, there are lots of computing methods to search for maximising input parameters to functions of interest in different problem domains. Which approaches work best depends critically on the nature of the functions. You could start by looking at [broad categories of global optimisation approaches](https://en.wikipedia.org/wiki/Global_optimization).
  
  Completely arbitrary functions are impossible to solve in this way because there could simply be an arbitrary spike at any co-ordinate, and task becomes an infinitely long search. So it is not possible to construct a general purpose solve-all-maximising-problems AI method.
  
  However, most real world problems that you may wish to solve are more tractable. They usually are constrained in some way, e.g. to a finite search space, and/or conforming to model some real system. Such problems tend not to have semi-random spikes that cause global minimums or maximums at unpredictable parameters, and also often have function spaces that can be characterised and allowed for when considering search strategies.
  
  Once the function space is constrained by some kind of model of the problem, there are often one or more techniques that can be applied for effective - or at least efficient - search. Also, often an approximate maximum (or minimum) is acceptable, especially if it can be shown to be within some reasonable bound of a best case global theoretical maximum.
  
  Would a reinforcement learning algorithm as outlined in the question be useful in a more constrained problem space? Perhaps, if anything can be learned by the agent about *how* to search because there is some common theme for searching for maximums for the kind of problem you are interested in. However, in general, Reinforcement Learning methods are designed for learning through trial and error, and they are not designed to be efficient search methods for solving optimisation problems. So there will often be a better way, depending on the problem space.
  
  > **Comments:**
  > **username_2**: _"In short, no, and this is technically an impossible task for any known optimisation technique."_... well technically yes, it can, the actual point is "can it do it in an polynomial amount of time"?   There are optimization algorithms that can give you the global max, just think about an extensive grid search... the problem is that they require an exponential amount of time/resources.   About the rest, I agree with you  
  > **username_1**: @username_2 This is not about polynomial time or search efficiency, just that the general case is immediately infinite, there's no N to consider scaling issues by. If you were talking about a system that was bound in some way, eg a finite grid, then search efficiency does come into play, and the problem tractable in theory. The OP doesn't specify any such bounds, and implies there are none with their example  
  > **username_0**: @username_1 Thank you for helping me out! Your answer is very useful. :)  
  
  ---
  
  