Search in sources :

Example 16 with RandomCutForestState

use of com.amazon.randomcutforest.state.RandomCutForestState in project ml-commons by opensearch-project.

the class BatchRandomCutForest method predict.

@Override
public MLOutput predict(DataFrame dataFrame, Model model) {
    if (model == null) {
        throw new IllegalArgumentException("No model found for batch RCF prediction.");
    }
    RandomCutForestState state = (RandomCutForestState) ModelSerDeSer.deserialize(model.getContent());
    RandomCutForest forest = rcfMapper.toModel(state);
    List<Map<String, Object>> predictResult = process(dataFrame, forest, 0);
    return MLPredictionOutput.builder().predictionResult(DataFrameBuilder.load(predictResult)).build();
}
Also used : RandomCutForest(com.amazon.randomcutforest.RandomCutForest) RandomCutForestState(com.amazon.randomcutforest.state.RandomCutForestState) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with RandomCutForestState

use of com.amazon.randomcutforest.state.RandomCutForestState in project ml-commons by opensearch-project.

the class BatchRandomCutForest method train.

@Override
public Model train(DataFrame dataFrame) {
    RandomCutForest forest = createRandomCutForest(dataFrame);
    Integer actualTrainingDataSize = trainingDataSize == null ? dataFrame.size() : trainingDataSize;
    process(dataFrame, forest, actualTrainingDataSize);
    Model model = new Model();
    model.setName(FunctionName.BATCH_RCF.name());
    model.setVersion(1);
    RandomCutForestState state = rcfMapper.toState(forest);
    model.setContent(ModelSerDeSer.serialize(state));
    return model;
}
Also used : RandomCutForest(com.amazon.randomcutforest.RandomCutForest) Model(org.opensearch.ml.common.parameter.Model) RandomCutForestState(com.amazon.randomcutforest.state.RandomCutForestState)

Aggregations

RandomCutForestState (com.amazon.randomcutforest.state.RandomCutForestState)17 RandomCutForestMapper (com.amazon.randomcutforest.state.RandomCutForestMapper)14 RandomCutForest (com.amazon.randomcutforest.RandomCutForest)8 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 OperationsPerInvocation (org.openjdk.jmh.annotations.OperationsPerInvocation)6 Precision (com.amazon.randomcutforest.config.Precision)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 LinkedBuffer (io.protostuff.LinkedBuffer)5 NormalMixtureTestData (com.amazon.randomcutforest.testutils.NormalMixtureTestData)3 IOException (java.io.IOException)3 Random (java.util.Random)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CommonUtils.checkArgument (com.amazon.randomcutforest.CommonUtils.checkArgument)1 CompactSampler (com.amazon.randomcutforest.sampler.CompactSampler)1