Answers.Body: <p>One idea that comes to mind is having the features (inputs) be the digits of the number, rather than the number itself. You might also try converting to binary before hand and then using those digits as features, or use some kind of one hot encoding for the decimal digits. The rationale being that finding primes is a discrete task dealing with integers, you don't want your model interpreting the input as a continuous value.</p>
  <p>You might get better results if you include the modulo of the input with some primes (or just random integers) as features as well.</p>
  <p>As for the hidden layers pick your favorite architecture. Standard linear layers followed by ReLU activations are acceptable. As you said, the last layer would be a sigmoid activation (preceded by a linear layer, not a ReLU). You can experiment with things like batch norm if you want although I wouldn't imagine they would help much.</p>
  <p>With this setup your training data would have features as the binary digits of a positive integer, and the target would be whether or not that integer is prime (0 or 1). Your loss would be binary cross entropy. Train with stochastic gradient descent or friend until convergence. Note that your training data is very imbalanced as most numbers are not prime.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-02T09:49:10.427Z
Answers.LastActivityDate: 2023-10-02T09:55:20.917Z
Answers.LastEditDate: 2023-10-02T09:55:20.917Z
Answers.UserDisplayName: Vityou
Body: <p>How to create a model that can give an output with a range of 0 to 1 with a sigmoid activation function where the value closer to 0 means the lesser chance that the input number is <strong>not</strong> prime and the closer to 1 means the greter chance that the input number is prime.</p>
  <p>This means that the output layer will contain one neuron with a sigmoid activation function.</p>
  <p>But I don't know what the input looks like.</p>
  <p>So, from this problem, I would like to ask, what does the dataset look like?</p>
  <p>Is it a one-dimensional list of prime numbers? like: [2,3,5,...,9997]</p>
  <p>Or is it actually an unsupervised learning problem?</p>
  <p>What do the input, hidden, and output layers look like?</p>
  <p>So in the end, I was expecting this kind of input-output:</p>
  <pre><code>#1
  Input: 77772
  Output: 0.01
  
  #2
  Input: 27777
  Output: 0.69
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-30T19:18:48.300Z
Comments.Text: @RAG The dataset is the question too, whether it will be unsupervised learning or supervised learning.
Comments.UserDisplayName: Muhammad Ikhwan Perwira
Tags: <ai-design><sigmoid>
Title: Approximate the chance of a number is prime using neural network
UserDisplayName: Muhammad Ikhwan Perwira
ThreadText: # Approximate the chance of a number is prime using neural network
  
  (Asked by: username_0 on 2023-09-29)
  
  How to create a model that can give an output with a range of 0 to 1 with a sigmoid activation function where the value closer to 0 means the lesser chance that the input number is **not** prime and the closer to 1 means the greter chance that the input number is prime.
  
  This means that the output layer will contain one neuron with a sigmoid activation function.
  
  But I don't know what the input looks like.
  
  So, from this problem, I would like to ask, what does the dataset look like?
  
  Is it a one-dimensional list of prime numbers? like: [2,3,5,...,9997]
  
  Or is it actually an unsupervised learning problem?
  
  What do the input, hidden, and output layers look like?
  
  So in the end, I was expecting this kind of input-output:
  
  ```
  #1
  Input: 77772
  Output: 0.01
  
  #2
  Input: 27777
  Output: 0.69
  
  ```
  
  **Tags:** ai-design, sigmoid
  
  > **Comments:**
  > **username_0**: @RAG The dataset is the question too, whether it will be unsupervised learning or supervised learning.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-10-02. Score: 1
  
  One idea that comes to mind is having the features (inputs) be the digits of the number, rather than the number itself. You might also try converting to binary before hand and then using those digits as features, or use some kind of one hot encoding for the decimal digits. The rationale being that finding primes is a discrete task dealing with integers, you don't want your model interpreting the input as a continuous value.
  
  You might get better results if you include the modulo of the input with some primes (or just random integers) as features as well.
  
  As for the hidden layers pick your favorite architecture. Standard linear layers followed by ReLU activations are acceptable. As you said, the last layer would be a sigmoid activation (preceded by a linear layer, not a ReLU). You can experiment with things like batch norm if you want although I wouldn't imagine they would help much.
  
  With this setup your training data would have features as the binary digits of a positive integer, and the target would be whether or not that integer is prime (0 or 1). Your loss would be binary cross entropy. Train with stochastic gradient descent or friend until convergence. Note that your training data is very imbalanced as most numbers are not prime.
  
  
  ---
  
  