Exemplo n.º 1
0
def test_nldsMartinDistance():
    """Test Martin distance computation for NLDS's.

    Config: 5 states, kernel centering
    """

    fileA = os.path.join(TESTBASE, "data/data1.txt")
    fileB = os.path.join(TESTBASE, "data/data2.txt")

    # load data files
    dataA, _ = loadDataFromASCIIFile(fileA)
    dataB, _ = loadDataFromASCIIFile(fileB)

    # configure kernels
    kpcaPA = KPCAParam()
    kpcaPA._kPar = RBFParam()
    kpcaPA._kPar._kCen = True
    kpcaPA._kFun = rbfK

    kpcaPB = KPCAParam()
    kpcaPB._kPar = RBFParam()
    kpcaPB._kPar._kCen = True
    kpcaPB._kFun = rbfK

    nldsA = NonLinearDS(5, kpcaPA, False)
    nldsB = NonLinearDS(5, kpcaPB, False)

    # estimate NLDS's
    nldsA.suboptimalSysID(dataA)
    nldsB.suboptimalSysID(dataB)

    # compute distances A<->A, A<->B
    dAA = nldsMartinDistance(nldsA, nldsA, 20)
    dAB = nldsMartinDistance(nldsA, nldsB, 20)

    truth = np.genfromtxt(os.path.join(TESTBASE,
      "data/nldsMartinDistanceData1Data2.txt" ))
    np.testing.assert_almost_equal(dAA, 0, 2)
    np.testing.assert_almost_equal(dAB, truth, 2)
Exemplo n.º 2
0
def main(argv=None):
    if argv is None: 
        argv = sys.argv

    parser = OptionParser(add_help_option=False)
    parser.add_option("-s", dest="model1File")
    parser.add_option("-r", dest="model2File") 
    parser.add_option("-n", dest="iterations", type="int", default=20)
    parser.add_option("-h", dest="shoHelp", action="store_true", default=False)
    parser.add_option("-v", dest="verbose", action="store_true", default=False) 
    opt, args = parser.parse_args()
    
    if opt.shoHelp: 
        usage()
    
    with open(opt.model1File, 'r') as fid:
        kdt1 = pickle.load(fid)
    with open(opt.model2File, 'r') as fid:
        kdt2 = pickle.load(fid)

    martinD = dsdist.nldsMartinDistance(kdt1, kdt2, opt.iterations)
    dsinfo.info('D(%s,%s) = %.4f' % (opt.model1File, opt.model2File, martinD))
Exemplo n.º 3
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    parser = OptionParser(add_help_option=False)
    parser.add_option("-s", dest="model1File")
    parser.add_option("-r", dest="model2File")
    parser.add_option("-n", dest="iterations", type="int", default=20)
    parser.add_option("-h", dest="shoHelp", action="store_true", default=False)
    parser.add_option("-v", dest="verbose", action="store_true", default=False)
    opt, args = parser.parse_args()

    if opt.shoHelp:
        usage()

    with open(opt.model1File, 'r') as fid:
        kdt1 = pickle.load(fid)
    with open(opt.model2File, 'r') as fid:
        kdt2 = pickle.load(fid)

    martinD = dsdist.nldsMartinDistance(kdt1, kdt2, opt.iterations)
    dsinfo.info('D(%s,%s) = %.4f' % (opt.model1File, opt.model2File, martinD))