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

does this package support multithreading? #10

Open
bryan-woods opened this issue Nov 22, 2016 · 1 comment
Open

does this package support multithreading? #10

bryan-woods opened this issue Nov 22, 2016 · 1 comment

Comments

@bryan-woods
Copy link

I know that the XGBoost package itself supports multithreading of the prediction task. Does this predictor implementation also support multithreading? If not, how could I go about adding it?

@komiya-atsushi
Copy link
Owner

Hi,

This library does not support multithreading yet, but instances of Predictor are thread-safe.

So if you have many FVec objects, you can share and use a Predictor across multiple threads like below:

// Predictor predictor = ...;
// List<SimpleEntry<Integer, FVec>> data = ...;

OptionalDouble logloss = data.parallelStream()
        .mapToDouble(pair -> {
            double predValue = predictor.predictSingle(pair.getValue());
            predValue = Math.min(Math.max(predValue, 1e-15), 1 - 1e-15);
            int actual = pair.getKey();
            return actual * Math.log(predValue) + (1 - actual) * Math.log(1 - predValue);
        })
        .average();

logloss.ifPresent(d -> System.out.println("Logloss (parallel): " + (-d)));

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

No branches or pull requests

2 participants