def script_compareHashWithToyExperiment(params):
    in_file = params.in_file;
    num_hash_tables_all = params.num_hash_tables_all;
    key_type = params.key_type;
    out_file_indices = params.out_file_indices;
    out_file_pres = params.out_file_pres;
    out_file_html = params.out_file_html;
    rel_path = params.rel_path;

    [features_test,features_train,labels_test,labels_train,_,_,indices,_]=pickle.load(open(in_file,'rb'));
    visualize.saveMatAsImage(indices,out_file_indices);    
    
    hammings=[];
    for out_file_pre,num_hash_tables in zip(out_file_pres,num_hash_tables_all):
        indices_hash = getIndicesHash(features_test,features_train,num_hash_tables,key_type);
        visualize.saveMatAsImage(indices_hash,out_file_pre+'.png');    
        hamming=util.getHammingDistance(indices,indices_hash);
        pickle.dump([indices_hash,indices,hamming],open(out_file_pre+'.p','wb'));

        hammings.append(np.mean(hamming));
    
    sizes = scipy.misc.imread(out_file_indices);
    sizes = sizes.shape

    im_files_html=[];
    captions_html=[];
    for idx,out_file_pre in enumerate(out_file_pres):
        out_file_curr=out_file_pre+'.png'
        key_str=str(key_type);
        key_str=key_str.replace('<type ','').replace('>','');
        caption_curr='NN Hash. Num Hash Tables: '+str(num_hash_tables_all[idx])+' '+'Hamming Distance: '+str(hammings[idx]);
        im_files_html.append([out_file_indices.replace(rel_path[0],rel_path[1]),out_file_curr.replace(rel_path[0],rel_path[1])])
        captions_html.append(['NN cosine',caption_curr]);

    visualize.writeHTML(out_file_html,im_files_html,captions_html,sizes[0]/2,sizes[1]/2);
Beispiel #2
0
def count(s, p, d):
    len_s = len(s)
    len_p = len(p)

    res = 0
    for x in range(len_s - len_p + 1):
        c = s[x:x + len_p]
        if getHammingDistance(p, c) <= d:
            res += 1
    return res
Beispiel #3
0
def d_row(p, s):
    k = len(p)
    minScore = k
    for i in range(len(s) - k + 1):
        match = s[i:i + k]
        d = getHammingDistance(p, match)
        if d < minScore:
            minScore = d
        if minScore == 0:
            break
    return minScore
def script_compareHashWithToyExperiment(params):
    in_file = params.in_file
    num_hash_tables_all = params.num_hash_tables_all
    key_type = params.key_type
    out_file_indices = params.out_file_indices
    out_file_pres = params.out_file_pres
    out_file_html = params.out_file_html
    rel_path = params.rel_path

    [
        features_test, features_train, labels_test, labels_train, _, _,
        indices, _
    ] = pickle.load(open(in_file, 'rb'))
    visualize.saveMatAsImage(indices, out_file_indices)

    hammings = []
    for out_file_pre, num_hash_tables in zip(out_file_pres,
                                             num_hash_tables_all):
        indices_hash = getIndicesHash(features_test, features_train,
                                      num_hash_tables, key_type)
        visualize.saveMatAsImage(indices_hash, out_file_pre + '.png')
        hamming = util.getHammingDistance(indices, indices_hash)
        pickle.dump([indices_hash, indices, hamming],
                    open(out_file_pre + '.p', 'wb'))

        hammings.append(np.mean(hamming))

    sizes = scipy.misc.imread(out_file_indices)
    sizes = sizes.shape

    im_files_html = []
    captions_html = []
    for idx, out_file_pre in enumerate(out_file_pres):
        out_file_curr = out_file_pre + '.png'
        key_str = str(key_type)
        key_str = key_str.replace('<type ', '').replace('>', '')
        caption_curr = 'NN Hash. Num Hash Tables: ' + str(
            num_hash_tables_all[idx]) + ' ' + 'Hamming Distance: ' + str(
                hammings[idx])
        im_files_html.append([
            out_file_indices.replace(rel_path[0], rel_path[1]),
            out_file_curr.replace(rel_path[0], rel_path[1])
        ])
        captions_html.append(['NN cosine', caption_curr])

    visualize.writeHTML(out_file_html, im_files_html, captions_html,
                        sizes[0] / 2, sizes[1] / 2)
Beispiel #5
0
def dContains(s, p, d):
    k = len(p)
    for i in range(len(s) - k + 1):
        if util.getHammingDistance(s[i:i + k], p) <= d:
            return True
    return False
Beispiel #6
0
from util import getHammingDistance

if __name__ == '__main__':
    t = raw_input()
    s = raw_input()
    d = int(raw_input())

    len_s = len(s)
    len_t = len(t)

    res = []
    for i in range(0, len_s - len_t + 1):
        ss = s[i:i + len_t]
        if getHammingDistance(t, ss) <= d:
            res.append(i)

    print ' '.join([str(x) for x in res])