My modification to the geodesic regression example fails -- but not clear why (at least to me) #427
-
My eventual goal is to introduce weights in the optimization. First, I ran the example from Y = similar(x0)
@show RegressionCost(data, t)(M, x0) # got 0.14286244488043887
RegressionGradient!(data, t)(M, Y, x0) Then, I made this modification to handle weights,
I again calculated the initial gradient, xw0 = ArrayPartition(x0, fill(1/n,n))
M2 = M × ProbabilitySimplex(n-1)
is_point(M2, xw0) # returns true
# Note the scaling by 'n', since the weights are in the probability simplex
Y3 = similar(xw0)
@show calc_cost2(RegressionCost(data, t), M2, xw0) * n # got 0.14286244488043887
calc_gradient2!(RegressionGradient!(data, t), M2, Y3, xw0)
norm(n*Y3[M2,1] - Y) / norm(Y) # got 4.228695411939743e-16 My cost and gradient evaluation are matching. Again, eventually I might optimize over weights as well, but not for now. I try the following for the optimization,
and get
Why doesn't it make any progress when the example problem (with same cost and gradient) seems to work. FYI -- My final optimization will not be over the entire simplex, as there would be many local optima with all weights at 2 points and the geodesic going through those 2. I just want to keep the weights around, either as a parameter or modifiy the objective to penalize non-uniform weights. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 9 replies
-
Hi, What do you mean by your gradient calculations are “matching”? Have you for example verified the gradient with https://manoptjl.org/stable/helpers/checks/#Manopt.check_gradient? I can try to find some time on the weekend to take a closer look. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the help. Incidentally, I believe in RegressionGradient!, there needs to be
and for RegressionGradient2a!,
|
Beta Was this translation helpful? Give feedback.
-
I tried my best today to recreate your example but since this is incremental, it is a bit hard to reproduce your results and problems. Can you maybe post a complete example? That would be great. because sure – I can spent 30+ minutes to get an example to run, but if I only have 30 minutes available like I had just now – that leaves a negative number of minutes to check the example :/ |
Beta Was this translation helpful? Give feedback.
-
Concerning the question in the linked code you wrote about why we do the PCA in a basis: On the sphere at a point $p^$, we have a tangent space – and if we have data in this space – that is data in a 2D space – but the tangent vectors are all always stored as vectors orthogonal to $p^$ – so something 3D. But only a 2D PCA makes sense. So when we represent the tangent vectors by coordinates in a basis, we get what we need – “2D data”. For the rest – sorry for the bug. I will probably remove that tutorial in a next release. Once someone fixes that and writes a tutorial that then also includes a gradient check (the tutorial predates the gradient check implementation by several years) – it should be added to ManoptExamples. |
Beta Was this translation helpful? Give feedback.
-
Great point. Thanks you!
…Sent from my Galaxy
-------- Original message --------
From: Mateusz Baran ***@***.***>
Date: 12/15/24 1:08 PM (GMT-05:00)
To: "JuliaManifolds/Manopt.jl" ***@***.***>
Cc: salbert83 ***@***.***>, Author ***@***.***>
Subject: Re: [JuliaManifolds/Manopt.jl] My modification to the geodesic regression example fails -- but not clear why (at least to me) (Discussion #427)
Yes, technically not using bases explicitly for PCA in many cases would work. It's just not particularly general because in JuliaManifolds tangent vectors are not always represented using plain arrays, so you can't be sure applying standard PCA algorithms works. For a sphere it does though.
Sometimes actually obtaining a basis is computationally expensive and PCA doesn't really need a basis, as you demonstrated with the sphere. I thought about adding more general frames<https://en.wikipedia.org/wiki/Frame_(linear_algebra)> to have fast PCA in cases where getting a basis is expensive but it hasn't reached the top of my priority list yet.
—
Reply to this email directly, view it on GitHub<#427 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFPIHY5JHWKZ4FEC2W73F7D2FXARVAVCNFSM6AAAAABS4ZCLVCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCNJXGM2TKNY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Concerning the question in the linked code you wrote about why we do the PCA in a basis:
There is no other way to make sense of it.
On the sphere at a point $p^$, we have a tangent space – and if we have data in this space – that is data in a 2D space – but the tangent vectors are all always stored as vectors orthogonal to $p^$ – so something 3D. But only a 2D PCA makes sense. So when we represent the tangent vectors by coordinates in a basis, we get what we need – “2D data”.
For the rest – sorry for the bug. I will probably remove that tutorial in a next release. Once someone fixes that and writes a tutorial that then also includes a gradient check (the tutorial predates the gradient che…