pulsatrix
Loading...
Searching...
No Matches
noise_schedule.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <cstdint>
9#include <vector>
10
12#include "pulsatrix/tensor.hpp"
13
14namespace pulsatrix {
15
47public:
61 explicit NoiseSchedule(int64_t num_timesteps, float beta_start = 1e-4f, float beta_end = 0.02f);
62
64 [[nodiscard]] int64_t num_timesteps() const { return num_timesteps_; }
65
71 [[nodiscard]] float beta(int64_t t) const;
72
78 [[nodiscard]] float alpha(int64_t t) const;
79
85 [[nodiscard]] float alpha_bar(int64_t t) const;
86
104 [[nodiscard]] Tensor add_noise(const Tensor& x0, const Tensor& epsilon, int64_t t) const;
105
125 [[nodiscard]] Tensor denoise_step(const Tensor& x_t, const Tensor& predicted_epsilon, const Tensor& z,
126 int64_t t) const;
127
128private:
133 [[nodiscard]] size_t index_of(int64_t t, const char* context) const;
134
135 int64_t num_timesteps_;
136 std::vector<float> beta_;
137 std::vector<float> alpha_;
138 std::vector<float> alpha_bar_;
139};
140
141} // namespace pulsatrix
The DDPM (Ho et al. 2020, arXiv:2006.11239) linear variance schedule plus the two tensor operations d...
Definition noise_schedule.hpp:46
float alpha_bar(int64_t t) const
alpha_bar_t = prod_{s=1..t} alpha_s (the cumulative product).
NoiseSchedule(int64_t num_timesteps, float beta_start=1e-4f, float beta_end=0.02f)
Precomputes the linear beta schedule and its alpha / alpha_bar derivatives.
Tensor add_noise(const Tensor &x0, const Tensor &epsilon, int64_t t) const
Closed-form forward (noising) sample: x_t = sqrt(alpha_bar_t) * x0 + sqrt(1 - alpha_bar_t) * epsilon.
Tensor denoise_step(const Tensor &x_t, const Tensor &predicted_epsilon, const Tensor &z, int64_t t) const
One reverse (sampling) step, x_{t-1} = mean_term + sqrt(beta_t) * z where the mean term is (1/sqrt(al...
float beta(int64_t t) const
Variance beta_t at timestep t.
float alpha(int64_t t) const
alpha_t = 1 - beta_t.
int64_t num_timesteps() const
Number of diffusion steps T this schedule was built for.
Definition noise_schedule.hpp:64
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Abstract interface isolating vendor-specific memory/compute operations from Tensor/ComputationGraph.
Definition acquisition_functions.hpp:16
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).