bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
torch_categorical.h
Go to the documentation of this file.
1#ifndef TORCH_CATEGORICAL_H
2#define TORCH_CATEGORICAL_H
7
8#include "bitrl/base/bitrl_config.h"
9
10#ifdef USE_PYTORCH
11
14
15#include <torch/torch.h>
16
17namespace bitrl
18{
19namespace maths::stats
20{
21
23{
24
25 public:
30 TorchCategorical() = default;
31
38 TorchCategorical(torch_tensor_t probs, bool do_build_from_logits = false);
39
43 ~TorchCategorical() override = default;
44
49 virtual torch_tensor_t entropy() const override;
50
56 virtual torch_tensor_t log_prob(torch_tensor_t value) override;
57
61 virtual torch_tensor_t sample(c10::ArrayRef<int64_t> sample_shape = {}) override;
62
67
72
76 torch_tensor_t get_logits() const { return logits_; }
77
82 torch_tensor_t get_probs() const { return probs_; }
83
84 private:
85 torch_tensor_t probs_;
86 torch_tensor_t logits_;
87 torch_tensor_t param_;
88 int num_events_;
89};
90} // namespace maths::stats
91} // namespace bitrl
92#endif
93#endif
TorchCategorical()=default
Default constructor.
void build_from_logits(torch_tensor_t logits)
build the distribution form logits
TorchCategorical(torch_tensor_t probs, bool do_build_from_logits=false)
Build the categorical distribution from given torch_tensor_t of probabilities. if the flag build_from...
virtual torch_tensor_t log_prob(torch_tensor_t value) override
log_prob
~TorchCategorical() override=default
~TorchCategorical. Destructor
torch_tensor_t get_logits() const
get_logits
Definition torch_categorical.h:76
virtual torch_tensor_t entropy() const override
entropy
torch_tensor_t get_probs() const
get_probs
Definition torch_categorical.h:82
virtual torch_tensor_t sample(c10::ArrayRef< int64_t > sample_shape={}) override
Ssample. Sample from the distribution.
void build_from_probabilities(torch_tensor_t probs)
build the distribution from probabilities
Definition torch_bernoulli_dist.h:23
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
torch::Tensor torch_tensor_t
torch_tensor_t
Definition bitrl_types.h:95