Given a Noisy Curve, Write a Function to Output Likely Slopes I am training a Variational Autoencoder (type of convolutional neural network), and have been plotting cost over time. The result is a noisy curve, shown here:

I would like to write a function that gives the probability that the cost function has bottomed out, i.e. that its slope going into the future is zero. Due to the noise, I can't just take the derivative of the cost function, as it oscillates stochastically. I could take the derivative of the moving average of the cost function, but it would be unclear what window size to use, and regardless a single window size would be useful for only part of the line (the noise tends to increase over time).

Is there some mathematical function/theorem I can use to take the local noise of the curve into account, and output a range/distribution of probable slopes? I would imagine the output being something like a histogram with the most likely slope at the middle and increasingly less-likely slopes off on the sides.
A moving window (with some reasonable window size) is probably hard to beat.  I don't know of any parameter-less solution.  

Another possible approach could be to estimate the slope of the last 10% of the data, and compare this to some threshold.  (So, the 1000th data point uses the average of points 900-1000.  The 2000th data point uses the average of points 1800-2000.  And so on.)  This way, if it does flatten out, then if you continue for another 10% longer, you'll reach a point where the last 10% is all flat and the procedure will likely terminate.  This may do 10% more iterations than "necessary", but that might be acceptable given that in return you get a procedure that doesn't require a fixed window size.

However, choosing a threshold might be a bit tricky.  I'm not sure how to do that in a reasonable way.

Given a bunch of data points, you can compute a least-squares fit for the regression line through those points, and find an estimate of the slope of that line.  You can also compute a confidence interval for that slope.  This will give you a range of plausible slopes.