facebookresearch / balance

The balance python package offers a simple workflow and methods for dealing with biased data samples when looking to infer from them to some target population of interest.
https://import-balance.org
GNU General Public License v2.0
686 stars 41 forks source link

[FEATURE] Chainging the way Sample take strategy for adjust #54

Open hadi-gharibi opened 1 year ago

hadi-gharibi commented 1 year ago

The existing implementation of the adjust function in the literal module, which relies on a separate mapper to import the appropriate function, complicates the process of adding new strategies. To address this issue, I propose introducing a new function signature that clearly indicates the minimal arguments for the Sample object and specifies the return type as TypedDict. Here's an example of how it could be implemented:

e.g:

return_func_sig = TypedDict({ 
        "weight": pd.DataFrame,
        "model": {
            "method": str,
            "X_matrix_columns": List[str],
            ...
            }
)

Callable[[pd.DataFrame, pd.DataFrame, ...], return_func_sig]

It should be possible to pass this callable as a strategy to adjust function and it would call this function instead.

talgalili commented 1 year ago

Hey Hadi, Nice to e-meet and thank you for the proposal!

I don't expect that adding this abstraction will be high on my priority.

In an ideal world, if you (or someone else) have a specific new method you'd like to propose, you could propose it and based on what it is we can think of what would be the best way to add it. In such a case I would be very open to further discuss your proposal. If you're open to make the implementations I'd be super happy to review your PR, and we can also discuss here (based in your idea) what could be a way to structure the work.

But if this is a general abstraction for someone else, in the future, to use it for adding more methods, then I'd keep this in mind, but am not likely to prioritize working on it in the near future.

Makes sense? WDYT?

On Mon, 22 May 2023, 19:17 Hadi Gharibi, @.***> wrote:

The existing implementation of the adjust function in the literal module, which relies on a separate mapper to import the appropriate function, complicates the process of adding new strategies. To address this issue, I propose introducing a new function signature that clearly indicates the minimal arguments for the Sample object and specifies the return type as TypedDict. Here's an example of how it could be implemented:

e.g:

return_func_sig = TypedDict({ "weight": pd.DataFrame, "model": { "method": str, "X_matrix_columns": List[str], ... } ) Callable[[pd.DataFrame, pd.DataFrame, ...], return_func_sig]

It should be possible to pass this callable as a strategy to adjust function and it would call this function instead.

— Reply to this email directly, view it on GitHub https://github.com/facebookresearch/balance/issues/54, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBXOWLL2CYNROH444KTXHOGRRANCNFSM6AAAAAAYKVOJ6M . You are receiving this because you are subscribed to this thread.Message ID: @.***>