Friday 20 March 2015

the map-to-topic and find-topic functions

The idea behind find-topic[op] is that given a collection of frequency lists, kets that change frequency drastically from list to list are the content, and those that have roughly invariant frequency (either very common like "the", or very rare) can be considered to contain less content. We measure frequency of a ket using normed-frequency-class function given in the last post.

Here is the python:
-- in the ket class:
  def find_topic(self,context,op):           
    return context.map_to_topic(self,op)

-- in the superposition class:
  def find_topic(self,context,op):           
    result = superposition()
    for x in self.data:
      result += context.map_to_topic(x,op)        # .drop_below(min) here too?
    r = result.normalize(100).coeff_sort()
    return r

-- in the new_context class:
  def map_to_topic(self,e,op,t=0):
    if type(op) == ket:
      op = op.label[4:]
    result = superposition()                                            
    for label in self.ket_rules_dict:
      if op in self.ket_rules_dict[label]:
        frequency_list = self.recall(op,label,True)                     
        value = normed_frequency_class(e,frequency_list)
        if value > t:                                                
          result.data.append(ket(label,value))    # "result += ket(label,value)" when swap in fast_superposition
    return result.normalize(100).coeff_sort()
I guess that is it. Though I suppose how the algo works, given the above python, is somewhat opaque. Examples in the next few posts.

No comments:

Post a Comment