Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replicating front-page example #31

Open
jagunther opened this issue Jun 15, 2023 · 1 comment
Open

replicating front-page example #31

jagunther opened this issue Jun 15, 2023 · 1 comment

Comments

@jagunther
Copy link

Hi!

First of all: Thanks a lot for making your code available :)

I want to implement 1D Fourier-extension of some functions and came across this library last week. I did a fresh install of Julia and the FrameFun, BasisFunctions and DomainSets packages. The first thing I did was to run the example code from the front-page (I run it as a script from the command-line):

gr();

B = Fourier(61) → -1..1
D = -0.5..0.5
f = x->x
F = Fun(f,B,D)
                                                                                                                                                                    
plot(F,layout = 2)

p = plot!(F,f,subplot=2)
display(p)
readline()

However, contrary to the plot on the front-page, the resulting function is only plotted in the inner interval, see figure attached.
frontpage_code_result

I did the following to get the approximation on the whole interval:

gr();

B = Fourier(61) → -1..1
D = -0.5..0.5
f = x->x
F_ = Fun(f, B, D)
F = expansion(B, F_.coefficients)

plot(F,layout = 2)
p = plot!(F,f,subplot=2)
display(p)
readline()

with the result
frontpage_code_adapted_result

This looks better, but it is not the same result as I see on the front-page.

What do I need to change?

@daanhb
Copy link
Member

daanhb commented Jul 11, 2023

Hi @jagunther, sorry for the slow reply here!

It seems we haven't updated the front page in a while. Indeed, somewhere along the way we changed the way plotting an "extension frame" works. It only shows the part of the approximation that actually approximates the given function (here the interval [-0.5,0.5]) and nothing outside.

The reason your plot on the extension [-1,1] differs from the one on the front page is because the extension is not unique. The "Fourier extension problem" is in fact solved using randomized linear algebra, hence you might even get a different result every time. It should always approximate the given function f on [-0.5,0.5] to high accuracy however.

About plotting the extension: at one point we had a plot_extension=true optional argument, but that seems to have disappeared. In your plotting example you manually create a Fourier basis, rescaled to the interval [-1,1]. This is implicit in the dictionary (more general than a basis) of the expansion F:

julia> dictionary(F)
(-0.5..0.5)  (Fourier(61)  (-1.0..1.0))

julia> superdict(dictionary(F))
Fourier(61)  (-1.0..1.0)

It would be slightly neater if we defined, say,

super(F::Expansion) = Expansion(superdict(dictionary(F)), coefficients(F))

then you could simply write plot(super(F)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants