- initial commit

This commit is contained in:
2024-01-20 09:34:03 +01:00
commit 2e58d31a13
7 changed files with 189 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+6
View File
@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.11 (heart)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (heart)" project-jdk-type="Python SDK" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/heart.iml" filepath="$PROJECT_DIR$/.idea/heart.iml" />
</modules>
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+85
View File
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="887dbe21-b04f-45f3-bf88-b266f10ec84d" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/heart.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 3
}</component>
<component name="ProjectId" id="2ZkbivUsAFWKe8Jf28vIFcKkNzE" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Python.main.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"last_opened_file_path": "/home/jens/temp/RL-lab/rl_lab.py",
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
}
}]]></component>
<component name="RunManager">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="heart" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="SDK_NAME" value="Python 3.11 (heart)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-python-sdk-7a29c1521ef0-d3b881c8e49f-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-233.11799.298" />
</set>
</attachedChunks>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="887dbe21-b04f-45f3-bf88-b266f10ec84d" name="Changes" comment="" />
<created>1702969154178</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1702969154178</updated>
</task>
<servers />
</component>
</project>
+67
View File
@@ -0,0 +1,67 @@
# This is a sample Python script.
# Press Umschalt+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import numpy as np
def conv2d(z, h):
sub_shape = h.shape
view_shape = tuple(np.subtract(z.shape, sub_shape) + 1) + sub_shape
strides = z.strides + z.strides
sub_matrices = np.lib.stride_tricks.as_strided(z, view_shape, strides)
m = np.einsum('ij,klij->kl', h, sub_matrices)
return m
def state_expand(state, h, ovl_init=0):
hw, hh = h.shape
xw, xh = state.shape
ovl_w = int((hw-1)/2)
ovl_h = int((hh-1)/2)
z = np.ones((xw+2*ovl_w, xh+2*ovl_h))*ovl_init
z[ovl_w:ovl_w+xw, ovl_h:ovl_w+xh] = state
return z
def state_init_incremental(size):
state = np.zeros((size, size))
k = 1
m, n = np.shape(state)
for i in range(0, m):
for j in range(0, n):
state[i, j] = k
k += 1
return state
def state_init_constant(size, ic=0):
h = np.ones((size, size))*ic
return h
def h_init(s=1):
h = np.array([[1,1,1], [1,0,1], [1,1,1]])*s
return h
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
state = state_init_incremental(5)
state = state_init_constant(5, 0)
h = h_init(1.0/8)
print (h)
for i in range(0,10,1):
state[0, 0] = 0
if i == 0:
state[0, 0] = 1
state_ex = state_expand(state, h)
state = 0.5*state + 0.5*conv2d(state_ex, h)
print(state)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/