def calcMomentsMatlabEmpirical(params):
    """Top 3 alternatives 20 empirical moment conditions"""
    alpha = params[0]
    a = params[1:5]
    b = params[5:]
    p1 = alpha*a+(1-alpha)*b
    p21 = alpha*a[0]*a[1:]/(1-a[0])+(1-alpha)*b[0]*b[1:]/(1-b[0])
    p22 = alpha*a[1]*np.hstack((a[0],a[2:]))/(1-a[1])+(1-alpha)*b[1]*np.hstack((b[0],b[2:]))/(1-b[1])
    p23 = alpha*a[2]*np.hstack((a[:2],a[3]))/(1-a[2])+(1-alpha)*b[2]*np.hstack((b[:2],b[3]))/(1-b[2])
    p24 = alpha*a[3]*a[:3]/(1-a[3])+(1-alpha)*b[3]*b[:3]/(1-b[3])
    p3 = np.array([
        alpha*a[0]*a[2]*a[3]/(1-a[2])/(a[0]+a[1])+(1-alpha)*b[0]*b[2]*b[3]/(1-b[2])/(b[0]+b[1]),
        alpha*a[0]*a[1]*a[3]/(1-a[3])/(a[1]+a[2])+(1-alpha)*b[0]*b[1]*b[3]/(1-b[3])/(b[1]+b[2]),
        alpha*a[0]*a[1]*a[2]/(1-a[0])/(a[3]+a[2])+(1-alpha)*b[0]*b[1]*b[2]/(1-b[0])/(b[3]+b[2]),
        alpha*a[2]*a[1]*a[3]/(1-a[1])/(a[0]+a[3])+(1-alpha)*b[2]*b[1]*b[3]/(1-b[1])/(b[0]+b[3])
        ])
    return np.concatenate((p1,p21,p22,p23,p24,p3))
def calcMomentsMatlabEmpirical ( params ) : alpha = params [ 0 ] a = params [ 1 : 5 ] b = params [ 5 : ] p1 = alpha * a + ( 1 - alpha ) * b p21 = alpha * a [ 0 ] * a [ 1 : ] / ( 1 - a [ 0 ] ) + ( 1 - alpha ) * b [ 0 ] * b [ 1 : ] / ( 1 - b [ 0 ] ) p22 = alpha * a [ 1 ] * np . hstack ( ( a [ 0 ] , a [ 2 : ] ) ) / ( 1 - a [ 1 ] ) + ( 1 - alpha ) * b [ 1 ] * np . hstack ( ( b [ 0 ] , b [ 2 : ] ) ) / ( 1 - b [ 1 ] ) p23 = alpha * a [ 2 ] * np . hstack ( ( a [ : 2 ] , a [ 3 ] ) ) / ( 1 - a [ 2 ] ) + ( 1 - alpha ) * b [ 2 ] * np . hstack ( ( b [ : 2 ] , b [ 3 ] ) ) / ( 1 - b [ 2 ] ) p24 = alpha * a [ 3 ] * a [ : 3 ] / ( 1 - a [ 3 ] ) + ( 1 - alpha ) * b [ 3 ] * b [ : 3 ] / ( 1 - b [ 3 ] ) p3 = np . array ( [ alpha * a [ 0 ] * a [ 2 ] * a [ 3 ] / ( 1 - a [ 2 ] ) / ( a [ 0 ] + a [ 1 ] ) + ( 1 - alpha ) * b [ 0 ] * b [ 2 ] * b [ 3 ] / ( 1 - b [ 2 ] ) / ( b [ 0 ] + b [ 1 ] ) , alpha * a [ 0 ] * a [ 1 ] * a [ 3 ] / ( 1 - a [ 3 ] ) / ( a [ 1 ] + a [ 2 ] ) + ( 1 - alpha ) * b [ 0 ] * b [ 1 ] * b [ 3 ] / ( 1 - b [ 3 ] ) / ( b [ 1 ] + b [ 2 ] ) , alpha * a [ 0 ] * a [ 1 ] * a [ 2 ] / ( 1 - a [ 0 ] ) / ( a [ 3 ] + a [ 2 ] ) + ( 1 - alpha ) * b [ 0 ] * b [ 1 ] * b [ 2 ] / ( 1 - b [ 0 ] ) / ( b [ 3 ] + b [ 2 ] ) , alpha * a [ 2 ] * a [ 1 ] * a [ 3 ] / ( 1 - a [ 1 ] ) / ( a [ 0 ] + a [ 3 ] ) + ( 1 - alpha ) * b [ 2 ] * b [ 1 ] * b [ 3 ] / ( 1 - b [ 1 ] ) / ( b [ 0 ] + b [ 3 ] ) ] ) return np . concatenate ( ( p1 , p21 , p22 , p23 , p24 , p3 ) )
Top 3 alternatives 20 empirical moment conditions