Example #1
0
def path_collider(vector, path):
    """adding a path to a vector"""
    path_copy = list(path)
    if not isinstance( vector, VectorDict):
        if len(vector):
            vector = tree_from_path( * ( vector + [ "weight" , 1 ] ))
        else:
            vector = VectorDict( VectorDict, dict() )
    current = vector
    while len(path) :
        current_key = path.pop(0)
        if current_key in current.keys():
            
            current = current[current_key]
            if current.get("weight", False):
                current["weight"]+=1
        else:
            path = [ current_key ] + path
            break
    if len(path):
        vector.add_path( path_copy + [ "weight" , 1 ] )
    return vector 
Example #2
0
    """
    phys = input_dict.get("physical", dict())
    rgb_vect = array( [ int(x) for x in bytearray.fromhex( 
        phys.get( "eye", "000000" ) )[0::1]
    ] )
    prefered_vect =  array([ int(x) for x in bytearray.fromhex(prefered_color)[0::1] ] )
    max_size = norm( prefered_vect ) * norm( rgb_vect ) 
    return  max_size > 0  and  ( 
                1.0 * sum( prefered_vect * rgb_vect)  / ( max_size )
            ) or -1


criterion_ponderation = VectorDict(float, dict( 
    eye = 1 ,
    fitness = 5,
    bankable = 4,
    extra = .5,
    not_too_expensive = .1
) )

norm_of_choice = criterion_ponderation.dot(criterion_ponderation)


for candidate,ldot in    map ( 
            lambda x :  [ 
                VectorDict(VectorDict,x) , criterion_ponderation.dot( 
                    criterion_ponderation * matrix( x ) 
                )
            ] , 
            data
        ) :