Beispiel #1
0
    def extract(self, item, query, target_keys=None):

        if target_keys:
            self.print_instance_difficulty(item, query)

        item_hrr = HRR(data=item)
        query_hrr = HRR(data=query)
        noisy_hrr = item_hrr.convolve(~query_hrr)
        return self.associate(noisy_hrr.v, target_keys)
Beispiel #2
0
    def extract(self, item, query, target_keys=None):

        if target_keys:
            self.print_instance_difficulty(item, query)

        item_hrr = HRR(data=item)
        query_hrr = HRR(data=query)
        noisy_hrr = item_hrr.convolve(~query_hrr)
        return self.associate(noisy_hrr.v, target_keys)
Beispiel #3
0
    def print_instance_difficulty(self, item, query, target_keys):

        if target_keys:
            # Print data about how difficult the current instance is
            correct_key = target_keys[0]

            item_hrr = HRR(data=item)
            query_hrr = HRR(data=query)
            noisy_hrr = item_hrr.convolve(~query_hrr)

            correct_hrr = HRR(data=self.index_vectors[correct_key])
            sim = noisy_hrr.compare(correct_hrr)
            dot = np.dot(noisy_hrr.v, correct_hrr.v)
            norm = np.linalg.norm(noisy_hrr.v)
            print "Statistics when extraction computed exactly:"
            print(
                "Cosine Similarity between extracted vector "
                "(before assoc) and correct index vector: "), sim
            print(
                "Dot product between extracted vector (before assoc) "
                "and correct index vector: "), dot
            print "Norm of extracted vector (before assoc): ", norm

            self.ideal_dot = dot

            hrrs = [(key, HRR(data=iv))
                    for key, iv in self.index_vectors.iteritems()
                    if key != correct_key]

            sims = [noisy_hrr.compare(h) for (k, h) in hrrs]
            dots = [np.dot(noisy_hrr.v, h.v) for (k, h) in hrrs]
            sim = max(sims)
            dot = max(dots)

            print "Cosine Similarity of closest incorrect index vector ", sim
            print "Dot product of closest incorrect index vector ", dot

            self.second_dot = dot
Beispiel #4
0
    def print_instance_difficulty(self, item, query, target_keys):

        if target_keys:
            # Print data about how difficult the current instance is
            correct_key = target_keys[0]

            item_hrr = HRR(data=item)
            query_hrr = HRR(data=query)
            noisy_hrr = item_hrr.convolve(~query_hrr)

            correct_hrr = HRR(data=self.index_vectors[correct_key])
            sim = noisy_hrr.compare(correct_hrr)
            dot = np.dot(noisy_hrr.v, correct_hrr.v)
            norm = np.linalg.norm(noisy_hrr.v)
            print "Statistics when extraction computed exactly:"
            print ("Cosine Similarity between extracted vector "
                   "(before assoc) and correct index vector: "), sim
            print ("Dot product between extracted vector (before assoc) "
                   "and correct index vector: "), dot
            print "Norm of extracted vector (before assoc): ", norm

            self.ideal_dot = dot

            hrrs = [(key, HRR(data=iv))
                    for key, iv in self.index_vectors.iteritems()
                    if key != correct_key]

            sims = [noisy_hrr.compare(h) for (k, h) in hrrs]
            dots = [np.dot(noisy_hrr.v, h.v) for (k, h) in hrrs]
            sim = max(sims)
            dot = max(dots)

            print "Cosine Similarity of closest incorrect index vector ", sim
            print "Dot product of closest incorrect index vector ", dot

            self.second_dot = dot