News for hackers. Stuff that matters.
Re:Why train when you can optimize? by steppi on Saturday April 30, 2022 @12:37AM (#31213377)
Neural networks can approximate any function, but that doesn’t mean they do so efficiently. Depending on the function, they can require incredible amounts of neurons and training. At their worst, they devolve into a lookup table. It’s not hard to find these examples either. Just try training a neural network to compute sin(x)!

This is possible! One of the cool things about neural networks is that you can try to encode prior understanding into either the structure of the network or choice of activation function. See the paper Neural Networks Fail to Learn Periodic Functions and How to Fix It by Ziwin, Hartweg, and Uweda. Where they propose the activation function f(x) = x + sin(x)^2 that can encode an understanding that the underlying function should be periodic.

[1] https://proceedings.neurips.cc/paper/2020/file/1160453108d3e...

Re:Why train when you can optimize? by PheonixPharts on Saturday April 30, 2022 @10:27AM (#31216314)
> Just try training a neural network to compute sin(x)!

This is also the classic demo case for LSTMs, I have a notebook open right now that as a LSTM learning the sine function quite well with 32 dimensional state vector.

However the authors point still stands. Neural Networks are not great at computing arbitrary functions where the output is an unbounded real number. The sine function is still limited to range that is bounded to [0,1].

A better example of where NNs really fail is when trying to learn tricky to implement the normal quantile function (inverse CDF).

This would be an excellent place for function approximation because

a.) generating training data is easy (just run random numbers into the CDF and reverse these arguments into a NN)

b.) manually writing the quantile function from scratch is a pain since it involves the inverse error function which is very annoying to implement from scratch.

You can learn the standard quantile function for mean=0, sd=1, however if you try to generalize this to taking not only the desired quantile but an arbitrary mean and standard deviation you will not learn anything useful.

It's a bit of a shame that neural networks are weak in this area because it would be incredible to have a good tool to approximate inverse functions in general. The fact that we almost never see neural networks being used as a tool for this type of work is evidence of this limitation.

In general if you're problem can't be modeled where the output is some vector of probabilities it's not a great fit for NNs.

