<p>It sounds like you are roughly interested in what is referred to as <em>neural network verification</em>. This field broadly consists of answering the question: given a range of possible inputs, what is the range of possible outputs from a neural network with a given set of weights? A few things to note:</p>
<ol>
<li><p>A neural network is essentially a complex, non-linear function. That is, it maps the input space to the output space. Defining an output range does not make sense except with respect to an input range. In your question you make no reference to the inputs, so your examples are flawed/incomplete.</p>
</li>
<li><p>In general, neural network verification is an emerging field with most published works being fairly recent (last 5-7 years). That being said, there are exact and approximate methods for fully connected networks with a variety of activation functions. I'll list a few such methods here:</p>
</li>
</ol>
<p><a href="https://arxiv.org/abs/2004.05519" rel="nofollow noreferrer">https://arxiv.org/abs/2004.05519</a> - MATLAB toolbox, but you could export your neural network in ONNX format and then use MATLAB for the verification/output range analysis.</p>
<p><a href="https://arxiv.org/abs/1804.10829" rel="nofollow noreferrer">https://arxiv.org/abs/1804.10829</a> - specifically for ReLU activation function.</p>
<p><a href="https://anwu1219.github.io/download/Marabou.pdf" rel="nofollow noreferrer">https://anwu1219.github.io/download/Marabou.pdf</a> with python API available here: <a href="https://github.com/NeuralNetworkVerification/Marabou" rel="nofollow noreferrer">https://github.com/NeuralNetworkVerification/Marabou</a></p>
<p>The field is still evolving so you may have to do some of the codings yourself rather than using pre-existing libraries in some cases, but these papers/ a search query for <em>neural network verification</em> should at least give you some ideas of where to start.</p>
Neural network with linear activation output. Calculate output range for each of the output neurons
<p>Let's assume I have a neural network like the following:</p>
<pre><code>model = keras.models.Sequential()
model.add(keras.layers.Dense(10, input_shape=(5,), activation='relu'))
model.add(keras.layers.Dense(4, activation='linear'))
</code></pre>
<p>With n output neurons with a linear activation function.</p>
<p>The training process is not important here, so we can take a look at the random weights that keras initialized using:</p>
<pre><code>model.weights 
</code></pre>
<p>Of course, in a real example, these weights should be adjusted in the training process.</p>
<p>Depending on these <code>model.weights</code>, each of the output neurons returns values in a range.</p>
<p>I would like to calculate this exact range.</p>
<p>Does keras offer any function to calculate it?</p>
<p>I built a flawed piece of code to make an approximation of it, using a loop and predicting random inputs. But this would not be really useful in a real example with much more inputs/neurons/weights.</p>
<p>Here a few examples trying to clarify my question (All of them assume that the input values are between and 1):</p>
<pre><code>model = keras.models.Sequential()
model.add(keras.layers.Dense(1, input_shape=(2,), 
          activation='linear', use_bias=False))

model.set_weights([np.array([1, 1]).reshape(2, 1)]) 
</code></pre>
<p>For the previous example the output neuron results would be between 0 and 2</p>
<pre><code>model.set_weights([np.array([-0.5, 1]).reshape(2, 1)])
</code></pre>
<p>For the previous example the output neuron results would be between -0.5 and 1</p>
<pre><code>model = keras.models.Sequential()
model.add(keras.layers.Dense(2, input_shape=(2,), activation='linear', use_bias=False))
model.add(keras.layers.Dense(1, activation='linear', use_bias=False))

model.set_weights([np.array([1, 1, 1, 1]).reshape(2,2), np.array([1, 1]).reshape(2,1)])
</code></pre>
<p>For the previous example, the output neuron results would be between <code>0</code> and <code>4</code></p>
<p>These are simplified examples. In a real scenario with a much complex network structure, activation functions, bias..... these ranges are not obvious to calculate.</p>