Answers.Body: <p>All modern frameworks for deep learning (<code>PyTorch</code>, <code>Jax</code>, <code>Tensorflow</code>) support automatic differentation. These operations can be easily implemented. Here I write, how it would look like in <code>PyTorch</code>:</p>
  <pre><code>class Net(nn.Module):
  
      def __init__(self):
           super().__init__()
  
           self.a = nn.Parameter(torch.randn(1))
           self.b = nn.Parameter(torch.randn(1))
           self.c = nn.Parameter(torch.randn(1))
           self.d = nn.Parameter(torch.randn(1))
           self.e = nn.Parameter(torch.randn(1))
  
     def forward(self, z1, y3):
         z = z1 + self.e
         y2 = y3 + self.d
         y1 = z + self.a
         x2 = y2 + self.c
         x1 = x2 + 2 * y1 + self.b
         return x1
  </code></pre>
  <p>And the use case is the following, say:</p>
  <pre><code>net = Net()
  net(torch.ones(1), 2 * torch.ones(1))
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-27T09:09:06.613Z
Answers.LastActivityDate: 2021-07-27T09:09:06.613Z
Answers.UserDisplayName: spiridon_the_sun_rotator
Body: <p>Say I have these equations:</p>
  <p><span class="math-container">$$x_1 = x_2 + 2y_1 + b$$</span>
  <span class="math-container">$$x_2 = y_2 + c$$</span>
  <span class="math-container">$$y_1 = z + a$$</span>
  <span class="math-container">$$y_2 = y_3 + d$$</span>
  <span class="math-container">$$z = z_1 + e$$</span></p>
  <p><span class="math-container">$x_1$</span> depends on <span class="math-container">$x_2$</span> (depends on <span class="math-container">$y_2$</span> (depends on <span class="math-container">$y_3$</span>)) and <span class="math-container">$y_1$</span> (depends on <span class="math-container">$z$</span> (depends on <span class="math-container">$z_1$</span>)).</p>
  <p><span class="math-container">$x_1$</span> is my final equation and <span class="math-container">$y_3$</span> and <span class="math-container">$z_1$</span> are my initial variables.</p>
  <p>How do I represent them in a neural network? My final aim is to backtrack from <span class="math-container">$x_1$</span>, and see what change of an amount <span class="math-container">$n$</span> in <span class="math-container">$x_1$</span> resulted from which of <span class="math-container">$y_3$</span> or <span class="math-container">$z_1$</span>.</p>
  <p>All these variables are item prices in the real world.</p>
  <p>My inputs are <span class="math-container">$z_1$</span> and <span class="math-container">$y_3$</span> and my output is <span class="math-container">$x_1. z_1$</span> and <span class="math-container">$y_3$</span> are prices and the final output <span class="math-container">$x_1$</span> is also a price.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-27T14:34:22.040Z
Comments.Text: Do you have a particular reason to prefer a neural network solution as opposed to a traditional solver for a linear system? If you're not particularly set on neural networks, there are efficient ways to solve linear systems in a much simpler way.
Comments.UserDisplayName: htl
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-27T15:40:34.220Z
Comments.Text: I want a neural network solution so that I can trace back any delta change in x1 to a major change in either z1 or y3. This neural network will train on historic price data, like last 10 years, and will be used to backtrack changes in x1 thereafter. Do you think a neural network is good for this or is there anything else that is better?
Comments.UserDisplayName: Chinmoy
Tags: <neural-networks><machine-learning><backpropagation>
Title: How to create a neural network from a set of equations?
UserDisplayName: Chinmoy
ThreadText: # How to create a neural network from a set of equations?
  
  (Asked by: username_0 on 2021-07-27)
  
  Say I have these equations:
  
  $$x\_1 = x\_2 + 2y\_1 + b$$
  $$x\_2 = y\_2 + c$$
  $$y\_1 = z + a$$
  $$y\_2 = y\_3 + d$$
  $$z = z\_1 + e$$
  
  $x\_1$ depends on $x\_2$ (depends on $y\_2$ (depends on $y\_3$)) and $y\_1$ (depends on $z$ (depends on $z\_1$)).
  
  $x\_1$ is my final equation and $y\_3$ and $z\_1$ are my initial variables.
  
  How do I represent them in a neural network? My final aim is to backtrack from $x\_1$, and see what change of an amount $n$ in $x\_1$ resulted from which of $y\_3$ or $z\_1$.
  
  All these variables are item prices in the real world.
  
  My inputs are $z\_1$ and $y\_3$ and my output is $x\_1. z\_1$ and $y\_3$ are prices and the final output $x\_1$ is also a price.
  
  **Tags:** neural-networks, machine-learning, backpropagation
  
  > **Comments:**
  > **username_1**: Do you have a particular reason to prefer a neural network solution as opposed to a traditional solver for a linear system? If you're not particularly set on neural networks, there are efficient ways to solve linear systems in a much simpler way.  
  > **username_0**: I want a neural network solution so that I can trace back any delta change in x1 to a major change in either z1 or y3. This neural network will train on historic price data, like last 10 years, and will be used to backtrack changes in x1 thereafter. Do you think a neural network is good for this or is there anything else that is better?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-07-27. Score: 1
  
  All modern frameworks for deep learning (`PyTorch`, `Jax`, `Tensorflow`) support automatic differentation. These operations can be easily implemented. Here I write, how it would look like in `PyTorch`:
  
  ```
  class Net(nn.Module):
  
      def __init__(self):
           super().__init__()
  
           self.a = nn.Parameter(torch.randn(1))
           self.b = nn.Parameter(torch.randn(1))
           self.c = nn.Parameter(torch.randn(1))
           self.d = nn.Parameter(torch.randn(1))
           self.e = nn.Parameter(torch.randn(1))
  
     def forward(self, z1, y3):
         z = z1 + self.e
         y2 = y3 + self.d
         y1 = z + self.a
         x2 = y2 + self.c
         x1 = x2 + 2 * y1 + self.b
         return x1
  
  ```
  
  And the use case is the following, say:
  
  ```
  net = Net()
  net(torch.ones(1), 2 * torch.ones(1))
  
  ```
  
  
  ---
  
  