Example #1
0
def final_4d_metric(blocks_shifts_x):
    count = 0
    start = 0
    #embedding = numpy.zeros() #TODO : Preallocate memory for the embedding
    embedding_size = 4 * len(blocks_shifts_x) * sum(
        [R_vals[i] * possible_s[i] for i in xrange(len(possible_s))])
    embedding = numpy.zeros((embedding_size))
    for block_id in xrange(len(blocks_shifts_x)):
        for s_id in xrange(len(blocks_shifts_x[block_id])):
            count += 1
            #print count
            s = possible_s[s_id]
            I_arr = random_s_block[block_id][s_id]
            r = len(I_arr)
            for u in xrange(r):
                '''
              psi_u_all_v = []
              STR = []
              for j in xrange(s):
                  for ri in I_arr[u]:
                      try:
                          STR.append(blocks_shifts_x[block_id][s_id][j][ri])
                          psi_u_all_v.append(''.join(STR))
                      except:
                          print j, ri
                          raise
              '''
                psi_u_all_v = numpy.bincount([
                    randomness.custom_hash(
                        s, u, ''.join([
                            blocks_shifts_x[block_id][s_id][j][ri]
                            for ri in I_arr[u]
                        ])) for j in xrange(s)
                ])[1:] * 1.0 / (2 * r)
                embedding[start:(start + psi_u_all_v.shape[0])] = psi_u_all_v
                start += 4 * s
                '''
              if count == 1:
                  embedding = numpy.zeros((4*s))
                  embedding[:psi_u_all_v.shape[0]] = psi_u_all_v
              else:
                  temp = numpy.zeros((4*s))
                  temp[:psi_u_all_v.shape[0]] = psi_u_all_v
                  embedding = numpy.concatenate((embedding, temp))
              '''
    return embedding
def final_4d_metric(blocks_shifts_x):
  count = 0
  start = 0
  #embedding = numpy.zeros() #TODO : Preallocate memory for the embedding
  embedding_size = 4*len(blocks_shifts_x)*sum([R_vals[i]*possible_s[i] 
                                          for i in xrange(len(possible_s))])
  embedding = numpy.zeros((embedding_size))
  for block_id in xrange(len(blocks_shifts_x)):
      for s_id in xrange(len(blocks_shifts_x[block_id])):
          count += 1
          #print count
          s = possible_s[s_id]
          I_arr = random_s_block[block_id][s_id]
          r = len(I_arr)
          for u in xrange(r):
              '''
              psi_u_all_v = []
              STR = []
              for j in xrange(s):
                  for ri in I_arr[u]:
                      try:
                          STR.append(blocks_shifts_x[block_id][s_id][j][ri])
                          psi_u_all_v.append(''.join(STR))
                      except:
                          print j, ri
                          raise
              '''
              psi_u_all_v = numpy.bincount([
                      randomness.custom_hash(s, u, ''.join([blocks_shifts_x[block_id][s_id][j][ri] 
                                              for ri in I_arr[u]])) 
                                                  for j in xrange(s)])[1:] * 1.0 / (2 * r)
              embedding[start:(start+psi_u_all_v.shape[0])] = psi_u_all_v
              start += 4*s
              '''
              if count == 1:
                  embedding = numpy.zeros((4*s))
                  embedding[:psi_u_all_v.shape[0]] = psi_u_all_v
              else:
                  temp = numpy.zeros((4*s))
                  temp[:psi_u_all_v.shape[0]] = psi_u_all_v
                  embedding = numpy.concatenate((embedding, temp))
              '''
  return embedding
def final_4d_metric(blocks_shifts_x, R_vals, possible_s, random_s_block):
    count = 0
    start = 0
    embedding_size = 4 * len(blocks_shifts_x) * sum([R_vals[i] * possible_s[i]
                                                     for i in xrange(len(possible_s))])
    embedding = numpy.zeros((embedding_size))
    for block_id in xrange(len(blocks_shifts_x)):
        for s_id in xrange(len(blocks_shifts_x[block_id])):
            count += 1
            s = possible_s[s_id]
            I_arr = random_s_block[block_id][s_id]
            r = len(I_arr)
            for u in xrange(r):
                psi_u_all_v = numpy.bincount([randomness.custom_hash(s, u, ''.join([blocks_shifts_x[block_id][s_id][
                                             j][ri] for ri in I_arr[u]])) for j in xrange(s)])[1:] * 1.0 / (2 * r)
                embedding[start:(start + psi_u_all_v.shape[0])] = psi_u_all_v
                start += 4 * s

    return embedding
Example #4
0
def final_4d_metric(blocks_shifts_x):
  count = 0
  start = 0
  #embedding = numpy.zeros() #TODO : Preallocate memory for the embedding
  embedding_size = 4*len(blocks_shifts_x)*sum([R_vals[i]*possible_s[i] 
                                          for i in xrange(len(possible_s))])
  embedding = numpy.zeros((embedding_size))
  for block_id in xrange(len(blocks_shifts_x)):
      for s_id in xrange(len(blocks_shifts_x[block_id])):
          count += 1
          #print count
          s = possible_s[s_id]
          I_arr = random_s_block[block_id][s_id]
          r = len(I_arr)
          for u in xrange(r):
              psi_u_all_v = numpy.bincount([
                      randomness.custom_hash(s, u, ''.join([blocks_shifts_x[block_id][s_id][j][ri] 
                                              for ri in I_arr[u]])) 
                                                  for j in xrange(s)])[1:] * 1.0 / (2 * r)
              embedding[start:(start+psi_u_all_v.shape[0])] = psi_u_all_v
              start += 4*s
  return embedding