Esempio n. 1
0
  def __full_embedding_update(self,resource,args):
    verbose = False

    n = resource.get('n')
    d = resource.get('d')
    S = resource.get_list('S')

    X_old = numpy.array(resource.get('X'))
    # set maximum time allowed to update embedding
    t_max = 5.0
    epsilon = 0.00001 # a relative convergence criterion, see computeEmbeddingWithGD documentation
    mu = .05


    emp_loss_old,hinge_loss_old,log_loss_old = utilsCrowdKernel.getLoss(X_old,S)
    X,tmp = utilsCrowdKernel.computeEmbeddingWithEpochSGD(n,d,S,mu,max_num_passes=16,epsilon=0,verbose=verbose)
    t_start = time.time()
    X,emp_loss_new,hinge_loss_new,log_loss_new,acc = utilsCrowdKernel.computeEmbeddingWithGD(X,S,mu,max_iters=1,epsilon=epsilon,verbose=verbose)
    k = 1
    while (time.time()-t_start<.5*t_max) and (acc > epsilon):
      X,emp_loss_new,hinge_loss_new,log_loss_new,acc = utilsCrowdKernel.computeEmbeddingWithGD(X,S,mu,max_iters=2**k,epsilon=epsilon,verbose=verbose)
      k += 1
    emp_loss_new,hinge_loss_new,log_loss_new = utilsCrowdKernel.getLoss(X,S)
    if emp_loss_old < emp_loss_new:
      X = X_old

    tau = utilsCrowdKernel.getCrowdKernelTauDistribution(X,S,mu)

    resource.set('X',X.tolist())
    resource.set('tau',tau.tolist())
Esempio n. 2
0
  def __incremental_embedding_update(self,resource,args):   
    verbose = False
     
    n = resource.get('n')
    d = resource.get('d')
    S = resource.get_list('S')
    
    X = numpy.array(resource.get('X'))
    # set maximum time allowed to update embedding
    t_max = 1.0
    epsilon = 0.00001 # a relative convergence criterion, see computeEmbeddingWithGD documentation
    mu = .05

    t_start = time.time()
    X,emp_loss_new,hinge_loss_new,log_loss_new,acc = utilsCrowdKernel.computeEmbeddingWithGD(X,S,mu,epsilon=epsilon,max_iters=1)
    k = 1
    while (time.time()-t_start<.5*t_max) and (acc > epsilon):
      X,emp_loss_new,hinge_loss_new,log_loss_new,acc = utilsCrowdKernel.computeEmbeddingWithGD(X,S,mu,max_iters=2**k, epsilon=epsilon, verbose=verbose)
      k+=1

    tau = utilsCrowdKernel.getCrowdKernelTauDistribution(X,S,mu)

    resource.set('X',X.tolist())
    resource.set('tau',tau.tolist())