def computeEmbeddingWithEpochSGD(n,d,S,max_num_passes=0,max_norm=0,epsilon=0.01,a0=0.1,verbose=False):
    m = len(S)

    # norm of each object is equal to 1 in expectation
    X = randn(n,d)

    if max_num_passes==0:
        max_iters = 16*m
    else:
        max_iters = max_num_passes*m

    if max_norm==0:
        max_norm = 10.*d

    # pattern for computing gradient
    H = mat([[2.,0.,-2.],[ 0.,  -2.,  2.],[ -2.,  2.,  0.]])

    epoch_length = m
    a = a0
    t = 0
    t_e = 0

    # check losses
    if verbose:
        emp_loss,hinge_loss = getLoss(X,S)
        print "iter=%d,   emp_loss=%f,   hinge_loss=%f,   a=%f" % (0,emp_loss,hinge_loss,a)

    rel_max_grad = None
    while t < max_iters:
        t += 1
        t_e += 1

        # check epoch conditions, udpate step size
        if t_e % epoch_length == 0:
            a = a*0.5
            epoch_length = 2*epoch_length
            t_e = 0

            if epsilon>0 or verbose:
                # get losses
                emp_loss,hinge_loss = getLoss(X,S)

                # get gradient and check stopping-time statistics
                G,avg_grad_row_norm_sq,max_grad_row_norm_sq,avg_row_norm_sq = getGradient(X,S)
                rel_max_grad = sqrt( max_grad_row_norm_sq / avg_row_norm_sq )
                rel_avg_grad = sqrt( avg_grad_row_norm_sq / avg_row_norm_sq )

                if verbose:
                    print "iter=%d,   emp_loss=%f,   hinge_loss=%f,   rel_avg_grad=%f,   rel_max_grad=%f,   a=%f" % (t,emp_loss,hinge_loss,rel_avg_grad,rel_max_grad,a)

                if rel_max_grad < epsilon:
                    break

        # get random triplet unifomrly at random
        q = S[randint(m)]

        # take gradient step
        score = getTripletScore(X,q)
        if 1.-score>0:
            grad_partial = dot(H,X[q,:])
            X[q,:] = X[q,:] - a*grad_partial

        # # project back onto ball such that norm(X[i])<=max_norm
        for i in q:
            norm_i = norm(X[i])
            if norm_i>max_norm:
                X[i] = X[i] * (max_norm / norm_i)

    return X,rel_max_grad
SimpleAssetsManagerTest - Test save and load #1, save and load an image with metadata
dataset/ETHPy150Open nextml/NEXT/next/apps/PoolBasedTripletMDS/algs/RandomSampling/utilsMDS.py/computeEmbeddingWithEpochSGD--crossover with--dataset/ETHPy150Open Net-ng/kansha/tests/tests_assetsmanager.py/SimpleAssetsManagerTest.test_save_and_load