Trigonometric functions are not very accurate

Hi Everyone, my name is Yuval and I’m a new member of the NBEL-Lab in Israel. I entered the filed not a long time ago and I have some questions:

  1. I’ve noticed that when using sin function, it is better to activate it on a single angle and not on a computed one like, for example, teta1+teta2. So, when I need to activate it on a computed angle, I compute it first using one ensemble and then activate the sin function using another ensemble.
    But, the opposite thing happens with the cos function. Why is that?

  2. The asin function is not very accurate. Any idea why?
    this is the code:

    stim_z = nengo.Node(Piecewise({0: 1}))
    
    z = nengo.Ensemble(n_neurons=3*120, dimensions=1, radius=1)
    
    nengo.Connection(stim_z, z)
    
    teta0 = nengo.Ensemble(n_neurons=1000, dimensions=1, radius=np.sqrt((np.pi/2)**2))

    def calculate_teta0(z):
        if (z < -1 ):  z = -1;
        if (z > 1 ): z = 1;
        return math.asin(z);
    nengo.Connection(z, teta0, function=calculate_teta0)

Hi Yuval and welcome to the forum,

Can you provide a bit more of your code to clear up what it is you are expecting and seeing For question 1? Mainly…

  1. What do you mean by “it is better to activate on a single angle”? Better in what way? Can you show how you are adding your two angles that the performance drops. When you say “the opposite happens with the cos function”, what do you mean exactly? The ouptut is opposite? The performance is better with combined angles?

  2. I’ve added a plot of the neural representation of your asin function by passing in evaluation points between -1 and 1, and plotting the dot product of the activities and learned decoders.
    asin_learned
    It looks like what is happening is that the LIF curve of your neurons has the opposite of your desired shape, causing the poor match towards the extremes.

You could solve this by using lots and lots of neurons with appropriate regularization and perhaps skewing some of the intercepts towards the high end (0.9-0.99 or so). Alternatively, you could use different neural response curves. If you wanted to “cheat” you could use asin as a response curve if you’re not worried about biological constraints.

I’ve attached the script that generates the above plot in case you were interested.

Cheers
asin.py (943 Bytes)

Hi,
Thank you so much for the detailed answer! and sorry for the late response.
Regarding question 1, I figured it is better to combine the angles before using each one of the trig functions (sin, cos). So the question is not relevant anymore :slight_smile:
Regarding question 2, I understand your answer and will do my best to make it work.

Regards.