Issue
Currently, I save correlations on Google Firebase. The structure looks somewhat like this:
{a: {a: 1.0, b: 0.6, c: -0.3, ...}, b: {a: 0.6, b: 1.0, c: -0.5, ...}, ...}
I want to retrieve a full correlation matrix efficiently, but I also want to have the freedom to select any combination of items.
I have a working solution by calling, for example "[GET]: /correlations/a/b", but as you can imagine I have many calls to the endpoint to download a full correlation matrix, even though I already omit via code calling "/correlations/a/b"+"/correlations/b/a" and "/correlations/a/a".
I was reading before creating the post, that I could also use a [POST] request with a body to download the matrix, by only calling the endpoint once. But, is this good practice? Is there a better approach to this problem?
Thanks in advance!
Solution
You can make batch requests to return the output. You can use either use parameters in GET requests to get the correlations
/api?q1=cor(a,b)&q2=cor(b,c)
or you can use the post requests
/api
where body = {"correlation vars": [(a,b), (c,d)]}
- Try to design API which is more readable.
- If you wish you pass complex queries then POST request could be a better option.
- Simpler queries could be created using parameters in GET request
- Compress data using gZip or byte array so I/O call is faster. Lot of frameworks provides in build support for that.
- Depending on your requirement measure tradeoffs between CPU computation and cost of I/O calls.
Answered By - Nikhil Kishore
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.