aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/features/random_normal_feature.h
blob: a99cebc4829ff99b751e6dd576da7e0174e07875 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/fef/blueprint.h>
#include <vespa/searchlib/util/random_normal.h>

namespace search::features {


/**
 * Implements the executor for the random normal feature outputting a
 * random number drawn from the Gaussian distribution with the
 * two arguments 'mean' and 'stddev'.
 **/
class RandomNormalExecutor : public fef::FeatureExecutor {
private:
    RandomNormal _rnd;       // seeded once per query

public:
    RandomNormalExecutor(uint64_t seed, double mean, double stddev);
    void execute(uint32_t docId) override;
};


/**
 * Implements the blueprint for the random normal feature.
 */
class RandomNormalBlueprint : public fef::Blueprint {
private:
    uint64_t _seed;
    double   _mean;
    double   _stddev;

public:
    RandomNormalBlueprint();

    void visitDumpFeatures(const fef::IIndexEnvironment & env, fef::IDumpFeatureVisitor & visitor) const override;
    fef::Blueprint::UP createInstance() const override;
    fef::ParameterDescriptions getDescriptions() const override {
        return fef::ParameterDescriptions().
            // Can run without parameters:
            desc().

            // Can run with two parameters (mean and stddev):
            desc().
            number(). // mean
            number(). // stddev

            // Can run with three parameters:
            desc().
            number(). // mean
            number(). // stddev
            string(); // in order to name different features
    }

    bool setup(const fef::IIndexEnvironment & env, const fef::ParameterList & params) override;
    fef::FeatureExecutor &createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const override;
};

}