-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Laurent Valdes
committed
Dec 23, 2024
0 parents
commit 7485470
Showing
6 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.ipynb* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "02d39a02-17f2-4307-8d41-6903c289e9d2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import tensorflow as tf" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "793e06aa-0230-433f-a92a-6c32846bc444", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"()\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"a = tf.constant(1)\n", | ||
"print(a.shape)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "4ea11dda-ab38-4e21-97e4-c318c0790ec7", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"(5,)\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"b = tf.constant([1,2,3,4,5])\n", | ||
"print(b.shape)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a3394f67-a3fc-4c26-887e-70c315703d65", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python (gym-env-py3.10)", | ||
"language": "python", | ||
"name": "gym-env-py3.10" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.16" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import gymnasium as gym | ||
|
||
env = gym.make("CartPole-v1", render_mode="human") | ||
env.reset() | ||
|
||
for i in range(200): | ||
env.step(env.action_space.sample()) | ||
env.render() | ||
|
||
env.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import gymnasium as gym | ||
|
||
env = gym.make("CartPole-v1", render_mode="human") | ||
env.reset() | ||
|
||
for i in range(100): | ||
done = False | ||
game_rew = 0 | ||
|
||
while not done: | ||
action = env.action_space.sample() | ||
obs, rew, terminated, truncated, info = env.step(action) | ||
game_rew += rew | ||
|
||
# Combine `terminated` (episode ended in a terminal state) | ||
# and `truncated` (time limit or another truncation condition) | ||
done = terminated or truncated | ||
|
||
if done: | ||
print(f"Episode {i} finished, reward: {game_rew}") | ||
env.reset() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import gymnasium as gym | ||
|
||
|
||
env = gym.make("CartPole-v1", render_mode="human") | ||
print(env.observation_space) | ||
print(env.action_space) | ||
print(env.action_space.sample()) | ||
print(env.action_space.sample()) | ||
print(env.observation_space.low) | ||
print(env.observation_space.high) | ||
|
||
env.reset() | ||
|
||
for i in range(100): | ||
done = False | ||
game_rew = 0 | ||
|
||
while not done: | ||
action = env.action_space.sample() | ||
obs, rew, terminated, truncated, info = env.step(action) | ||
game_rew += rew | ||
|
||
# Combine `terminated` (episode ended in a terminal state) | ||
# and `truncated` (time limit or another truncation condition) | ||
done = terminated or truncated | ||
|
||
if done: | ||
print(f"Episode {i} finished, reward: {game_rew}") | ||
env.reset() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import tensorflow as tf | ||
|
||
# Create two constants: a and b | ||
a = tf.constant(4) | ||
b = tf.constant(3) | ||
|
||
# Perform a computation | ||
c = a + b | ||
|
||
# In TensorFlow 2.x, eager execution is enabled by default, | ||
# so you can directly inspect the result. | ||
print(c.numpy()) # This should print 7 |