Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
advice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Philipp Sauer
advice
Commits
acf29237
Commit
acf29237
authored
1 month ago
by
Philipp Sauer
Browse files
Options
Downloads
Patches
Plain Diff
Bugfix buffer record_range
parent
c26a88d8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/buffer.py
+6
-2
6 additions, 2 deletions
src/buffer.py
with
6 additions
and
2 deletions
src/buffer.py
+
6
−
2
View file @
acf29237
...
...
@@ -11,6 +11,7 @@ class Buffer:
# Its tells us num of times record() was called.
self
.
buffer_counter
=
0
self
.
buffer_filled
=
False
# Instead of list of tuples as the exp.replay concept go
# We use different np.arrays for each tuple element
...
...
@@ -33,7 +34,10 @@ class Buffer:
def
record
(
self
,
obs_tuple
):
# Set index to zero if buffer_capacity is exceeded,
# replacing old records
index
=
self
.
buffer_counter
%
self
.
buffer_capacity
if
self
.
buffer_counter
==
self
.
buffer_capacity
:
self
.
buffer_filled
=
True
self
.
buffer_counter
=
0
index
=
self
.
buffer_counter
self
.
state_buffer
[
index
]
=
obs_tuple
[
0
]
self
.
action_buffer
[
index
]
=
obs_tuple
[
1
]
...
...
@@ -77,7 +81,7 @@ class Buffer:
# We compute the loss and update parameters
def
learn
(
self
):
# Get sampling range
record_range
=
min
(
self
.
buffer_c
ounter
,
self
.
buffer_c
apacity
)
record_range
=
self
.
buffer_c
apacity
if
self
.
buffer_filled
else
self
.
buffer_c
ounter
# Randomly sample indices
batch_indices
=
np
.
random
.
choice
(
record_range
,
self
.
batch_size
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment