-1

Given a d x d array, 1% of which contains the value 1 and all remaining locations contain the value 0. (e.g. a 128 x 128 array would have 164 values equal to 1 and 16220 values equal to 0). What would be a formula and/or proof for determining the minimum number of maxpooling operations with a 3x3 kernel, stride of 2, and same padding needed to guarantee that all values in the produced array are 1.

From repeated random trials (code for reproduction below) when d is 64, 128, 256, 512, 1024, or 2048, only 5 iterations of maxpooling are needed (whereas, d=32 -> 4 ops, d=16 -> 4 ops, d=8 -> 3 ops, d=4 -> 2 ops, etc.). However, a proof of mathematical certainty regarding these observations and formulation for the determination of the number of ops required for any value for d, would be beneficial.

import numpy as np
import tensorflow as tf

dim = 128
numPositions = dim*dim
randQuantity = 1-0.01
num_Initial = np.floor(numPositions*randQuantity)
maxPool = tf.keras.layers.MaxPool2D(pool_size=3, strides=2, padding='same')
finalIterations = []
for i in range(0, 1000):
    arr_Random = tf.reshape(tf.random.shuffle(tf.range(numPositions)), (1, dim, dim, 1))
    mask_Bool = tf.greater_equal(arr_Random, num_Initial)
    mask = tf.cast(mask_Bool, dtype=tf.float32)
    numInvalid = (1.0-mask.numpy()).sum()
    iterations = 0
    while numInvalid > 0:
        mask = maxPool(mask)
        iterations+=1
        numInvalid = (1.0-mask.numpy()).sum()
    finalIterations.append(iterations)
finalIterations = np.array(finalIterations)
print('Number of Operations Required to Ensure all 1s: ', finalIterations.max())
  • Welcome to SO. I am afraid this is not a *programming* question, hence it is actually off-topic here; please see the intro and NOTE in https://stackoverflow.com/tags/machine-learning/info – desertnaut Aug 10 '23 at 19:36

0 Answers0