commit 2e58d31a13824f376a20631ffc7d1b55b49f7aa6 Author: jens Date: Sat Jan 20 09:34:03 2024 +0100 - initial commit diff --git a/.idea/heart.iml b/.idea/heart.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/.idea/heart.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..46c3181 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..538e1b2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..84852cd --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + { + "associatedIndex": 3 +} + + + + + + + + + + + + + + + + + + + + + 1702969154178 + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..ceae4f4 --- /dev/null +++ b/main.py @@ -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/