std1.0.0-beta-7 SafeC docs

std :: ml::rl

Struct std::PolicyAgent

#include <std/ml/rl.h> source

struct PolicyAgent {
    struct Mlp policy;
    struct Mlp value;
    struct Optimizer opt;
    struct PgConfig cfg;
    struct Rng rng;
    struct TensorArena stepArena;
    unsigned long obsDim;
    unsigned long actions;
    struct Vec<float> rObs;
    struct Vec<float> rNext;
    struct Vec<float> rAction;
    struct Vec<float> rReward;
    struct Vec<float> rTerminal;
    struct Vec<float> rDone;
    unsigned long rollout;
    float lastEntropy;
}

Separate policy (logits) and value networks, one Adam optimizer. The rollout collects transitions until PolicyAgent::update consumes them: call it at episode ends (REINFORCE) or every N steps (A2C / PPO).

Fields

§struct Mlp policysource
§struct Mlp valuesource
§struct PgConfig cfgsource
§struct Rng rngsource
§struct TensorArena stepArenasource
§unsigned long obsDimsource
§unsigned long actionssource
§struct Vec<float> rObssource
§struct Vec<float> rNextsource
§struct Vec<float> rActionsource
§struct Vec<float> rRewardsource
§struct Vec<float> rTerminalsource
§struct Vec<float> rDonesource

terminated or truncated

§unsigned long rolloutsource

transitions stored

§float lastEntropysource

Methods

§unsigned long act(const &FloatTensor obs, int sample)source · definition

sample 1: draw from the policy; 0: the most likely action.

§void record( const &FloatTensor obs, unsigned long action, float reward, const &FloatTensor next, int terminated, int truncated, )source · definition
§float update()source · definition

Trains on the stored rollout with the configured algorithm, clears it, and returns the last loss.

§void collect_params(&Vec<&FloatTensor> out) constsource · definition

Parameterized (module.h): the policy and value networks.

§void collect_state(&Vec<&FloatTensor> out) constsource · definition
§void drop()source · definition
§void free() consumesource · definition

= drop()

§static struct PolicyAgent new( unsigned long obsDim, unsigned long actions, const &PgConfig cfg, )source · definition