Predict linear data given the slope

sisyphus: <p>Hi everyone, I am very new to neural networks and pytorch. I would like to train a model to take slope as an input, and give the corresponding line as an output. You might wonder why I wouldn’t just do this directly with the equation y=mx. The point is that I eventually want to use this same idea to make predictions for a highly non-linear function of an unknown form, but which is unique for different sets of parameters. Linear data is just the simplest example.</p>
<p>At any rate, I was thinking I could train a model on a bunch of linear data labeled with the slope, and then give the model a new slope and see how well it is able to make the corresponding line. I’m having a hard time figuring out how to do this with pytorch. The pytorch website has examples of image recognition, but the labels all correspond to discrete categories, whereas slope is a continuous variable. I have also looked at the examples for regression, but I’m struggling to see how to train something like that. It seems like the regression examples just try to fit a single function, but I want something that can <em>predict</em> a function.</p>
<p>So does anyone know how to do what I’m describing? I hope I am making myself clear. Thanks.</p>

JuanFMontesinos: <p>The problem is that this <code>y=mx+c</code> is the very basic behavior of a single neuron.<br>
So indeed if you create a linear layer with bias=0 and a 1 filter you will basically get this op mx.</p>
<p>Why would you want to struggle to make it harder?<br>
You have many tutorials which you can adapt to predict something more diff (like a sine)</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://linuxtut.com/en/fe2d3308b3ba56a80c7a/">
  <header class="source">
      <img src="https://linuxtut.com/py.png" class="site-icon" width="16" height="16">

      <a href="https://linuxtut.com/en/fe2d3308b3ba56a80c7a/" target="_blank" rel="noopener nofollow ugc" title="12:00AM - 16 November 2020">linuxtut.com – 16 Nov 20</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://linuxtut.com/en/fe2d3308b3ba56a80c7a/" target="_blank" rel="noopener nofollow ugc">Sine wave prediction (regression) with Pytorch</a></h3>

  <p>Python, Anaconda, Chainer, regression, PyTorch</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
<p>
or</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://jaimefernandezdcu.wordpress.com/2018/11/15/lstm-a-how-to-implement-it-in-pytorch-b-i-nice-example-using-ltms-to-predict-the-sine-wave-in-pytorch/">
  <header class="source">
      <img src="https://s1.wp.com/i/favicon.ico" class="site-icon" width="32" height="32">

      <a href="https://jaimefernandezdcu.wordpress.com/2018/11/15/lstm-a-how-to-implement-it-in-pytorch-b-i-nice-example-using-ltms-to-predict-the-sine-wave-in-pytorch/" target="_blank" rel="noopener nofollow ugc" title="01:59PM - 15 November 2018">Jaime B. Fernández R. – 15 Nov 18</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:440/166;"><img src="https://jaimefernandezdcu.files.wordpress.com/2018/11/lstms_0pred.png?fit=440%2C330" class="thumbnail" width="440" height="166"></div>

<h3><a href="https://jaimefernandezdcu.wordpress.com/2018/11/15/lstm-a-how-to-implement-it-in-pytorch-b-i-nice-example-using-ltms-to-predict-the-sine-wave-in-pytorch/" target="_blank" rel="noopener nofollow ugc">LSTM: a) How to implement it in PyTorch. b) A nice example using LTMs to...</a></h3>

  <p>a) LSTM: a) How to implement it in PyTorch. b) A nice example using LTMs to predict the sine wave in PyTorch. I go this example and run a basic test to predict a sine wave to see how a LSMT behaves…</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>So basically you can adapt this to a line.</p>

sisyphus: <p>Thank you very much! I will check these examples out.</p>

sisyphus: <p>I was able to use these examples to write what I wanted. Thank you so much!</p>