示例#1
0
文件: test_GDL.py 项目: cenit/GDL
def test_invalid_code():
    code = '''
    PRO invalid_code
       this_is_invalid
    end
    '''
    with GDLFile(code) as name:
        with pytest.raises(GDL.error):
            GDL.pro(name)
示例#2
0
文件: test_GDL.py 项目: zj0324/gdl
def test_invalid_code():
    code = '''
    PRO invalid_code
       this_is_invalid
    end
    '''
    with GDLFile(code) as name:
        with pytest.raises(GDL.error):
            GDL.pro(name)
示例#3
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_invalid_code():
    '''Call a function with some invalid GDL code'''

    code = '''
    PRO invalid_code
       this_is_invalid
    end
    '''
    with GDLFile(code) as name:
        with pytest.raises(GDL.error):
            GDL.pro(name, ret)
示例#4
0
文件: test-GDL.py 项目: cenit/GDL
def test_invalid_code():
    '''Call a function with some invalid GDL code'''
    
    code = '''
    PRO invalid_code
       this_is_invalid
    end
    '''
    with GDLFile(code) as name:
        with pytest.raises(GDL.error):
            GDL.pro(name)
示例#5
0
文件: test_GDL.py 项目: cenit/GDL
def test_pro_user():
    '''Call the setenv procedure via a user defined procedure'''

    code = '''
    pro USER_SETENV, key, val
      SETENV, key + '=' + val
      print, GETENV(key)
    end
    '''
    s = 'blabla'
    with GDLFile(code) as name:
        GDL.pro(name, 'T1', s)
示例#6
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_pro_user():
    '''Call the setenv procedure via a user defined procedure'''

    code = '''
    pro USER_SETENV, key, val
      SETENV, key + '=' + val
      print, GETENV(key)
    end
    '''
    s = 'blabla'
    with GDLFile(code) as name:
        GDL.pro(name, 'T1', s)
示例#7
0
文件: test_GDL.py 项目: zj0324/gdl
def test_script():
    '''Call a simple script that writes a short file'''

    fname = os.tmpnam()
    scriptname = os.tmpnam()
    arg = 'Hello, world!'
    code = '''openw, 5, '{0}'
    printf, 5, '{1}'
    close, 5
    '''
    with GDLFile(code.format(fname, arg)) as script:
        GDL.script(script)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == ret
示例#8
0
文件: test_GDL.py 项目: cenit/GDL
def test_script():
    '''Call a simple script that writes a short file'''
    
    fname = os.tmpnam()
    scriptname = os.tmpnam()
    arg = 'Hello, world!'
    code = '''openw, 5, '{0}'
    printf, 5, '{1}'
    close, 5
    '''
    with GDLFile(code.format(fname, arg)) as script:
        GDL.script(script)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == ret
示例#9
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_pro_setvalue(dtype):
    '''Call a user defined procedure that replaces the values of an array with
    its sinus.

    Note that GDL does not support changes in the arguments, so this test is
    expected to fail'''

    code = '''pro SETVALUE, arg
    arg[*] = sin(arg)
    end
    '''
    with GDLFile(code) as name:
        arg = numpy.arange(-10, 10., 1.1).astype(dtype)
        ret = numpy.copy(arg)
        GDL.pro(name, ret)
        for a, r in zip(numpy.sin(arg), ret):
            assert a == r
示例#10
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_script():
    '''Call a simple script that writes a short file'''

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        fname = tempfile.mkstemp()[1]
        scriptname = tempfile.mkstemp()[1]
    arg = 'Hello, world!'
    code = '''openw, 5, '{0}'
    printf, 5, '{1}'
    close, 5
    '''
    with GDLFile(code.format(fname, arg)) as script:
        GDL.script(script)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == ret
示例#11
0
文件: test_GDL.py 项目: cenit/GDL
def test_pro_arg_pass(arg):
    '''Call a user defined procedure that stores the value for different
    data types in a file'''
    
    code = '''
    PRO pro_arg_pass, fname, arg
      openw, 5, fname
      printf, 5, arg
      close, 5
    end
    '''
    with GDLFile(code) as name:
        fname = os.tmpnam()
        GDL.pro(name, fname, arg)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == arg.__class__(ret)
示例#12
0
文件: test_GDL.py 项目: zj0324/gdl
def test_pro_arg_pass(arg):
    '''Call a user defined procedure that stores the value for different
    data types in a file'''

    code = '''
    PRO pro_arg_pass, fname, arg
      openw, 5, fname
      printf, 5, arg
      close, 5
    end
    '''
    with GDLFile(code) as name:
        fname = os.tmpnam()
        GDL.pro(name, fname, arg)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == arg.__class__(ret)
示例#13
0
文件: test_GDL.py 项目: cenit/GDL
def test_pro_setvalue(dtype):
    '''Call a user defined procedure that replaces the values of an array with
    its sinus.

    Note that GDL does not support changes in the arguments, so this test is
    expected to fail'''

    
    code = '''pro SETVALUE, arg
    arg[*] = sin(arg)
    end
    '''
    with GDLFile(code) as name:
        arg = numpy.arange(-10, 10., 1.1).astype(dtype)
        ret = numpy.copy(arg)
        GDL.pro(name, ret)
        for a, r in zip(numpy.sin(arg), ret):
            assert a == r
