def node_activation(weighted_sum): return 1.0 / (1.0 + np.exp(-1 * weighted_sum)) def forward_propagate(network, inputs): layer_inputs = list(inputs) # start with the input layer as the input to the first hidden layer for layer in network: layer_data = network[layer] layer_outputs = [] for layer_node in layer_data: node_data = layer_data[layer_node] # compute the weighted sum and the output of each node at the same time node_output = node_activation(compute_weighted_sum(layer_inputs, node_data['weights'], node_data['bias'])) layer_outputs.append(np.around(node_output[0], decimals=4)) if layer != 'output': print('The outputs of the nodes in hidden layer number {} is {}'.format(layer.split('_')[1], layer_outputs)) layer_inputs = layer_outputs # set the output of this layer to be the input to next layer network_predictions = layer_outputs return network_predictions
plt.figure(facecolor='w') plt.plot(xx, tempinf, label="Temps inf") plt.xlabel("Abscisse x de la barre (m)") plt.ylabel("Température (K)") plt.title("Diffusion de la chaleur dans une barre") n1, n2 = 5, 8 theta1, theta2 = 50, 100 temp1 = np.sin(2*pi*n1*(xx+a)/2/(b+a)) temp2 = np.sin(2*pi*n2*(xx+a)/2/(b+a)) temp0 = tempinf + theta1*temp1 + theta2*temp2 plt.plot(xx, temp0, label="Temps 0") T = 60 temp1 *= np.exp(-(pi*n1/(b+a))**2*sigma**2*T/2) temp2 *= np.exp(-(pi*n2/(b+a))**2*sigma**2*T/2) tempT = tempinf + theta1*temp1 + theta2*temp2 plt.plot(xx, tempT, label="Temps T = "+'{}'.format(T)+' s') plt.legend(loc="best") #%% # calcul de la température au point x en date t # choix du point x x = 0 #temperature exacte en point x temp1 = np.sin(2*pi*n1*(x+a)/2/(b+a)) temp2 = np.sin(2*pi*n2*(x+a)/2/(b+a)) temp1 *= np.exp(-(pi*n1/(b+a))**2*sigma**2*T/2) temp2 *= np.exp(-(pi*n2/(b+a))**2*sigma**2*T/2)