Exemple #1
0
def psi(x, y, sm, sparm):
    """Return a feature vector describing pattern x and label y.
    
    This returns a sequence representing the feature vector describing
    the relationship between a pattern x and label y.  What psi is
    depends on the problem.  Its particulars are described in the
    Tsochantaridis paper.  The return value should be either a support
    vector object of the type returned by svmlight.create_svector, or
    a list of such objects."""
    # In the case of binary classification, psi is just the class (+1
    # or -1) times the feature vector for x, including that special
    # constant bias feature we pretend that we have.
    import svmlight
    thePsi = [0.5*y*i for i in x]
    thePsi.append(0.5*y) # Pretend as though x had an 1 at the end.
    return svmlight.create_svector(thePsi)
def psi(x, y, sm, sparm):
    """Return a feature vector describing pattern x and label y.
    
    This returns a sequence representing the feature vector describing
    the relationship between a pattern x and label y.  What psi is
    depends on the problem.  Its particulars are described in the
    Tsochantaridis paper.  The return value should be either a support
    vector object of the type returned by svmlight.create_svector, or
    a list of such objects."""

    #we ignore the type of y in this function
    y2,y_type = y;

    qid, feature_id_list, feature_value_list = x
    # Add in the weight for the bias term for each example.
    thepsi = {}
    for i,label in enumerate(y2):
        for k,v in itertools.izip(feature_id_list[i],feature_value_list[i]):
            thepsi[k] = thepsi.get(k,0.0) + label*v
    intermediate_psi = sorted(thepsi.items())
    return svmlight.create_svector(intermediate_psi)
Exemple #3
0
def psi(x, y, sm, sparm):
    # Just increment the feature index to the appropriate stack position.
    return svmlight.create_svector([(f+(y-1)*sparm.num_features,v)
                                    for f,v in x])