Пример #1
0
def get_random_state_and_name(seed=7777):
    try:
        import numpy.random_intel as rnd
        rs = rnd.RandomState(seed, brng='MT19937')
        return rs, 'numpy.random_intel'
    except ImportError:
        import numpy.random as rnd
        rs = rnd.RandomState(seed)
        return rs, 'numpy.random'
Пример #2
0
def get_random_state(seed=_random_seed_benchmark_default_):
    try:
        import numpy.random_intel as rnd
        rs = rnd.RandomState(seed, brng='MT19937')
        print("TAG: Using np.random_intel")
    except ImportError:
        import numpy.random as rnd
        rs = rnd.RandomState(seed)
        print("TAG: Using np.random")
    except:
        rs = None
        raise ValueError("Failed to initialize RandomState")
    #
    return rs
Пример #3
0
def gen_kmeans(args):
    try:
        import numpy.random_intel as nri
    except ImportError:
        raise ImportError('numpy.random_intel not found. '
                          'Please use Intel Distribution for Python.')

    rs = nri.RandomState(args.seed, brng=('MT2203', args.node_id))

    # generate centers
    cluster_centers = _get_cluster_centers(args.clusters, args.features)
    pvec = np.full((args.clusters, ), 1.0 / args.clusters, dtype=np.double)
    cluster_sizes = rs.multinomial(args.samples, pvec)
    cluster_sizes_cum = cluster_sizes.cumsum()

    # generate clusters around those centers
    sz = 0.5
    ch = rs.uniform(low=-sz, high=sz, size=(_ch_size(args.features), ))
    data = rs.multinormal_cholesky(cluster_centers[0],
                                   ch,
                                   size=(args.samples + args.test_samples, ))
    diff_i0 = np.empty_like(cluster_centers[0])
    for i in range(1, args.clusters):
        np.subtract(cluster_centers[i], cluster_centers[0], out=diff_i0)
        data[cluster_sizes_cum[i - 1]:cluster_sizes_cum[i]] += diff_i0

    j = nri.choice(range(0, args.samples), size=args.clusters, replace=False)

    X_init = data[j]
    X = data
    times = []
    import timeit
    for n in range(10):
        t1 = timeit.default_timer()
        variances = np.var(X, axis=0)
        absTol = np.mean(variances) * 1e-16
        t2 = timeit.default_timer()
        times.append(t2 - t1)
    print(f'Computing absolute threshold on this machine '
          f'takes {min(times)} seconds')

    np.save(args.filex, X[:args.samples])
    if args.test_samples != 0:
        np.save(args.filextest, X[args.samples:])
    np.save(args.filei, X_init)
    np.save(args.filet, absTol)
    return 0
Пример #4
0
 def _make_args(self, n):
     self._rs = rnd.RandomState(123)
     # rnd.RandomState(123, brng='MT19937') with the Intel variant in the future
     self._size = n
Пример #5
0
def _get_cluster_centers(clusters, features):
    import numpy.random_intel as nri
    rs = nri.RandomState(1234, brng='SFMT19937')
    cluster_centers = rs.randn(clusters, features)
    cluster_centers *= np.double(clusters)
    return cluster_centers