Coder Social home page Coder Social logo

Multi-interval remez algorithm about lolremez HOT 11 OPEN

ramym1 avatar ramym1 commented on September 21, 2024
Multi-interval remez algorithm

from lolremez.

Comments (11)

aadler avatar aadler commented on September 21, 2024

Why don't you just find separate minimax interpolating polynomials for each interval?

from lolremez.

ramym1 avatar ramym1 commented on September 21, 2024

I want to approximate a polynomial for sign function in [-1,1]. My usecase is that I have an encrypted input x \in [-1,1] but I can't know if x is negative or positive. I am using "fully homomorphic encryption" which supports evaluating polynomials on encrypted data.

from lolremez.

samhocevar avatar samhocevar commented on September 21, 2024

That’s a very interesting use case! I’ll have a look at what can be done.

from lolremez.

ramym1 avatar ramym1 commented on September 21, 2024

Thanks a lot!
actually this problem is solved in the state of the art by what is called "multi-interval Remez algorithm", which computes Remez on [-1,-eps], [eps, 1]:
https://eprint.iacr.org/2020/834.pdf

from lolremez.

samhocevar avatar samhocevar commented on September 21, 2024

So, this specific case is actually a lot less complex than the general case, because you can use the technique for odd functions explained in the lolremez manual, the function you want to approximate is simply $f(x) = 1$ and the range is $[\sqrt{0.01},1]$.

For instance:

$ lolremez -d 5 -r 0.1:1 '1/sqrt(x)' '1/sqrt(x)'
double f(double x)
{
    double u = -27.674387189032068;
    u = u * x + 89.61852558307946;
    u = u * x + -113.12718846240877;
    u = u * x + 70.763443739725503;
    u = u * x + -23.464237705608777;
    return u * x + 4.8738244889926898;
}
$

Replacing $x$ with $x^2$ and multiplying the final result by $x$:

image

from lolremez.

ramym1 avatar ramym1 commented on September 21, 2024

Thank you!
do you have an idea on how to solve the general case?

from lolremez.

ramym1 avatar ramym1 commented on September 21, 2024

Or more specifically, is it possible to compute an approximation of a stepwise function? For example, approximating the following function:
f(x) = {-3 if x < -1, 0 if -1 < x < 1, 2 if 1 < x < 3}
In the domains: [-3+eps, -1-eps], [-1+eps, 1-eps], [1+eps, 3-eps]`.

One way to do this would be to express f(x) as the sum of two stepwise functions that have two branches, and then using your solution to approximate a stepwise function with two branches. However, I wonder if there is a way to compute an approximation of f(x) using Remez directly.

from lolremez.

samhocevar avatar samhocevar commented on September 21, 2024

The Remez algorithm doesn’t work well with non-continuous functions. I would recommend helping it by making the functions continuous, or even smooth (C-infinity). You can for instance build a good such function using tanh(). In your case:

$$-3 + 3\frac{1+\tanh k(x+1)}{2} + 2\frac{1+\tanh k(x-1)}{2}$$

The greater $k$ is, the closer to the stepwise function you will get. For instance with $k = 5$ and $k = 30$:

image

Using the Remez algorithm on $[-3,3]$ will then give something like that:

image

However there is clearly a problem with LolRemez and that kind of function; most of the time it fails to converge and find a solution. I am going to investigate.

from lolremez.

ramym1 avatar ramym1 commented on September 21, 2024

Great, thanks!

from lolremez.

yellow123Nike avatar yellow123Nike commented on September 21, 2024

So, this specific case is actually a lot less complex than the general case, because you can use the technique for odd functions explained in the lolremez manual, the function you want to approximate is simply f(x)=1 and the range is [0.01,1].

For instance:

$ lolremez -d 5 -r 0.1:1 '1/sqrt(x)' '1/sqrt(x)'
double f(double x)
{
    double u = -27.674387189032068;
    u = u * x + 89.61852558307946;
    u = u * x + -113.12718846240877;
    u = u * x + 70.763443739725503;
    u = u * x + -23.464237705608777;
    return u * x + 4.8738244889926898;
}
$

Replacing x with x2 and multiplying the final result by x:

image

"How to approximate only use 7th-order polynomial?"

from lolremez.

j2kun avatar j2kun commented on September 21, 2024

Funny that I also saw this in search of a remez-like algorithm for FHE. Note that a Go implementation of the multi-interval method exists in Lattigo: https://github.com/tuneinsight/lattigo/blob/0d754047425ff9513bf6fbea717415a754911408/he/hefloat/minimax_composite_polynomial.go#L125

from lolremez.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.