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

Joint function for Evaluation and Jacobian ? #20

Open
j-fu opened this issue Jul 29, 2020 · 8 comments
Open

Joint function for Evaluation and Jacobian ? #20

j-fu opened this issue Jul 29, 2020 · 8 comments

Comments

@j-fu
Copy link

j-fu commented Jul 29, 2020

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) ?

@rveltz
Copy link
Member

rveltz commented Jul 29, 2020

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.

@j-fu
Copy link
Author

j-fu commented Jul 29, 2020

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.

@rveltz
Copy link
Member

rveltz commented Jul 29, 2020

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.

@j-fu
Copy link
Author

j-fu commented Jul 29, 2020

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).

@rveltz
Copy link
Member

rveltz commented Jul 29, 2020 via email

@j-fu
Copy link
Author

j-fu commented Jul 29, 2020

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.

@rveltz
Copy link
Member

rveltz commented Jul 30, 2020

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?

@j-fu
Copy link
Author

j-fu commented Jul 30, 2020

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

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