Пример #1
0
def test_concatenate(app_inst: ArrayApplication):
    axis = 1
    real_X, _ = BimodalGaussian.get_dataset(1000, 9)
    real_ones = np.ones(shape=(1000, 1))
    X = app_inst.array(real_X, block_shape=(100, 9))
    ones = app_inst.ones((1000, 1), (100, 1), dtype=X.dtype)
    X_concated = app_inst.concatenate([X, ones],
                                      axis=axis,
                                      axis_block_size=X.block_shape[axis])
    common.check_block_integrity(X_concated)
    real_X_concated = np.concatenate([real_X, real_ones], axis=axis)
    assert np.allclose(X_concated.get(), real_X_concated)

    real_X2 = np.random.random_sample(1000 * 17).reshape(1000, 17)
    X2 = app_inst.array(real_X2, block_shape=(X.block_shape[0], 3))
    X_concated = app_inst.concatenate([X, ones, X2],
                                      axis=axis,
                                      axis_block_size=X.block_shape[axis])
    common.check_block_integrity(X_concated)
    real_X_concated = np.concatenate([real_X, real_ones, real_X2], axis=axis)
    assert np.allclose(X_concated.get(), real_X_concated)

    y1 = app_inst.zeros(shape=(50, ), block_shape=(10, ), dtype=int)
    y2 = app_inst.ones(shape=(50, ), block_shape=(10, ), dtype=int)
    y = app_inst.concatenate([y1, y2], axis=0)
    common.check_block_integrity(y)
Пример #2
0
def sample(app: ArrayApplication, sample_size, feature, num_gpus, augment=False):
    if num_gpus == 2:
        # X_train = nps.concatenate([app.random.normal(shape=(sample_size // 2, feature), block_shape=(sample_size // 2, feature), dtype=np.float64),
        #                         app.random.normal(shape=(sample_size // 2, feature), block_shape=(sample_size // 2, feature), dtype=np.float64) + 2.0],
        #                           axis=0)
        # y_train = nps.concatenate([app.zeros(shape=(sample_size // 2,),
        #                                          block_shape=(sample_size // 2,),
        #                                          dtype=nps.int),
        #                            app.ones(shape=(sample_size // 2,),
        #                                      block_shape=(sample_size // 2,),
        #                                      dtype=nps.int)], axis=0)
        print("X_train")
        X_train = app.random.normal(shape=(sample_size, feature), block_shape=(sample_size // 2, feature),
                                    dtype=np.float64)
        print("y_train")
        y_train = app.ones(shape=(sample_size, 1), block_shape=(sample_size // 2, 1), dtype=nps.int)
    else:
        assert num_gpus is 1
        # X_train = app.random.normal(shape=(sample_size, feature), block_shape=(sample_size, feature), dtype=np.float64)
        # y_train = app.ones(shape=(sample_size,), block_shape=(sample_size,),
        #                                          dtype=nps.int)
        X_train = app.random.normal(shape=(sample_size, feature), block_shape=(sample_size, feature), dtype=np.float64)

        y_train = app.ones(shape=(sample_size, 1), block_shape=(sample_size, 1), dtype=nps.int)
    # We augment X with 1s for intercept term.
    if augment:
        X_train = app.concatenate([X_train, app.ones(shape=(X_train.shape[0], 1),
                                                     block_shape=(X_train.block_shape[0], 1),
                                                     dtype=X_train.dtype)],
                                  axis=1,
                                  axis_block_size=X_train.block_shape[1] + 1)
    return X_train, y_train
Пример #3
0
def sample_set(app: ArrayApplication):
    shape = (500, 10)
    block_shape = (100, 10)
    rs = app.random_state(1337)
    X1 = rs.normal(loc=5.0, shape=shape, block_shape=block_shape)
    y1 = app.zeros(shape=(shape[0],), block_shape=(block_shape[0],), dtype=int)
    X2 = rs.normal(loc=10.0, shape=shape, block_shape=block_shape)
    y2 = app.ones(shape=(shape[0],), block_shape=(block_shape[0],), dtype=int)
    X = app.concatenate([X1, X2], axis=0)
    y = app.concatenate([y1, y2], axis=0)
    return X, y
Пример #4
0
def sample(app: ArrayApplication, sample_size):
    X_train = nps.concatenate([
        nps.random.randn(sample_size // 2, 2),
        nps.random.randn(sample_size // 2, 2) + 2.0
    ],
                              axis=0)
    y_train = nps.concatenate([
        nps.zeros(shape=(sample_size // 2, ), dtype=nps.int),
        nps.ones(shape=(sample_size // 2, ), dtype=nps.int)
    ],
                              axis=0)
    # We augment X with 1s for intercept term.
    X_train = app.concatenate([
        X_train,
        app.ones(shape=(X_train.shape[0], 1),
                 block_shape=(X_train.block_shape[0], 1),
                 dtype=X_train.dtype)
    ],
                              axis=1,
                              axis_block_size=X_train.block_shape[1] + 1)
    return X_train, y_train