Answers.Body: <p>In this case it is possible to translate the function into a neural network without training because you know the function and don't need to learn the weights.</p>
  <p>If you know the number of elements in x, then the mean can be a single layer network with the number of elements in x as an input and no output. The weights of the network are just 1/len(x), and you can set the bias to 0.
  Then you can build your own activation function which returns 1 if the output is superior to 1, 0 else.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-06T15:08:31.107Z
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-07-07T03:14:58.627Z
Answers.Text: note that I highlighted **example**, the function I gave is just an example! and it is so easy to just manually set the paramerter, what i am asking is how to do it generally!
Answers.UserDisplayName: em1971
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-07T07:52:41.157Z
Answers.Text: in that case I don't think it's possible to help you further. But your suggested method is probably best: you can generate samples using the deterministic function and use those to train a NN. The most difficult part will be to find the appropriate architecture and compexity
Answers.UserDisplayName: theophile
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-06T12:56:37.810Z
Answers.LastActivityDate: 2022-07-06T12:56:37.810Z
Answers.UserDisplayName: theophile
Body: <p>Suppose I have a known function, for <strong>example</strong>:</p>
  <pre><code>def func(x):
      m = np.mean(x)
      if m &gt; 1: 
         return 1
      else:
         return 0
  </code></pre>
  <p>Are there any algorithms to convert this into a neural network?</p>
  <p>A naive way would be:</p>
  <ul>
  <li>use <code>func</code> to generate training set</li>
  <li>train the NN using the training set</li>
  </ul>
  <p>But this will be slow and the trained NN will probably be inaccurate. Are there better ways to &quot;copy&quot; a known function?</p>
  <p>As the questions suggests, I am not asking about the about trivial <strong>example</strong> function, I am asking about a <strong>general</strong> known function!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-06T12:29:28.087Z
Comments.Text: Why is it necessary to do something like this? If you know the function, why not use it directly?
Comments.UserDisplayName: mikkola
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-06T12:35:49.960Z
Comments.Text: it can be really useful, but I am not gonna talk about it here to raise unnecessary debates.  of course you can think of it as "unnecessary", but that doesn't change the fact that the above is a valid academic question
Comments.UserDisplayName: em1971
Tags: <neural-networks><machine-learning>
Title: How to convert a known function to a neural network
UserDisplayName: em1971
ThreadText: # How to convert a known function to a neural network
  
  (Asked by: username_0 on 2022-07-06)
  
  Suppose I have a known function, for example:
  def func(x):
      m = np.mean(x)
      if m > 1: 
         return 1
      else:
         return 0
  
  Are there any algorithms to convert this into a neural network?
  A naive way would be:
  
  use func to generate training set
  train the NN using the training set
  
  But this will be slow and the trained NN will probably be inaccurate. Are there better ways to "copy" a known function?
  As the questions suggests, I am not asking about the about trivial example function, I am asking about a general known function!
  
  **Tags:** neural-networks, machine-learning
  > **Comments:**
  > **username_1**: Why is it necessary to do something like this? If you know the function, why not use it directly?  
  > **username_0**: it can be really useful, but I am not gonna talk about it here to raise unnecessary debates.  of course you can think of it as "unnecessary", but that doesn't change the fact that the above is a valid academic question  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-07-06. Score: 2
  
  In this case it is possible to translate the function into a neural network without training because you know the function and don't need to learn the weights.
  
  If you know the number of elements in x, then the mean can be a single layer network with the number of elements in x as an input and no output. The weights of the network are just 1/len(x), and you can set the bias to 0.
  Then you can build your own activation function which returns 1 if the output is superior to 1, 0 else.
  
  > **Comments:**
  > **username_3**: 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).  
  > **username_0**: note that I highlighted **example**, the function I gave is just an example! and it is so easy to just manually set the paramerter, what i am asking is how to do it generally!  
  > **username_2**: in that case I don't think it's possible to help you further. But your suggested method is probably best: you can generate samples using the deterministic function and use those to train a NN. The most difficult part will be to find the appropriate architecture and compexity  
  
  ---
  
  