本文整理汇总了Python中numpy.random.mtrand.RandomState方法的典型用法代码示例。如果您正苦于以下问题:Python mtrand.RandomState方法的具体用法?Python mtrand.RandomState怎么用?Python mtrand.RandomState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.random.mtrand
的用法示例。
在下文中一共展示了mtrand.RandomState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ensemble
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def ensemble(self, x, random=None):
if random is None:
random = RandomState()
elif not isinstance(random, RandomState):
raise TypeError('Invalid random state.')
config = ensemble.EnsembleConfiguration(adaptation_lag=self.adaptation_lag,
adaptation_time=self.adaptation_time,
scale_factor=self.scale_factor,
evaluator=self._evaluator)
return ensemble.Ensemble(x=x,
betas=self.betas.copy(),
config=config,
adaptive=self.adaptive,
random=random,
mapper=self._mapper)
示例2: __init__
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def __init__(self, n_qubits: int, rs: Optional[RandomState] = None):
"""
A wavefunction simulator that uses numpy's tensordot or einsum to update a state vector
Please consider using
:py:class:`PyQVM(..., quantum_simulator_type=NumpyWavefunctionSimulator)` rather
than using this class directly.
This class uses a n_qubit-dim ndarray to store wavefunction
amplitudes. The array is indexed into with a tuple of n_qubits 1's and 0's, with
qubit 0 as the leftmost bit. This is the opposite convention of the Rigetti Lisp QVM.
:param n_qubits: Number of qubits to simulate.
:param rs: a RandomState (should be shared with the owning :py:class:`PyQVM`) for
doing anything stochastic. A value of ``None`` disallows doing anything stochastic.
"""
super().__init__(n_qubits=n_qubits, rs=rs)
self.n_qubits = n_qubits
self.rs = rs
self.wf = np.zeros((2,) * n_qubits, dtype=np.complex128)
self.wf[(0,) * n_qubits] = complex(1.0, 0)
示例3: __init__
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def __init__(self, n_qubits: int, rs: Optional[RandomState] = None):
"""
A wavefunction simulator that prioritizes readability over performance.
Please consider using
:py:class:`PyQVM(..., wf_simulator_type=ReferenceWavefunctionSimulator)` rather
than using this class directly.
This class uses a flat state-vector of length 2^n_qubits to store wavefunction
amplitudes. The basis is taken to be bitstrings ordered lexicographically with
qubit 0 as the rightmost bit. This is the same as the Rigetti Lisp QVM.
:param n_qubits: Number of qubits to simulate.
:param rs: a RandomState (should be shared with the owning :py:class:`PyQVM`) for
doing anything stochastic. A value of ``None`` disallows doing anything stochastic.
"""
super().__init__(n_qubits=n_qubits, rs=rs)
self.n_qubits = n_qubits
self.rs = rs
self.wf = np.zeros(2 ** n_qubits, dtype=np.complex128)
self.wf[0] = complex(1.0, 0)
示例4: stratified_k_fold
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def stratified_k_fold(
label: str, df: pd.DataFrame = None, file: str = None, n_splits=5,
seed: int = 0
):
random_state = RandomState(seed)
if file is not None:
df = pd.read_csv(file)
index = np.arange(df.shape[0])
res = np.zeros(index.shape)
folds = StratifiedKFold(n_splits=n_splits,
random_state=random_state,
shuffle=True).split(index, df[label])
for i, (train, val) in enumerate(folds):
res[val] = i
return res.astype(np.int)
示例5: __init__
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def __init__(self, seed, dist=None):
if seed <= 0:
self._rng = mt.RandomState()
elif seed > 0:
self._rng = mt.RandomState(seed)
if dist is None:
dist = default_distribution
if not isinstance(dist, Distribution):
raise error("Not a distribution object")
self._dist = dist
示例6: test_random_1
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_random_1(self):
def f():
randomState = numpy.random.mtrand.RandomState(seed=42)
return randomState.rand()
numpy.testing.assert_allclose(
self.evaluateWithExecutor(f),
f()
)
示例7: test_random_2
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_random_2(self):
def f():
randomState = mtrand.RandomState(seed=42)
return randomState.rand(10)
numpy.testing.assert_allclose(
self.evaluateWithExecutor(f),
f()
)
示例8: test_random_repeated_sampling
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_random_repeated_sampling(self):
def f():
randomstate = mtrand.RandomState(seed=42)
rand0 = randomstate.rand()
rand1 = randomstate.rand()
rand2 = randomstate.rand()
return (rand0, rand1, rand2)
numpy.testing.assert_allclose(
self.evaluateWithExecutor(f),
f()
)
示例9: test_random_normals_1
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_random_normals_1(self):
def f():
randomstate = mtrand.RandomState(seed=42)
return randomstate.randn()
numpy.testing.assert_allclose(
self.evaluateWithExecutor(f),
f()
)
示例10: test_random_normals_2
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_random_normals_2(self):
def f():
randomstate = mtrand.RandomState(seed=42)
return randomstate.randn(10)
numpy.testing.assert_allclose(
self.evaluateWithExecutor(f),
f()
)
示例11: test_various_randoms
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_various_randoms(self):
def f():
rng = mtrand.RandomState(seed=42)
f = rng.rand(4)
p = rng.rand()
return p + f[0]
# just check that this doesn't blow up
self.evaluateWithExecutor(f)
示例12: test_random_uniforms_1
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_random_uniforms_1(self):
def f():
randomstate = mtrand.RandomState(seed=42)
unif = randomstate.uniform(-1, 1)
return unif
numpy.testing.assert_allclose(
self.evaluateWithExecutor(f),
f()
)
示例13: test_random_uniforms_2
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_random_uniforms_2(self):
def f():
randomstate = mtrand.RandomState(seed=42)
return randomstate.uniform(low=-1.0, high=1.0, size=9)
numpy.testing.assert_allclose(
self.evaluateWithExecutor(f),
f()
)
示例14: test_sorted_large_1
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_sorted_large_1(self):
def f():
rng = mtrand.RandomState(seed=250015)
x = rng.uniform(size=1000)
res = sorted(x)
return all(
[res[ix] <= res[ix + 1]
for ix in xrange(len(res) - 1)]
)
self.equivalentEvaluationTest(f)
示例15: test_sorted_large_2
# 需要导入模块: from numpy.random import mtrand [as 别名]
# 或者: from numpy.random.mtrand import RandomState [as 别名]
def test_sorted_large_2(self):
def f():
rng = mtrand.RandomState(seed=250015)
x = rng.uniform(size=1000000)
res = sorted(x)
return all(
[res[ix] <= res[ix + 1]
for ix in xrange(len(res) - 1)]
)
self.equivalentEvaluationTest(f)