BifurcationKit.jl icon indicating copy to clipboard operation
BifurcationKit.jl copied to clipboard

Joint function for Evaluation and Jacobian ?

Open j-fu opened this issue 3 years ago • 8 comments

Hi, I am thinking about using your package. My first try would be to join this with my package VoronoiFVM.jl. I understand that for the problem call back one can either pass F(x,p) or F(x,p) and J(x,p) together.

As in my code I am calculating F and (sparse) J at the same time using ForwardDiff and DiffResults I wonder if it would be possible to have another option which allows to pass something like F_and_J(x,p) ?

j-fu avatar Jul 29 '20 09:07 j-fu

Hi,

I am not sure I can do what you are asking for because it would impair the use of iterative methods (for example). However, I think you can minimize the wastes by using a struct which caches the jacobian and Fvalue and "your" functions would return those values to my package.

rveltz avatar Jul 29 '20 13:07 rveltz

I already thought about the caching option, wouldn't mind to do it this way. However I need to know when to "re-cache".

Can I assume that for given x, both F and J are called exactly once, respectively ? Or are there cases when F is called and there is no call to J or vice versa ?

I would like to use two flags storing if F resp. J has been called, and I would re-cache and reset the flags on the next invocation.

j-fu avatar Jul 29 '20 14:07 j-fu

Can I assume that for given x, both F and J are called exactly once, respectively

Pretty much I guess, everything is in newton or newtonPALC. J is called an extra time for eigenvalue detection in Utils.jl but coming after newtonPALC, it should be the same x.

rveltz avatar Jul 29 '20 14:07 rveltz

Had a look into the code - in newtonPALC we also need to take into account the parameters. Just relying on the call pattern appears to be quite brittle... Thinking about storing hashes of x and p now . This should be O(N) and little work compared to the rest.

julia> myhash(X)=sum((x)->hash(x),X)
myhash (generic function with 1 method)

julia> Y=collect(1:0.0001:100);

julia> @time myhash(Y)
  0.037302 seconds (119.07 k allocations: 5.307 MiB)
0xe408239bb83608ce

julia> @time myhash(Y)
  0.004938 seconds (1 allocation: 16 bytes)
0xe408239bb83608ce

julia> Y[1000]+=1.0e-8
1.09990001

julia> @time myhash(Y)
  0.003233 seconds (1 allocation: 16 bytes)
0xb9204860d37e4879

julia> 

So this might do (Julia hash() would give a collision here).

j-fu avatar Jul 29 '20 15:07 j-fu

Le 29 juillet 2020 17:14:40 j-fu [email protected] a écrit :

Had a look into the code - in newtonPALC we also need to take into account the parameters. Just relying on the call pattern appears to be quite brittle... Thinking about storing hashes of x and p now .

you should think of x and p as a whole in this context. if i were to ask for dpF would it simplify your work ( i would remove the FD approx in newtonPALC)?

This should be O(N) and little work compared to the rest.

julia> myhash(X)=sum((x)->hash(x),X) myhash (generic function with 1 method)

julia> Y=collect(1:0.0001:100);

julia> @time myhash(Y) 0.037302 seconds (119.07 k allocations: 5.307 MiB) 0xe408239bb83608ce

julia> @time myhash(Y) 0.004938 seconds (1 allocation: 16 bytes) 0xe408239bb83608ce

julia> Y[1000]+=1.0e-8 1.09990001

julia> @time myhash(Y) 0.003233 seconds (1 allocation: 16 bytes) 0xb9204860d37e4879

julia> So this might do (Julia hash() would give a collision here).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

Envoyé avec AquaMail pour Android https://www.mobisystems.com/aqua-mail

rveltz avatar Jul 29 '20 17:07 rveltz

I was thinking to ask about this. From a robustness POV, asking for dpF IMHO would be a better choice. I don't have this functionality in Julia yet (in our C++ path following code we do it this way, but we have not many resources to maintain and develop it, especially for all the bifurcation detection stuff you already did, and then our nonlinearities are becoming nightmares...).

I have plans to add the dpF creation resulting in a vector via autodiff.

BTW currently I am just investigating these things for setting up my mind, I hope to find time to work on it in September.

j-fu avatar Jul 29 '20 17:07 j-fu

BTW currently I am just investigating these things for setting up my mind, I hope to find time to work on it in September.

Me too, I cannot do it right now. BTW, did you try my package in conjonction with yours?

rveltz avatar Jul 30 '20 05:07 rveltz

Not yet - with this discussion I tried to clarify what I need to do, now it is pretty clear. I plan this for September...

j-fu avatar Jul 30 '20 08:07 j-fu