Re:Why train when you can optimize? by steppi on Saturday April 30, 2022 @11:08AM (#31216608)
It's a bit of a shame that neural networks are weak in this area because it would be incredible to have a good tool to approximate inverse functions in general. The fact that we almost never see neural networks being used as a tool for this type of work is evidence of this limitation.

It's funny you say. I haven't actually used NNs much in my research but my background is in math and in my spare time I'm a maintainer for SciPy working on special and statistical functions, often the exact kind of stuff you mentioned.

I might take up your challenge and write a blog post about it or something if I get any success.

Anyway, I wasn’t trying to invalidate the author’s general point, just point out a fun fact about his example.

Re:Why train when you can optimize? by PheonixPharts on Saturday April 30, 2022 @11:37AM (#31216831)
> I might take up your challenge and write a blog post about it or something if I get any success.

Success or failure, I would really enjoy seeing that write up! I would be even more excited to be proven wrong.

The promise of "universal function approximator" is very temping. My personal dream would be to have it so one could essentially run scipy in reverse and learn the entire library with a NN. Even in the case I gave, the idea that you could learn an arbitrary quantile function means you could also arbitrarily learn a sampler for any distribution, since all you have to do compose a uniform sampler with whatever quantile function you learned.

Of course for this example I'm using "solved" using a similar approach with variational inference (pyro has a write up on it: https://pyro.ai/examples/svi_part_i.html, you might find David Blei's "Variational Inference: A Review for Statisticians" useful as well https://arxiv.org/abs/1601.00670)

Re:Why train when you can optimize? by steppi on Saturday April 30, 2022 @12:07PM (#31217031)
What a coincidence. Pyro has basically become my go to for Bayesian learning and I know those docs in and out. I’ve also skimmed that David Blei article before. Small world. I’m not very confident of success but it seems like an interesting path to explore.
Re:Why train when you can optimize? by mumblemumble on Saturday April 30, 2022 @11:54AM (#31216951)
> LSTM learning the sine function quite well with 32 dimensional state vector.

I'd say that, from "LSTM" and "32 dimensional state vector" alone, the author's point still stands. That may not be a huge network by contemporary deep learning standards, but it's still a pretty darned expensive way to compute sine. That's 100% in line with the original assertion that ANNs can learn any function, but they can't necessarily do so efficiently.

Re:Why train when you can optimize? by Der_Einzige on Saturday April 30, 2022 @12:49PM (#31217324)
Is it that neural networks are weak or is it that gradient descent/backprop doesn't do well for finding good local solutions for these kinds of problems?
Re:Why train when you can optimize? by steppi on Sunday May 01, 2022 @08:51AM (#31224620)
My understanding is that it's because extrapolation is difficult in general. Extrapolating the behavior of a periodic function like sine is one thing, but extrapolating the behavior of a 1d function that tends to infinity is another challenge altogether. I happen to be very familiar with the implementation of the inverse CDF of the normal distribution though. My plan is to cook a lot of prior knowledge into the NN. Even if I get it working, the end result will likely seem more like sleight of hand than something truly impressive.
Re:Why train when you can optimize? by zarzavat on Saturday April 30, 2022 @01:56AM (#31213713)
It’s hard to walk if you can’t feel your legs.

The problem is improperly evaluating the neural network as a function of time, instead of evaluating the network as a function of previous state.

When we humans approximate functions (let’s say you’re drawing it on a piece of paper, or waving your arm around) we do not simply look at a clock and feed forward that information directly into our motor neurons. Rather, we have sensory neurons that feed in the current state of the function we are approximating as an input, then approximating the next output of a periodic function becomes trivial.

It’s very easy to train a neural network to look at a piece of a sine wave and predict what the next value should be - the fact that the function is periodic actually helps you.

Re:Why train when you can optimize? by dahart on Saturday April 30, 2022 @09:52AM (#31216081)
> It’s very easy to train a neural network to look at a piece of a sine wave and predict what the next value should be - the fact that the function is periodic actually helps you.

I’m not sure what you mean. Are you talking about training a network to predict cos(x)? In this case nothing at all changes by training on the derivative.

Or do you mean train the net to take as input sin(t) and produce sin(t+0.01)? The problem with this is that any given value of sin(t) has 2 answers for sin(t+0.01), therefore your optimizer is going to spit out 0 as the answer. Plus, this is a different problem entirely, and you lose the ability to infer sin(t) based on t. It doesn’t answer the same question.

Your suggestion is further going to be seriously confounded if the periodic function is more complex, say, the sum of several sin waves. There can be an arbitrary number of values y that correctly match f(x).

You should try it before making assumptions that it’s easy, see what it takes to train a net to predict sin(x), without embedding knowledge of the fact that sin is periodic.

> The problem is improperly evaluating the neural network as a function of time, instead of evaluating the network as a function of state.

This also sounds like an assumption to me that somehow the entire world of research has failed to consider the most obvious of ideas. The point of both optimizers and neural networks is that they can be black boxes, right? It doesn’t matter at all whether the input is time based or position based or a function of money. The network, in theory, can learn any function, time or otherwise, and there’s nothing special about time.

But, neural networks function better with domain knowledge. When you know the function domain is time and that the output is periodic, you can do things to make a network easier to train, like using a periodic activation function.

As a side note, RNNs explicitly model an NN based on previous state. Also all layered NNs can be viewed as a series of smaller nets that feed state to the next net. In some sense, NNs always evaluate as a function of state.

Re:Why train when you can optimize? by omrjml on Saturday April 30, 2022 @02:41AM (#31213905)
Periodic function like sin(x) are not a dynamical system so its previous state does not determine the current state. So it should be approximated in that way.
Re:Why train when you can optimize? by doubleunplussed on Saturday April 30, 2022 @02:48AM (#31213934)
Periodic functions like sin(x) are the solutions to differential equations like dy/dx = -y that describe for example, oscillations of springs, to name but one of an extremely large number of dynamical systems that behave this way.
Re:Why train when you can optimize? by omrjml on Saturday April 30, 2022 @02:56AM (#31213983)
Of course sine can appear in the solution for dynamical systems but the function itself is not dynamical. When evaluating sin(x) you do not need to know about the previous state.
Re:Why train when you can optimize? by zmgsabst on Saturday April 30, 2022 @03:11AM (#31214041)
That is true, the problem is with the conclusion you drew from that fact:

> So it should not be approximated in that way.

We can’t conclude a dynamic approximation is a bad approach based purely on the fact the underlying function isn’t dynamic.

The function might nevertheless be easily approximated via dynamics — as in the case of predicting sine from seeing the recent history.

Re:Why train when you can optimize? by freemint on Saturday April 30, 2022 @02:13PM (#31217940)
sin(x) only arises as solution in second order systems. So d^2x/dt^2 = -x
Re:Why train when you can optimize? by doubleunplussed on Sunday May 01, 2022 @07:04AM (#31223963)
Sorry, you're absolutely correct. Brain fart. The equation I wrote actually is for an exponential, whoops.
Re:Why train when you can optimize? by em500 on Saturday April 30, 2022 @04:54AM (#31214454)
It's completely valid and equivalent to formulate trigonometric functions as a dynamic system (x,y-coordinates as you go around the circle using a rotation matrix).
Re:Why train when you can optimize? by vidarh on Sunday May 01, 2022 @03:15AM (#31222878)
It sounds like you're trying to say something different than the comment you replied to. sin(x) for a range of x is trivial to draw by looking at earlier parts of the curve to determine what to draw next. Back in the slow 1980's home computer days, on machines without floating point and multiply/divide, we quickly got used to approximate sine waves numerically by simply typing out sequences of integers with a rough idea of the wave it'd produce. If you gave me a subset of such a sequence and asked me to complete it, I wouldn't need much of it to assume you were wanting to approximate sin.
Re:Why train when you can optimize? by omrjml on Saturday April 30, 2022 @02:49AM (#31213941)
Edit: should not be approximated
Re:Why train when you can optimize? by em500 on Saturday April 30, 2022 @04:57AM (#31214469)
I have the creeping feeling that soon the field is going to reinvent all of Fourier analysis from scratch.
Re:Why train when you can optimize? by orbifold on Saturday April 30, 2022 @08:27AM (#31215506)
It will be called „Neural Harmonic Analysis“, it will cite one paper by a Russian and otherwise ignore any prior work which didn’t include the word neural network.
Re:Why train when you can optimize? by srean on Saturday April 30, 2022 @05:01PM (#31219321)
Its sad that this is not far from the truth
Re:Why train when you can optimize? by guidopallemans on Saturday April 30, 2022 @10:43AM (#31216440)
wavenet and transformer models already come dangerously close
Re:Why train when you can optimize? by SemanticStrengh on Saturday April 30, 2022 @01:10AM (#31213501)
And then your NN can't represent anything else than periodic functions.. If we had to build separate programs for each product requirements variations.. programming would not be viable. More generally neural networks can't even imitate a dumb calculator without throwing absurd errors despite the rules of calculus being trivial and well defined. And matching a calculator is a task order of magnitudes easier than the semantic Causal reasoning abilities of human NLU that is involved in argumentation, inferences and understanding. But people are pathetically fooled by the fallacy of it being a uNiVeRsAl aPpRoXiMaTor.
Re:Why train when you can optimize? by viraptor on Saturday April 30, 2022 @01:43AM (#31213649)
> And then your NN can't represent anything else than periodic functions

Significant parts of x+sin are close to linear. You don't need to use this activation as the result layer either. Why would we lose anything?

> If we had to build separate programs for each product requirements variations

We pretty much do? We use both extremely generic frameworks both in technical sense (.net) and organisational (sap). But we also have software written to specific requirements where needed (there's millions of very specific ways to invoice someone, companies get invoicing platforms written just for them from scratch). There's space for both approaches.

Re:Why train when you can optimize? by telchar on Saturday April 30, 2022 @01:41AM (#31213640)
And yet neural networks can solve symbolic integral and derivative problems and differential equations better than other computer algebra programs. Sure one network might fail to compute sin(x) numerically, but another could easily tell you its derivative is cos(x). Turns out they are pretty flexible. Do they need to do everything?
Re:Why train when you can optimize? by ABeeSea on Saturday April 30, 2022 @02:50AM (#31213950)
Source? I would be very surprised if there was a neural symbolic PDE solver better than what’s in wolfram mathematica.
Re:Why train when you can optimize? by SemanticStrengh on Saturday April 30, 2022 @03:07AM (#31214026)
Re:Why train when you can optimize? by mhh__ on Saturday April 30, 2022 @02:53AM (#31213962)
At the cost of how many parameters?
Re:Why train when you can optimize? by PartiallyTyped on Saturday April 30, 2022 @01:49AM (#31213677)
Re:Why train when you can optimize? by SemanticStrengh on Saturday April 30, 2022 @01:52AM (#31213694)
? I did not say that NNs can't represent periodic functions. Show me a NN calculator with >99% accuracy if you wanna refute me.
Re:Why train when you can optimize? by PartiallyTyped on Saturday April 30, 2022 @02:09AM (#31213782)
> and then your NN can't represent anything else than periodic functions..

This is a quote from the parent comment where you state that NNs with periodic activations can't represent non periodic functions.

Siren (what I linked) uses periodic activations and is able to represent non periodic functions.

Re:Why train when you can optimize? by SemanticStrengh on Saturday April 30, 2022 @02:33AM (#31213872)
Oh OK, thanks yes that's what I was looking for! However if this NN can represent non Periodic functions, what cost does the Periodic function support incur on non Periodic function accuracy, if any?
Re:Why train when you can optimize? by PartiallyTyped on Saturday April 30, 2022 @04:36AM (#31214378)
It actually behaves a lot better than non periodic functions in some scenarios. It seems that period functions enable a network to encode positional information within [-1,1]. This is supported by the fact that positional encoding is needed in transformers to make them work.
Re:Why train when you can optimize? by lukaszwojtow on Saturday April 30, 2022 @04:03AM (#31214233)
Shameless plug as I'm the author: Primeclue uses math functions to express models and one of its function is sine. Like here: https://github.com/lukaszwojtow/primeclue/blob/68e3b4c8e9f1a...
Re:Why train when you can optimize? by whatshisface on Saturday April 30, 2022 @12:47AM (#31213423)
If we're allowed to do that, why can't my activation function be sin(x)?
Re:Why train when you can optimize? by yobbo on Saturday April 30, 2022 @01:11AM (#31213507)
It can, but sin(x) has infinite number of extremes, and the gradients will vanish at those points. Activations will get stuck at 1 and -1 (x=π/2, 3π/2, ...). They set x+(1/a)*sin²(x) to be monotonic, which fixes this.

Or you need to optimize without using gradients.

Re:Why train when you can optimize? by blackcat201 on Saturday April 30, 2022 @01:03AM (#31213474)
You can use sin as activation function, but that would require careful initialization to avoid gradient explosion as you would ended up with a lot of points where gradient is simply zero. You can refer to Implicit Neural Representations with Periodic Activation Functions for more details.
Re:Why train when you can optimize? by zarzavat on Saturday April 30, 2022 @01:35AM (#31213612)
It works perfectly if you don’t have any parameters.
Re:Why train when you can optimize? by PartiallyTyped on Saturday April 30, 2022 @01:49AM (#31213676)
Re:Why train when you can optimize? by sicp-enjoyer on Saturday April 30, 2022 @02:08AM (#31213777)
I'm surprised to see almost no discussion of fourier series in that paper, considering fourier series is all about representing signals as linear combinations of sinusoidal functions.
Re:Why train when you can optimize? by PartiallyTyped on Saturday April 30, 2022 @02:22AM (#31213830)
You may be interested in [1] where they go to a great extend to show that the convolution operation that we consider in DL is the dual of fourier series [2].

[1] https://geometricdeeplearning.com

[2] https://arxiv.org/pdf/2104.13478.pdf page 27 (23 if you count book pages).

Re:Why train when you can optimize? by amelius on Saturday April 30, 2022 @08:00AM (#31215357)
Is convolution in DL not implemented with the FFT as the underlying workhorse?
Re:Why train when you can optimize? by PartiallyTyped on Saturday April 30, 2022 @09:41AM (#31216013)
Probably no since FFT is slower and less parallelizable than products.
Re:Why train when you can optimize? by anoy8888 on Saturday April 30, 2022 @08:58AM (#31215707)
I like your article and went to your home page to find more good articles and I like what I saw. Thank you for sharing. The only thing is that I am reading from my phone and the site is not very mobile friendly
Re:Why train when you can optimize? by thomasahle on Monday May 02, 2022 @02:13PM (#31238702)
While `x + sin(x)^2` may be monotonic itself, it only takes a simple linear combination of two neurons like `x+sin(x)^2 - (x/2 + sin(x/2)^2)` before you have a completely crazy loss landscape. I have a feeling this is why such activation functions haven't become standard.