Exemplo n.º 1
0
def find_most_violated_constraint_margin(problem, gt, model, sparm):
    """Return ybar associated with x's most violated constraint.

    The find most violated constraint function for margin rescaling.
    The default behavior is that this returns the value from the
    general find_most_violated_constraint function."""

    assert(isinstance(problem, manhattan_utils.ManhattanProblem))
    assert(isinstance(gt, manhattan_utils.ManhattanSolution))

    data_weights,T = diagonal.unpack_weights(list(model.w))
    data_terms = path.compute_data_terms(problem.F, data_weights)
    loss_terms = gt.compute_loss_terms(LossFunc)
    A = data_terms + loss_terms
    est_states,est_orients = diagonal.solve(A, T)
    hyp = manhattan_utils.ManhattanSolution(problem, est_states, est_orients)

    print '\nFinding most violated constraint'
    print '  w: ',list(model.w)
    print '  data w: ',data_weights
    print '  transition:\n',T
    print '  true y: ',gt.ys
    print '  classified ybar: ',hyp.ys
    print '  feature(true y): ',path.compute_path_features(problem.F, gt.pair)
    print '  feature(ybar): ',path.compute_path_features(problem.F, hyp.pair)
    print '  loss: ',gt.compute_loss(hyp, LossFunc)

    return hyp
Exemplo n.º 2
0
def find_most_violated_constraint_margin(problem, gt, model, sparm):
    """Return ybar associated with x's most violated constraint.

    The find most violated constraint function for margin rescaling.
    The default behavior is that this returns the value from the
    general find_most_violated_constraint function."""

    assert (isinstance(problem, manhattan_utils.ManhattanProblem))
    assert (isinstance(gt, manhattan_utils.ManhattanSolution))

    data_weights, T = diagonal.unpack_weights(list(model.w))
    data_terms = path.compute_data_terms(problem.F, data_weights)
    loss_terms = gt.compute_loss_terms(LossFunc)
    A = data_terms + loss_terms
    est_states, est_orients = diagonal.solve(A, T)
    hyp = manhattan_utils.ManhattanSolution(problem, est_states, est_orients)

    print '\nFinding most violated constraint'
    print '  w: ', list(model.w)
    print '  data w: ', data_weights
    print '  transition:\n', T
    print '  true y: ', gt.ys
    print '  classified ybar: ', hyp.ys
    print '  feature(true y): ', path.compute_path_features(problem.F, gt.pair)
    print '  feature(ybar): ', path.compute_path_features(problem.F, hyp.pair)
    print '  loss: ', gt.compute_loss(hyp, LossFunc)

    return hyp
Exemplo n.º 3
0
def classify_example(problem, model, sparm):
    """Given a pattern x, return the predicted label."""

    data_weights,T = diagonal.unpack_weights(list(model.w))
    A = path.compute_data_terms(problem.F, data_weights)
    hyp_path,hyp_orients = diagonal.solve(A, T)
    return manhattan_utils.ManhattanSolution(problem, hyp_path, hyp_orients)
Exemplo n.º 4
0
def classify_example(problem, model, sparm):
    """Given a pattern x, return the predicted label."""

    data_weights, T = diagonal.unpack_weights(list(model.w))
    A = path.compute_data_terms(problem.F, data_weights)
    hyp_path, hyp_orients = diagonal.solve(A, T)
    return manhattan_utils.ManhattanSolution(problem, hyp_path, hyp_orients)
def find_most_violated_constraint_margin(F, y, model, sparm):
    """Return ybar associated with x's most violated constraint.

    The find most violated constraint function for margin rescaling.
    The default behavior is that this returns the value from the
    general find_most_violated_constraint function."""

    if len(y) != 2:
        raise Exception('y should be a pair (states,orients)')

    data_weights, T = diagonal.unpack_weights(list(model.w))
    states, orients = y
    A = path.compute_loss_augmented_terms(F, data_weights, states, path.L2)
    ybar = diagonal.solve(A, T)

    if len(ybar) != 2:
        raise Exception('ybar should be a pair (states,orients)')

    print '\nFinding most violated constraint'
    print '  w: ', list(model.w)
    print '  data w: ', data_weights
    print '  transition:\n', T
    print '  true y: ', y
    print '  classified ybar: ', ybar
    print '  feature(true y): ', path.compute_path_features(F, y)
    print '  feature(ybar): ', path.compute_path_features(F, ybar)
    print '  loss: ', path.compute_loss(y[0], ybar[0], path.L2)

    return ybar
def find_most_violated_constraint_margin(F, y, model, sparm):
    """Return ybar associated with x's most violated constraint.

    The find most violated constraint function for margin rescaling.
    The default behavior is that this returns the value from the
    general find_most_violated_constraint function."""

    if len(y) != 2:
        raise Exception('y should be a pair (states,orients)')

    data_weights,T = diagonal.unpack_weights(list(model.w))
    states,orients = y
    A = path.compute_loss_augmented_terms(F, data_weights, states, path.L2)
    ybar = diagonal.solve(A,T)

    if len(ybar) != 2:
        raise Exception('ybar should be a pair (states,orients)')

    print '\nFinding most violated constraint'
    print '  w: ',list(model.w)
    print '  data w: ',data_weights
    print '  transition:\n',T
    print '  true y: ',y
    print '  classified ybar: ',ybar
    print '  feature(true y): ',path.compute_path_features(F,y)
    print '  feature(ybar): ',path.compute_path_features(F,ybar)
    print '  loss: ',path.compute_loss(y[0], ybar[0], path.L2)

    return ybar
def classify_example(F, model, sparm):
    """Given a pattern x, return the predicted label."""

    data_weights, T = diagonal.unpack_weights(list(model.w))
    A = path.compute_data_terms(F, data_weights)
    return diagonal.solve(A, T)
def classify_example(F, model, sparm):
    """Given a pattern x, return the predicted label."""

    data_weights,T = diagonal.unpack_weights(list(model.w))
    A = path.compute_data_terms(F, data_weights)
    return diagonal.solve(A, T)