# -*- coding:utf-8 -*-
import numpy as np
def dropout(X, keep_prob = 0.5):
"""
:param X: input
:param keep_prob:
:return:
"""
D = np.random.rand(X.shape[0], X.shape[1]) # step1: initialize matrix d
D = D < keep_prob # step2: convert entries of d
X = X * D # step3: shut down some neuron
X = X/keep_prob #step4: scale the value of neuron
return X
'''
numpy.random.rand(do,d1, ...,dn)
create an array of the given shape and populate it with random samples from a uniform distribution over[0,1)
'''
# 带 dropout的前向后向传播
def forward_propogation_with_dropout(X, parameters, keep_prob = 0.5):
"""
Implemente the forward propagation : LINERE->