Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use for-loop instead of list comprehension #46

Open
rgaiacs opened this issue Nov 30, 2017 · 2 comments
Open

Use for-loop instead of list comprehension #46

rgaiacs opened this issue Nov 30, 2017 · 2 comments

Comments

@rgaiacs
Copy link

rgaiacs commented Nov 30, 2017

entrofy/core.py has

    # Run the specified number of randomized trials
    results = [__entrofy(df_binary.values, n, rng,
                         w=target_weight,
                         q=target_prob,
                         pre_selects=pre_selects_i,
                         quantile=quantile,
                         alpha=alpha)
               for _ in range(n_trials)]

    # Select the trial with the best score
    max_score, best = results[0]
    for score, solution in results[1:]:
        if score > max_score:
            max_score = score
            best = solution

This could be replaced with

    # Run the specified number of randomized trials
    max_score = 0
    for _ in range(n_trials):
        score, solution = __entrofy(df_binary.values, n, rng,
                         w=target_weight,
                         q=target_prob,
                         pre_selects=pre_selects_i,
                         quantile=quantile,
                         alpha=alpha)
        if score > max_score:
            max_score = score
            best = solution
@bmcfee
Copy link
Collaborator

bmcfee commented Nov 30, 2017

Yes, it could be replaced. Is there a reason to do that though?

@rgaiacs
Copy link
Author

rgaiacs commented Nov 30, 2017

Is there a reason to do that though?

I think this is mostly my preference when coding and thinking about the logic behind it. I could try to write a technical reason related with memory (not allocate all the n_trials solution in memory) or speed (one n_trial for-loop instead of two) but I don't have data to support my idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants