jdtuck / fdasrsf_python

elastic fda python code
http://research.tetonedge.net
BSD 3-Clause "New" or "Revised" License
51 stars 18 forks source link

Query concerning f_pca values generated and plotted in vpca.plot() #30

Closed rmward61 closed 1 year ago

rmward61 commented 1 year ago

Hi, when I use vpca.plot() and examine the f domain plots, the mean function is not exactly the same in all plots. I'm puzzled by this as looking at the code it seems that for each PC, when l=1, stds[l]=0 and so q_pca[:,l,k] = mqn for all k. (fpca.py line 96)

The q domain plots have an identical mean function, but it seems that the integral is giving slightly different f domain curves. I cannot see anything in the code that would cause this, so am I missing something?

Here's an example - the first two principal directions from my dataset. This is only happening for the first two directions though, PD 3 is the same as PD 2 etc.

fmean_compare

Hope you can clarify this for me :)

jdtuck commented 1 year ago

what is your id for integration?

jdtuck commented 1 year ago

Also you are forgetting about the initial value which is not captured in the q domain

rmward61 commented 1 year ago

Hi, thanks for getting back to me. I don't think I can be forgetting the initial value as PDs 2 and 3 are identical, whereas 1 and 2 are different.

Not quite sure what you mean by id for integration? I'm using hourly data for periods of 1 day so 23 values per day.

If it helps, here is the code I've used to produce the plot. And I've attached the full plot so you can see the comparison between PDs 2 and 3?

Thanks for your help,

Rebecca :).

fmean_compare

Code:

time = np.arange(1,25,1).astype('float64')

qpc = vpca.q_pca fpc = vpca.f_pca

fig,axs = plt.subplots(2,2)

axs[0,0].plot(time, qpc[:24,1,0], 'blue') axs[0,0].plot(time, qpc[:24,1,1], '--') axs[0,0].set_title('q domain: PD 1,2', fontsize=10)

axs[0,1].plot(time, fpc[:,1,0], 'blue') axs[0,1].plot(time, fpc[:,1,1], '--') axs[0,1].set_title('f domain: PD 1,2', fontsize=10)

axs[1,0].plot(time, qpc[:24,1,1], 'blue') axs[1,0].plot(time, qpc[:24,1,2], '--') axs[1,0].set_title('q domain: PD 2,3', fontsize=10)

axs[1,1].plot(time, fpc[:,1,1], 'blue') axs[1,1].plot(time, fpc[:,1,2], '--') axs[1,1].set_title('f domain: PD 2,3', fontsize=10)

axs[0,0].tick_params(labelsize=6) axs[0,1].tick_params(labelsize=6) axs[1,0].tick_params(labelsize=6) axs[1,1].tick_params(labelsize=6)

fig.tight_layout(pad=1)

plt.savefig('fmean_compare.png', dpi=300)

jdtuck commented 1 year ago

You are forgetting that when you go to SRSF you loose the intial value of the function, converting back it is added in. Also the 'id' is where the initial value is take in the computation. It is usually the middle of the function. I need to see your original data to really talk more.

rmward61 commented 1 year ago

That’s given me food for thought - I’ll check and get back to you. I’ve been using the MATLAB version up until now but need to move to python, so I have a reasonable understanding of the method. I’ll check how the id is set.

Thanks for your help,

Rebecca

Sent from Outlook for iOShttps://aka.ms/o0ukef


From: Derek Tucker @.> Sent: Tuesday, May 9, 2023 6:05:26 PM To: jdtuck/fdasrsf_python @.> Cc: Rebecca Ward @.>; Author @.> Subject: Re: [jdtuck/fdasrsf_python] Query concerning f_pca values generated and plotted in vpca.plot() (Issue #30)

You are forgetting that when you go to SRSF you loose the intial value of the function, converting back it is added in. Also the 'id' is where the initial value is take in the computation. It is usually the middle of the function. I need to see your original data to really talk more.

— Reply to this email directly, view it on GitHubhttps://github.com/jdtuck/fdasrsf_python/issues/30#issuecomment-1540549814, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADCGFMW52RAGDCP6P4I66Y3XFJ2NNANCNFSM6AAAAAAXLD6U6E. You are receiving this because you authored the thread.Message ID: @.***>

rmward61 commented 1 year ago

Hi,

I don’t think that the issue can be that I am leaving out the initial value as surely it should be the same initial value in all cases for the mean function.

I see the same issue when I use your function vpca.plot(). Here is the output for the first 3 PDs. You can see that the mean function is different for PDs 1 and 2 but the same for 2 and 3.

As regards the id value I’m using the default, so that will be the mid-point. I will try changing it and see if that helps.

Thanks again for your help,

Best regards,

Rebecca

From: Derek Tucker @.> Date: Tuesday, 9 May 2023 at 18:05 To: jdtuck/fdasrsf_python @.> Cc: Rebecca Ward @.>, Author @.> Subject: Re: [jdtuck/fdasrsf_python] Query concerning f_pca values generated and plotted in vpca.plot() (Issue #30)

You are forgetting that when you go to SRSF you loose the intial value of the function, converting back it is added in. Also the 'id' is where the initial value is take in the computation. It is usually the middle of the function. I need to see your original data to really talk more.

— Reply to this email directly, view it on GitHubhttps://github.com/jdtuck/fdasrsf_python/issues/30#issuecomment-1540549814, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADCGFMW52RAGDCP6P4I66Y3XFJ2NNANCNFSM6AAAAAAXLD6U6E. You are receiving this because you authored the thread.Message ID: @.***>

rmward61 commented 1 year ago

I get better results changing id to 23 (the final value in each data sample). Thanks for the pointer - still not exactly the same but much closer.

Thanks again, Rebecca