Predict linear data given the slope

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.

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 predict a function.

So does anyone know how to do what I’m describing? I hope I am making myself clear. Thanks.

The problem is that this y=mx+c is the very basic behavior of a single neuron.
So indeed if you create a linear layer with bias=0 and a 1 filter you will basically get this op mx.

Why would you want to struggle to make it harder?
You have many tutorials which you can adapt to predict something more diff (like a sine)


So basically you can adapt this to a line.

1 Like

Thank you very much! I will check these examples out.

I was able to use these examples to write what I wanted. Thank you so much!