aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/vespa/eval/eval/fast_forest.h
blob: 7931f19858db30a23eeb423b0db82ab2b3ecfdd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "function.h"
#include <vespa/vespalib/util/optimized.h>
#include <memory>
#include <cassert>
#include <cmath>

namespace vespalib::eval::gbdt {

/**
 * Use modern optimization strategies to improve evaluation
 * performance of GBDT forests.
 *
 * Comparisons must be on the form 'feature < const' or '!(feature >=
 * const)'. The inverted form is used to signal that the true branch
 * should be selected when the feature value is missing (NaN).
 **/
class FastForest
{
protected:
    FastForest();
public:
    virtual ~FastForest();
    using UP = std::unique_ptr<FastForest>;
    class Context {
    protected:
        Context();
    public:
        virtual ~Context();
        using UP = std::unique_ptr<Context>;
    };
    static UP try_convert(const Function &fun, size_t min_fixed = 8, size_t max_fixed = 64);
    virtual vespalib::string impl_name() const = 0;
    virtual Context::UP create_context() const = 0;
    virtual double eval(Context &context, const float *params) const = 0;
    double estimate_cost_us(const std::vector<double> &params, double budget = 5.0) const;
};

}