bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
torch_bernoulli_dist.h
Go to the documentation of this file.
1#ifndef TORCH_BERNOULLI_DIST_H
2#define TORCH_BERNOULLI_DIST_H
3
8
9#include "bitrl/base/bitrl_config.h"
10
11#ifdef USE_PYTORCH
12
15
16#include <torch/torch.h>
17
18namespace bitrl
19{
20namespace maths
21{
22namespace stats
23{
24
29{
30 public:
35 TorchBernoulliDist() = default;
36
44 TorchBernoulliDist(torch_tensor_t probs, bool do_build_from_logits = false);
45
49 virtual ~TorchBernoulliDist() = default;
50
55 virtual torch_tensor_t entropy() const override;
56
62 virtual torch_tensor_t log_prob(torch_tensor_t value) override;
63
67 virtual torch_tensor_t sample(c10::ArrayRef<int64_t> sample_shape = {}) override;
68
73
78
82 torch_tensor_t get_logits() const { return logits_; }
83
88 torch_tensor_t get_probs() const { return probs_; }
89
90 private:
91 torch_tensor_t probs_;
92 torch_tensor_t logits_;
93 torch_tensor_t param_;
94 int num_events_;
95};
96
97} // namespace stats
98} // namespace maths
99} // namespace bitrl
100
101#endif // TORCH_BERNOULLI_DIST_H
102#endif
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
virtual torch_tensor_t entropy() const override
entropy
torch_tensor_t get_logits() const
get_logits
Definition torch_bernoulli_dist.h:82
virtual torch_tensor_t log_prob(torch_tensor_t value) override
log_prob
TorchBernoulliDist()=default
Default constructor.
TorchBernoulliDist(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...
torch_tensor_t get_probs() const
get_probs
Definition torch_bernoulli_dist.h:88
void build_from_logits(torch_tensor_t logits)
build the distribution form logits
virtual ~TorchBernoulliDist()=default
~TorchCategorical. Destructor
Definition torch_bernoulli_dist.h:23
Definition lp_metric.h:10
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