示例#14
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_function_arg_pass_return(arg):
    '''Call a function that just returns its argument, with different data types'''

    code = '''
    function ARG_PASS_RETURN, arg
      return, arg
    end
    '''
    with GDLFile(code) as name:
        assert numpy.all(GDL.function(name, arg) == arg)
示例#15
0
文件: test_GDL.py 项目: cenit/GDL
def test_function_arg_pass_return(arg):
    '''Call a function that just returns its argument, with different data types'''

    code = '''
    function ARG_PASS_RETURN, arg
      return, arg
    end
    '''
    with GDLFile(code) as name:
        assert numpy.all(GDL.function(name, arg) == arg)
示例#16
0
文件: test_GDL.py 项目: cenit/GDL
def test_function_user():
    '''Call the sinus function via a user defined function'''

    code = '''
    function MYSIN, arg
      return, sin(arg)
    end
    '''
    with GDLFile(code) as name:
        assert GDL.function(name, 1.0) == math.sin(1.0)
示例#17
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_function_user():
    '''Call the sinus function via a user defined function'''

    code = '''
    function MYSIN, arg
      return, sin(arg)
    end
    '''
    with GDLFile(code) as name:
        assert GDL.function(name, 1.0) == math.sin(1.0)
示例#18
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_pro_arg_pass(arg):
    '''Call a user defined procedure that stores the value for different
    data types in a file'''

    code = '''
    PRO pro_arg_pass, fname, arg
      openw, 5, fname
      printf, 5, arg
      close, 5
    end
    '''
    with GDLFile(code) as name:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            fname = tempfile.mkstemp()[1]
        GDL.pro(name, fname, arg)
        ret = open(fname).read().strip()
        os.unlink(fname)
        assert arg == arg.__class__(ret)
示例#19
0
    fea, labels = loadData.load_coil100()    # K=25 u=100 v=0.1
    print("data_set = COIL100    data.shape =", fea.shape)

    print("------ Normalizing data ------")
    # fea = tool.data_Normalized(fea)
    Normalizer = MinMaxScaler()
    Normalizer.fit(fea)
    fea = Normalizer.transform(fea)

    # u = 100
    # dist = tool.rank_dis_c(fea, u)
    dist = tool.rank_order_dis(fea)

    group_number = len(np.unique(labels))
    K = 25    # the number of nearest neighbors for KNN graph
    v = 0.1

    print("------ Clustering ------")
    start = time.time()
    labels_pred = GDL.gdl(dist, group_number, K, v, True)
    end = time.time()
    print("time =", end - start)

    NMI = measure.NMI(labels, labels_pred)
    print("NMI =", NMI)
    ACC = measure.ACC(labels, labels_pred)
    print("ACC =", ACC)
    precision_score = measure.precision_score(labels, labels_pred)
    print("precision_score =", precision_score)
示例#20
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_function_internal():
    '''Call the internal sin() function'''

    assert GDL.function('sin', 1.0) == math.sin(1.0)
示例#21
0
文件: test_GDL.py 项目: cenit/GDL
def test_function_internal():
    '''Call the internal sin() function'''
    
    assert GDL.function('sin', 1.0) == math.sin(1.0)
示例#22
0
文件: test_GDL.py 项目: cenit/GDL
def test_pro_internal():
    '''Call the internal setenv procedure'''
    
    s = 'blabla'
    GDL.pro('setenv', 'T1=' + s)
示例#23
0
    Normalizer = MinMaxScaler()
    Normalizer.fit(fea)
    fea = Normalizer.transform(fea)

    # dist = tool.rank_dis_c(fea)
    # dist = dist - np.diag(np.diag(dist))
    print("------ Clustering ------")
    start = time.time()
    dist = cdist(fea, fea)
    groupNumber = len(np.unique(labels))
    K = 15  # the number of nearest neighbors for KNN graph
    a = 10
    # a = 10
    # cl = AGDL.AGDL(dist, groupNumber, K, v)

    # cluster = AGDL.AGDL(fea, dist, groupNumber, K, 5, a)
    # labels_pred = np.zeros(len(labels), dtype='i')
    # for i in range(len(cluster)):
    #     for j in range(len(cluster[i])):
    #         labels_pred[cluster[i][j]] = i

    labels_pred = GDL.gdl(dist, groupNumber, K, a, True)
    end = time.time()
    print("time =", end - start)

    print("------ Computing performance measure ------")
    NMI = measure.NMI(labels, labels_pred)
    print("NMI =", NMI)
    ACC = measure.ACC(labels, labels_pred)
    print("ACC =", ACC)
示例#24
0
文件: test-GDL.py 项目: pjb7687/gdl
def test_pro_internal():
    '''Call the internal setenv procedure'''

    s = 'blabla'
    GDL.pro('setenv', 'T1=' + s)