Skip to content

modify the _embed function to fit the 2d input#15

Merged
raphaelvallat merged 3 commits intoraphaelvallat:masterfrom
cheliu-computation:patch-2
Jan 22, 2022
Merged

modify the _embed function to fit the 2d input#15
raphaelvallat merged 3 commits intoraphaelvallat:masterfrom
cheliu-computation:patch-2

Conversation

@cheliu-computation
Copy link
Copy Markdown
Contributor

modify the _embed funciton, so, it can take input as 2d array.
pre store the sliced signal into a list to accelerate concatenation operation.
pre define the indice of sliced signal to reduce the computing in loop.
add vectorized operation in loop to slice the signal for all input signal in one time.

performance:
1e3 signal with 1000 time point, order = 3, decay=1: 0.01s

1e4 signal with 1000 time point, order = 3, decay=1: 0.1s
1e4 signal with 1000 time point, order = 10, decay=1: 0.85s

1e5 signal with 1000 time point, order = 3, decay=1: 1.11s
1e5 signal with 1000 time point, order = 10, decay=1: 9.82s

5e5 signal with 1000 time point, order = 3, decay=1: 67s

modify the _embed funciton, so, it can take input as 2d array.
pre store the sliced signal into a list to accelerate concatenation operation.
pre define the indice of sliced signal to reduce the computing in loop.
add vectorized operation in loop to slice the signal for all input signal in one time.

performance:
1e3 signal with 1000 time point, order = 3, decay=1: 0.01s

1e4 signal with 1000 time point, order = 3, decay=1: 0.1s
1e4 signal with 1000 time point, order = 10, decay=1: 0.85s

1e5 signal with 1000 time point, order = 3, decay=1: 1.11s
1e5 signal with 1000 time point, order = 10, decay=1: 9.82s

5e5 signal with 1000 time point, order = 3, decay=1: 67s
@raphaelvallat raphaelvallat self-requested a review January 20, 2022 05:24
@raphaelvallat raphaelvallat added the enhancement New feature or request label Jan 20, 2022
@raphaelvallat
Copy link
Copy Markdown
Owner

Hi @cheliu-computation,

Thanks for opening the PR. I have been wanting to implement a 2D version of this function for a long time. I do have several comments however:

  1. Currently the proposed changes will break unit testing, because the AntroPy functions will send a 1D array instead of the required 2D. The _embed function needs to support both 1D and 2D arrays. If 1D array are passed, the array should be converted to a 2D array and then the output should be squeezed back to a 1D array before the return.

  2. Can you run speed benchmarks comparison against the original version? For 1D array of different lengths, as well as for 2D arrays in which you use a simple for loop for the original version?

Thanks,
Raphael

@cheliu-computation
Copy link
Copy Markdown
Contributor Author

Thanks for your review.

  1. this task is easy to solve, I will fix it ASAP.
  2. Test the funciton with 1D array with different size is fine. But how to compare the performance of 2D array on my function and the original one? After the simple for loop, the origianl function will return several 1D array, and we need to assemble it.

While the original funciton cannot do this directly. If I use some numpy API, such as np.concatenate, it will have O(n) time complexity and O(2n) space complexity. Apperently that's unfair to test two functions.

I have tested two functions with 2D array without the assemble operation (no concatenate, stack, etc...) The modified function only has O(1) on time and O(n) on space. Is that an acceptable way to compare two functions?

add one condition to detect the array dimension
if 1d array, follow the original function code
if 2d array, return 3d array (signals_number, embedded signal length, order)
add one condition to detect the array dimension
if 1d array, follow the original function code
if 2d array, return 3d array (signals_number, embedded signal length, order)
@cheliu-computation
Copy link
Copy Markdown
Contributor Author

Hi , I have fixed the function to be able pass 1d and 2d array both. The return would be 2d if you pass 1d as the original function. I think there is no problem here. Hoever, if you pass 2d array, the function will return 3d array and no function from 'antropy' can deal with it so far, becasue I have not modified other functions.

Do you prefer to merge it after I have modified other entropy computing function to be able pass the result (3d array) from the modified function? It might takes lots of time to modified whole function in this package.

benchmark comparsion.xlsx

@raphaelvallat
Copy link
Copy Markdown
Owner

Thank you @cheliu-computation. I think we can merge this first PR and then you, me and/or others can work on adding support for such 3D arrays in the other functions.

@cheliu-computation
Copy link
Copy Markdown
Contributor Author

cheliu-computation commented Jan 21, 2022 via email

@raphaelvallat
Copy link
Copy Markdown
Owner

Merging now!

@raphaelvallat raphaelvallat merged commit a39dc97 into raphaelvallat:master Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants