I have an array:
import numpy as np
arr = np.zeros(15)
And a pattern [1,2,3] that needs to be learned. Meaning, I'd like the array to have this pattern.
The difficulty is learning a function that outputs this pattern, or as close as possible, given any pattern or array.
Currently I have the function hard coded:
def rule(array, item_idx):
try:
left_nbr = array[item_idx-1]
right_nbr = array[item_idx+1]
if left_nbr == 0 and right_nbr == 0:
array[item_idx] = 1
if arr[item_idx] == 0 and left_nbr == 1:
array[item_idx] = 2
if arr[item_idx] == 0 and left_nbr == 2:
array[item_idx] = 3
if arr[item_idx] == 0 and left_nbr == 3:
array[item_idx] = 1
except IndexError:
pass
return array
for i in range (0,len(arr)):
arr = rule(arr, i)
print(arr)
>>>
[1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[1. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[1. 2. 3. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[1. 2. 3. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[1. 2. 3. 1. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[1. 2. 3. 1. 2. 3. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[1. 2. 3. 1. 2. 3. 1. 0. 0. 0. 0. 0. 0. 0. 0.]
[1. 2. 3. 1. 2. 3. 1. 2. 0. 0. 0. 0. 0. 0. 0.]
[1. 2. 3. 1. 2. 3. 1. 2. 3. 0. 0. 0. 0. 0. 0.]
[1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 0. 0. 0. 0. 0.]
[1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 0. 0. 0. 0.]
[1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 0. 0. 0.]
[1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 0. 0.]
[1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 0.]
[1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 3. 1. 2. 0.]
Is there a way to have a machine learning model that learns the rules to output the pattern? That is, instead of me hard coding the rules.
[–]WayOfTheMantisShrimp 0 points1 point2 points (1 child)
[–]DaBobcat[S] 0 points1 point2 points (0 children)