pub struct LinearGaussianPolicy<T: Float + Debug + Send + Sync + 'static> { /* private fields */ }Expand description
Diagonal Gaussian policy a ~ N(W φ(s), diag(σ²)) with σ = exp(log_std).
Both the mean weights and the (state-independent) log standard deviations are
trainable parameters, exposed as "weights" and "log_std". All gradients are
closed form:
∇_W log π(a|s) = ((a − μ)/σ²) φ(s)ᵀ
∇_logσ_j log π(a|s) = (a_j − μ_j)²/σ_j² − 1
∇_logσ_j H[π] = 1 ∇_W H[π] = 0
∇_W Σ_ij w_ij μ_j(s_i) = Σ_i w_i φ(s_i)ᵀ (deterministic-policy-gradient hook)Implementations§
Source§impl<T: Float + Debug + Send + Sync + 'static> LinearGaussianPolicy<T>
impl<T: Float + Debug + Send + Sync + 'static> LinearGaussianPolicy<T>
Sourcepub fn new(action_dim: usize, n_features: usize, init_std: T) -> Result<Self>
pub fn new(action_dim: usize, n_features: usize, init_std: T) -> Result<Self>
Create a zero-mean policy with the given initial standard deviation.
Sourcepub fn action_dim(&self) -> usize
pub fn action_dim(&self) -> usize
Action dimension.
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Observation/feature dimension.
Sourcepub fn mean_actions(&self, observations: &Array2<T>) -> Result<Array2<T>>
pub fn mean_actions(&self, observations: &Array2<T>) -> Result<Array2<T>>
Deterministic mean action μ(s) = W φ(s), shape (n, action_dim).
Trait Implementations§
Source§impl<T: Clone + Float + Debug + Send + Sync + 'static> Clone for LinearGaussianPolicy<T>
impl<T: Clone + Float + Debug + Send + Sync + 'static> Clone for LinearGaussianPolicy<T>
Source§fn clone(&self) -> LinearGaussianPolicy<T>
fn clone(&self) -> LinearGaussianPolicy<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Float + Debug + Send + Sync + 'static> PolicyNetwork<T> for LinearGaussianPolicy<T>
impl<T: Float + Debug + Send + Sync + 'static> PolicyNetwork<T> for LinearGaussianPolicy<T>
Source§fn evaluate_actions(
&self,
observations: &Array2<T>,
actions: &Array2<T>,
) -> Result<PolicyEvaluation<T>>
fn evaluate_actions( &self, observations: &Array2<T>, actions: &Array2<T>, ) -> Result<PolicyEvaluation<T>>
Evaluate actions for given observations
Source§fn get_action_distribution(
&self,
observations: &Array2<T>,
) -> Result<ActionDistribution<T>>
fn get_action_distribution( &self, observations: &Array2<T>, ) -> Result<ActionDistribution<T>>
Get action distribution for given observations
Source§fn update_parameters(
&mut self,
deltas: &HashMap<String, Array1<T>>,
) -> Result<()>
fn update_parameters( &mut self, deltas: &HashMap<String, Array1<T>>, ) -> Result<()>
Add a parameter delta to the policy parameters (see the trait docs).
Source§fn log_prob_gradient(
&self,
observations: &Array2<T>,
actions: &Array2<T>,
coefficients: &Array1<T>,
) -> Result<HashMap<String, Array1<T>>>
fn log_prob_gradient( &self, observations: &Array2<T>, actions: &Array2<T>, coefficients: &Array1<T>, ) -> Result<HashMap<String, Array1<T>>>
Gradient of a coefficient-weighted sum of log-probabilities:
∂/∂θ Σᵢ cᵢ · log π(aᵢ | sᵢ). Read moreSource§fn entropy_gradient(
&self,
observations: &Array2<T>,
) -> Result<HashMap<String, Array1<T>>>
fn entropy_gradient( &self, observations: &Array2<T>, ) -> Result<HashMap<String, Array1<T>>>
Gradient of the batch-mean entropy
∂/∂θ (1/N) Σᵢ H[π(·|sᵢ)]. Read moreSource§fn mean_action_gradient(
&self,
observations: &Array2<T>,
weights: &Array2<T>,
) -> Result<HashMap<String, Array1<T>>>
fn mean_action_gradient( &self, observations: &Array2<T>, weights: &Array2<T>, ) -> Result<HashMap<String, Array1<T>>>
Gradient of a weighted sum of the distribution mean:
∂/∂θ Σᵢ Σⱼ w[i,j] · μⱼ(sᵢ). Read moreSource§fn kronecker_factors(
&self,
observations: &Array2<T>,
actions: &Array2<T>,
) -> Result<Vec<KroneckerBlock<T>>>
fn kronecker_factors( &self, observations: &Array2<T>, actions: &Array2<T>, ) -> Result<Vec<KroneckerBlock<T>>>
Per-sample Kronecker factors of the Fisher information matrix. Read more
Source§fn score_matrix(
&self,
observations: &Array2<T>,
actions: &Array2<T>,
) -> Result<Array2<T>>
fn score_matrix( &self, observations: &Array2<T>, actions: &Array2<T>, ) -> Result<Array2<T>>
Per-sample score vectors
g_i = ∇_θ log π(aᵢ|sᵢ), one per row, flattened
with flatten_named’s canonical layout. Read moreAuto Trait Implementations§
impl<T> Freeze for LinearGaussianPolicy<T>
impl<T> RefUnwindSafe for LinearGaussianPolicy<T>where
T: RefUnwindSafe,
impl<T> Send for LinearGaussianPolicy<T>
impl<T> Sync for LinearGaussianPolicy<T>
impl<T> Unpin for LinearGaussianPolicy<T>
impl<T> UnsafeUnpin for LinearGaussianPolicy<T>
impl<T> UnwindSafe for LinearGaussianPolicy<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.