sequence function: normed-frequency-class

    description:
        normed-frequency-class(e, X)
        implement the normed frequency class equation
        where: e is a ket, X is a superposition, and the result is in [0,1]
        1 for exact match, 0 for not in set, values in between otherwise
        
        if all coeffs in X are equal, it gives 1 for membership, and 0 for non-membership
        if the coeffs are not all equal, then it has fuzzier properties

        this function is the back-end to the map-to-topic function
        and works particularly well when X is a frequency list
        
    the algorithm:
        drop all elements <= 0 from X
        smallest = the min coeff in X
        largest = the max coeff in X
        f = the value of e.label in X
        
        if largest <= 0 or f <= 0:
            return 0
        fc_max = math.floor(0.5 - math.log(smallest / largest, 2)) + 1
        return 1 - math.floor(0.5 - math.log(f / largest, 2)) / fc_max
        
    examples:
        -- all coeffs in X equal:
        -- b is a member of |a> + |b> + |c> + |d> + |e>
        normed-frequency-class(|b>, |a> + |b> + |c> + |d> + |e>)
            |number: 1.0>

        -- all coeffs in X equal:
        -- c is a member of 7.2 |a> + 7.2 |b> + 7.2 |c> + 7.2 |d>
        normed-frequency-class(|c>, 7.2 |a> + 7.2 |b> + 7.2 |c> + 7.2 |d>)
            |number: 1.0>

        -- e is not a member of |a> + |b> + |c>
        normed-frequency-class(|e>, |a> + |b> + |c>)
            |number: 0>


        -- a "not all coeffs equal" example:
        -- consider: 
        smooth[0.5]^5 |10>
            0.001|7.5> + 0.01|8> + 0.044|8.5> + 0.117|9> + 0.205|9.5> + 0.246|10> + 0.205|10.5> + 0.117|11> + 0.044|11.5> + 0.01|12> + 0.001|12.5>

        -- this has this shape:
        bar-chart[40] smooth[0.5]^5 |10>
            ----------
            7.5  :
            8    : |
            8.5  : |||||||
            9    : |||||||||||||||||||
            9.5  : |||||||||||||||||||||||||||||||||
            10   : ||||||||||||||||||||||||||||||||||||||||
            10.5 : |||||||||||||||||||||||||||||||||
            11   : |||||||||||||||||||
            11.5 : |||||||
            12   : |
            12.5 :
            ----------

        -- now see the results:
        fc |*> #=> round[3] frequency-class(|_self>, smooth[0.5]^5 |10>)
        nfc |*> #=> round[3] normed-frequency-class(|_self>, smooth[0.5]^5 |10>)
        table[number, fc, nfc] range(|6>, |14>, |0.5>)
            +--------+----+-------+
            | number | fc | nfc   |
            +--------+----+-------+
            | 6      | 9  | 0     |
            | 6.5    | 9  | 0     |
            | 7      | 9  | 0     |
            | 7.5    | 8  | 0.111 |
            | 8      | 5  | 0.444 |
            | 8.5    | 2  | 0.778 |
            | 9      | 1  | 0.889 |
            | 9.5    | 0  | 1.0   |
            | 10     | 0  | 1.0   |
            | 10.5   | 0  | 1.0   |
            | 11     | 1  | 0.889 |
            | 11.5   | 2  | 0.778 |
            | 12     | 5  | 0.444 |
            | 12.5   | 8  | 0.111 |
            | 13     | 9  | 0     |
            | 13.5   | 9  | 0     |
            | 14     | 9  | 0     |
            +--------+----+-------+

    see also:
        frequency-class, map-to-topic

Home