def find_most_violated_constraint(x, y, sm, sparm):
    """Return ybar associated with x's most violated constraint.
    Returns the label ybar for pattern x corresponding to the most
    violated constraint according to SVM^struct cost function.  To
    find which cost function you should use, check sparm.loss_type for
    whether this is slack or margin rescaling (1 or 2 respectively),
    and check sparm.slack_norm for whether the slack vector is in an
    L1-norm or L2-norm in the QP (1 or 2 respectively).

    If this function is not implemented, this function is equivalent
    to 'classify(x, sm, sparm)'.  The optimality guarantees of
    Tsochantaridis et al. no longer hold, since this doesn't take the
    loss into account at all, but it isn't always a terrible
    approximation.  One still technically maintains the empirical
    risk bound condition, but without any regularization.
    score = classify_example(x,sm,sparm)
    discy, discny = y*score, -y*score + 1
    if discy > discny: return y
    return -y"""
    import os
    import os.path as path
    import jnius_config
    from jnius import autoclass
    global x_to_file_dictionary
    jnius_config.add_classpath(os.path.dirname(__file__) + "/*")
    print jnius_config.expand_classpath()

    System = autoclass('java.lang.System')
    print System.getProperty('java.class.path')

    IHT = autoclass('edu.albany.cs.ssvmCSD.IHT_Bridge')
    file_name = x_to_file_dictionary[str(x)]
    print 'constrain func:', file_name
    iht_ins = IHT(
        path.abspath(path.join(__file__, "../../../../../..")) + "/data/" +
        file_name)
    ybar = iht_ins.getX()
    print 'ybar:-', ybar
    return ybar
Exemple #2
0
def expand_classpath():
    return jnius_config.expand_classpath()
Exemple #3
0
from pprint import pprint

from unicorn.arm_const import UC_ARM_REG_PC

from oputil.opsim import MemoryMap
from oputil.opsim import firmware

# noinspection PyUnresolvedReferences
__all__ = ["ThumbSJ", "run_sj"]

cwd = os.getcwd()
os.chdir(r"C:\Program Files\Java\jdk1.8.0_171\jre\bin\server")

import jnius_config

jnius_config.expand_classpath()
jnius_config.add_classpath(
    r"C:\Users\EcmaXp\Dropbox\Projects\ThumbSJ\out\production\ThumbSJ")
jnius_config.options += [
    "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
    # "-XX:+UnlockDiagnosticVMOptions",
    # "-XX:+PrintCompilation",
    # "-XX:+PrintInlining",
]

# noinspection PyUnresolvedReferences
import java

with java:
    # noinspection PyUnresolvedReferences
    from kr.pe.ecmaxp.thumbsj import CPU, MemoryFlag, Handler
Exemple #4
0
import os
import os.path as path
import jnius_config

jnius_config.add_classpath(os.path.dirname(__file__) + "/*")
print jnius_config.expand_classpath()

from jnius import autoclass

System = autoclass('java.lang.System')
print System.getProperty('java.class.path')

IHT = autoclass('edu.albany.cs.ssvmCSD.IHT_Bridge')
iht_ins = IHT(
    path.abspath(path.join(__file__, "../../../../../..")) +
    "/data/APDM-GridData-100-precen_0.05-noise_0-numCC_1_0.txt")
print iht_ins.getX()