Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptualrobots committed Jan 15, 2024
1 parent 9f6d5b6 commit 9fe29ca
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 91 deletions.
45 changes: 9 additions & 36 deletions nbs/00_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
Expand All @@ -38,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"import gym \n",
"import gym, warnings\n",
"render=False\n",
"runs=1"
]
Expand Down Expand Up @@ -204,7 +195,7 @@
"output_type": "stream",
"text": [
"**************************\n",
"cartpoleh PCTHierarchy [1, 1, 1, 1] fa2763ce-27ed-11ee-aada-8cf8c5b8669e\n",
"cartpoleh PCTHierarchy [1, 1, 1, 1] 94aa530f-b3e3-11ee-939d-5c879c15de65\n",
"--------------------------\n",
"PRE: None\n",
"Level 0 Cols 1\n",
Expand Down Expand Up @@ -356,7 +347,7 @@
"output_type": "stream",
"text": [
"**************************\n",
"cartpoleh PCTHierarchy [1, 1, 1, 1] fa2763ce-27ed-11ee-aada-8cf8c5b8669e\n",
"cartpoleh PCTHierarchy [1, 1, 1, 1] 94aa530f-b3e3-11ee-939d-5c879c15de65\n",
"--------------------------\n",
"PRE: CartPole-v1 CartPoleV1 | 0 | links greaterthan \n",
"Level 3 Cols 1\n",
Expand Down Expand Up @@ -431,22 +422,15 @@
"DiGraph with 18 nodes and 21 edges\n",
"['greaterthan', 'force', 'CartPole-v1', 'cart_velocity_reference', 'cart_position_output', 'subtract', 'cart_velocity', 'cart_position_reference', 'pole_velocity_output', 'subtract1', 'cart_position', 'pole_velocity_reference', 'pole_angle_output', 'subtract2', 'pole_velocity', 'pole_angle_reference', 'subtract3', 'pole_angle']\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\ryoung\\AppData\\Local\\Temp\\ipykernel_21976\\4286188622.py:3: DeprecationWarning: info is deprecated and will be removed in version 3.0.\n",
"\n",
" print(nx.info(gr))\n"
]
}
],
"source": [
"import networkx as nx\n",
"gr = cartpole_hierarchy.graph()\n",
"print(nx.info(gr))\n",
"print(gr.nodes())"
"with warnings.catch_warnings():\n",
" warnings.simplefilter(\"ignore\")\n",
" print(nx.info(gr))\n",
" print(gr.nodes())"
]
},
{
Expand Down Expand Up @@ -509,18 +493,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\ryoung\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\nbdev\\export.py:54: UserWarning: Notebook 'C:\\Users\\ryoung\\Versioning\\python\\nbdev\\pct\\nbs\\12_yaw_module.ipynb' uses `#|export` without `#|default_exp` cell.\n",
"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n",
"See https://nbdev.fast.ai/getting_started.html for more information.\n",
" warn(f\"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\\n\"\n"
]
}
],
"outputs": [],
"source": [
"#| hide\n",
"import nbdev; nbdev.nbdev_export()"
Expand Down
54 changes: 36 additions & 18 deletions nbs/01_putils.ipynb

Large diffs are not rendered by default.

44 changes: 10 additions & 34 deletions nbs/08_architectures.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pct/architectures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'setup_environment', 'create_hierarchy']

# %% ../nbs/08_architectures.ipynb 5
import os
import os, warnings
import numpy as np
from abc import ABC, abstractmethod

Expand Down
23 changes: 21 additions & 2 deletions pct/putils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import sys
import importlib
import json
import warnings
warnings.filterwarnings("error")

# %% ../nbs/01_putils.ipynb 4
class SingletonObjects:
Expand Down Expand Up @@ -316,11 +318,28 @@ def floatListsToString(alist, places):

# %% ../nbs/01_putils.ipynb 24
def sigmoid(x, range, slope) :
return -range / 2 + range / (1 + np.exp(-x * slope / range));
val = 0
if abs(x) > 10000000:
exv = - np.sign(x) * 10000000
else:
exv = -x * slope / range
if exv > 709:
exv = 709
try:
val = -range / 2 + range / (1 + np.exp(exv))
except RuntimeWarning:
print(f'RuntimeWarning... exv={exv} x={x} slope={slope} range={range}')

return val

# %% ../nbs/01_putils.ipynb 25
def smooth(new_val, old_val, smooth_factor):
return old_val * smooth_factor + new_val * (1-smooth_factor)
val = 0
try:
val = old_val * smooth_factor + new_val * (1-smooth_factor)
except RuntimeWarning:
print(f'RuntimeWarning... old_val={old_val} new_val={new_val} smooth_factor={smooth_factor}')
return val

# %% ../nbs/01_putils.ipynb 26
def dot(inputs, weights):
Expand Down

0 comments on commit 9fe29ca

Please sign in to comment.