Skip to main content
. 2025 Oct 22;10(11):715. doi: 10.3390/biomimetics10110715
Algorithm 1 TBC-HRL: Strategy Optimization and Training Procedure
  •  1:

    Init: high-level SAC π1, low-level SAC π0 (NDBCNet), twin critics Q1,1,Q1,2 and Q0,1,Q0,2, target critics Q1,itgt,Q0,itgt, replay buffers D1,D0, optimizers with LR (η1,η0), discounts (γ,γτ), temperatures (α1,α0), Polyak factor τpolyak, batch sizes (B1,B0), update steps (K1,K0)

  •  2:

    for each episode do

  •  3:

       Reset env; get st

  •  4:

       while episode not terminated do

  •  5:

         Sample high-level action (g,Δt)∼π1(·|st); set Δtrem←Δt, τ←0, Rsum←0, sstart←st

  •  6:

         for k=0 to Δt−1 do

  •  7:

            Sample a∼π0(·|st,g,Δtrem)

  •  8:

            Execute a; observe st+1, reward r0, done

  •  9:

            Store (st,g,Δtrem,a,r0,st+1,Δtrem−1) in D0

  • 10:

            Rsum←Rsum+r0;   Δtrem←Δtrem−1;   τ←τ+1

  • 11:

            // low-level updates

  • 12:

            for u=1 to K0 do

  • 13:

              Sample batch {(s,g,δ,a,r,s′,δ′)}B0∼D0;   sample a′∼π0(·|s′,g,max(δ′,0))

  • 14:

              y0←r+γminiQ0,itgt(s′,g,max(δ′,0),a′)−α0logπ0(a′|s′,g,max(δ′,0))

  • 15:

              Update Q0,i towards y0;   update π0 with respect to α0logπ0−miniQ0,i

  • 16:

              Soft-update Q0,itgt←τpolyakQ0,i+(1−τpolyak)Q0,itgt

  • 17:

              (optional) adjust α0 by target entropy

  • 18:

            end for

  • 19:

            t←t+1;   st←st+1

  • 20:

            if done or GoalReached(st,g) or Δtrem=0 then

  • 21:

              break

  • 22:

            end if

  • 23:

         end for

  • 24:

         // aggregate and store high-level SMDP transition

  • 25:

         r1←Rsum (plus success bonus/penalty)

  • 26:

         Store (sstart,g,τ,r1,st,done) in D1

  • 27:

         if not GoalReached(st,g) then

  • 28:

            g′←st Hindsight Goal Relabeling (HGR)

  • 29:

            recompute r1′

  • 30:

            Store (sstart,g′,τ,r1′,st,done) in D1

  • 31:

         end if

  • 32:

         // high-level updates

  • 33:

         for u=1 to K1 do

  • 34:

            Sample batch {(s,g,τ,r1,s+,d)}B1∼D1;   sample (g+,Δt+)∼π1(·|s+)

  • 35:

            y1←r1+γτminiQ1,itgt(s+,g+,Δt+)−α1logπ1(g+,Δt+|s+)

  • 36:

            Update Q1,i towards y1;   update π1 with respect to α1logπ1−miniQ1,i

  • 37:

            Soft-update Q1,itgt←τpolyakQ1,i+(1−τpolyak)Q1,itgt

  • 38:

            (optional) adjust α1 by target entropy

  • 39:

         end for

  • 40:

       end while

  • 41:

    end for

  • 42:

    return trained π1(θ1), π0(θ0)