コード例 #1
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_derivfuncs_dims1():
    import ann

    x = np.zeros((2,2,2))
    y = np.zeros((2,2,2))
    MSE = ann.ERROR_MSE

    failed = False
    try:
        ann.get_deriv(MSE, x, y)
    except ValueError:
        failed = True

    assert failed, "Should not work with more than 2 dimensions"
コード例 #2
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_derivfuncs_dims1():
    import ann

    x = np.zeros((2, 2, 2))
    y = np.zeros((2, 2, 2))
    MSE = ann.ERROR_MSE

    failed = False
    try:
        ann.get_deriv(MSE, x, y)
    except ValueError:
        failed = True

    assert failed, "Should not work with more than 2 dimensions"
コード例 #3
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_derivfuncs_dims2():
    import ann

    # First, should fail if arrays differ in dimension
    x = np.zeros((2,2))
    y = np.zeros((3,3))
    MSE = ann.ERROR_MSE

    failed = False
    try:
        ann.get_deriv(MSE, x, y)
    except ValueError:
        failed = True

    assert failed, "Dimensions should not match!"
コード例 #4
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_derivfuncs_dims2():
    import ann

    # First, should fail if arrays differ in dimension
    x = np.zeros((2, 2))
    y = np.zeros((3, 3))
    MSE = ann.ERROR_MSE

    failed = False
    try:
        ann.get_deriv(MSE, x, y)
    except ValueError:
        failed = True

    assert failed, "Dimensions should not match!"
コード例 #5
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_derivfuncs_data1dlistsminimal():
    import ann

    rows, cols = 1, 1
    x = [0.0 for i in range(rows)]
    y = [2.0 for i in range(rows)]
    MSE = ann.ERROR_MSE

    error = ann.get_deriv(MSE, x, y)

    assert len(error.shape) == 1, "Should be one-dimensional result"
    assert error.shape[0] == rows, "Count should match row number"

    for e in error.ravel():
        assert 0.000001 > e - (2 - 0), "Error is incorrect"
コード例 #6
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_derivfuncs_data1d():
    import ann

    rows, cols = 5, 1
    x = np.zeros(rows)
    y = np.ones(rows) * 2
    MSE = ann.ERROR_MSE

    error = ann.get_deriv(MSE, x, y)

    assert len(error.shape) == 1, "Should be one-dimensional result"
    assert error.shape[0] == rows, "Count should match row number"

    for e in error.ravel():
        assert 0.000001 > e - (2 - 0), "Error is incorrect"
コード例 #7
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_derivfuncs_data1dlistsminimal():
    import ann

    rows, cols = 1, 1
    x = [0.0 for i in range(rows)]
    y = [2.0 for i in range(rows)]
    MSE = ann.ERROR_MSE

    error = ann.get_deriv(MSE, x, y)

    assert len(error.shape) == 1, "Should be one-dimensional result"
    assert error.shape[0] == rows, "Count should match row number"

    for e in error.ravel():
        assert 0.000001 > e - (2 - 0), "Error is incorrect"
コード例 #8
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_derivfuncs_data1d():
    import ann

    rows, cols = 5, 1
    x = np.zeros(rows)
    y = np.ones(rows) * 2
    MSE = ann.ERROR_MSE

    error = ann.get_deriv(MSE, x, y)

    assert len(error.shape) == 1, "Should be one-dimensional result"
    assert error.shape[0] == rows, "Count should match row number"

    for e in error.ravel():
        assert 0.000001 > e - (2 - 0), "Error is incorrect"
コード例 #9
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_surv_likelihood():
    import ann

    dim = (20,2)
    targets = np.ones(dim)
    censlvl=0.0
    for i in range(len(targets)):
        if np.random.uniform() < censlvl:
            targets[i, 1] = 0
    outputs = np.random.normal(1, 10, size=dim)

    #timesorting = outputs[:, 0].argsort()

    cens = targets[:, 1] < 1
    uncens = targets[:, 1] == 1

    errors = ann.get_error(ann.ERROR_SURV_LIKELIHOOD, targets, outputs)
    derivs = ann.get_deriv(ann.ERROR_SURV_LIKELIHOOD, targets, outputs)
コード例 #10
0
ファイル: test.py プロジェクト: spacecowboy/pysurvival-ann
def test_surv_likelihood():
    import ann

    dim = (20, 2)
    targets = np.ones(dim)
    censlvl = 0.0
    for i in range(len(targets)):
        if np.random.uniform() < censlvl:
            targets[i, 1] = 0
    outputs = np.random.normal(1, 10, size=dim)

    #timesorting = outputs[:, 0].argsort()

    cens = targets[:, 1] < 1
    uncens = targets[:, 1] == 1

    errors = ann.get_error(ann.ERROR_SURV_LIKELIHOOD, targets, outputs)
    derivs = ann.get_deriv(ann.ERROR_SURV_LIKELIHOOD, targets, outputs)