quara.qcircuit.data_generator module
- calc_empi_dist_sequence(measurement_num, data, num_sums)[source]
calculates empirical distributions.
uses
datafrom 0-th tonum_sums[index]-th to calculate empirical distributions.- Parameters
measurement_num (int) – number of measurements.
data (List[int]) – data of measurement outcomes.
num_sums (List[int]) – a list of the range of
datato calculate empirical distributions.
- Returns
a list of (the range of
data, empirical distribution). the dtype of each empirical distribution is np.float64.- Return type
List[Tuple[int, np.ndarray]]
- Raises
ValueError –
measurement_numis not non-negative integer.ValueError – there is an element of
num_sumsthat is not less than or equal to length ofdata.ValueError – there is an element of
datathat is not non-negative and less thanmeasurement_num.ValueError –
num_sumsis not an increasing sequence.
Examples
>>> measurement_num = 2 >>> data = [1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1] >>> num_sums = [5, 10, 20] >>> empi_dist = calc_empi_dist_sequence(measurement_num, data, num_sums) >>> empi_dist [(5, array([0.4, 0.6])), (10, array([0.3, 0.7])), (20, array([0.3, 0.7]))]
- calc_empi_dists_sequence(measurement_nums, dataset, list_num_sums)[source]
calculates a sequence of empirical distributions by
calc_empidist().- Parameters
measurement_nums (List[int]) – a list of measurement_num
dataset (List[List[int]]) – a dataset
list_num_sums (List[List[int]]) – a list of num_sums
- Returns
a sequence of empirical distributions.
- Return type
List[List[np.ndarray]]
- Raises
ValueError – the length of
measurement_numsdoes not equal the length ofdataset.ValueError – the length of
measurement_numsdoes not equal the length oflist_llist_num_sumsist_num_sum.
- generate_data_from_prob_dist(prob_dist, data_num, seed_or_generator=None, atol=None)[source]
generates random data from a probability distribution.
the data is a sequence (list) of measurement outcomes. measurement outcomes are integers.
0 <= each measurement outcomes < len(probdist). length of the data equalsdata_num.- Parameters
prob_dist (np.ndarray) – a probability distribution used to generate random data.
data_num (int) – length of the data.
seed_or_generator (Union[int, np.random.Generator], optional) – If the type is int, it is assumed to be a seed used to generate random data. If the type is Generator, it is used to generate random data. If argument is None, np.random is used to generate random data. Default value is None.
atol (float, optional) – the absolute tolerance parameter, uses
get_atol()by default. checksabsolute(the sum of probabilities - 1) <= atolin this function.
- Returns
generated data.
- Return type
List[int]
- Raises
ValueError – each probability is not a positive number.
ValueError – the sum of probabilities does not equal 1.
- generate_dataset_from_prob_dists(prob_dists, data_nums, seeds_or_generators=None)[source]
generates random dataset from probability distributions.
the dataset is a list of data generated by
generate_data_from_probdist()- Parameters
prob_dists (List[np.ndarray]) – a list of probdist.
data_nums (List[int]) – a list of data_num.
seeds_or_generators (Union[int, np.random.Generator], optional) – If the type is int, generates Generator with seed seed_or_generators and returned generated Generator. If the type is Generator, returns Generator. If argument is None, returns np.random. Default value is None.
- Returns
generated dataset.
- Return type
List[List[int]]
- Raises
ValueError – the length of
prob_distsdoes not equal the length ofdata_nums.ValueError –
seeds_or_streamsis not None and the length ofprob_distsdoes not equal the length ofseeds_or_streams.
- generate_empi_dist_sequence_from_prob_dist(prob_dist, num_sums, seed_or_generator=None)[source]
calculates a sequence of empirical distribution from probability distribution.
- Parameters
prob_dist (np.ndarray) – probability distribution.
num_sums (List[int]) – list of number of trials
seed_or_generator (Union[int, np.random.Generator], optional) – If the type is int, it is assumed to be a seed used to generate random data. If the type is Generator, it is used to generate random data. If argument is None, np.random is used to generate random data. Default value is None.
- Returns
a sequence of empirical distribution.
- Return type
List[Tuple[int, np.ndarray]]
- generate_empi_dists_sequence_from_prob_dists(prob_dists, list_num_sums, seed_or_generator=None)[source]
calculates a sequence of empirical distributions from probability distributions.
- Parameters
prob_dists (List[np.ndarray]) – probability distributions.
list_num_sums (List[List[int]]) – list of number of trials
seed_or_generator (Union[int, np.random.Generator], optional) – If the type is int, it is assumed to be a seed used to generate random data. If the type is Generator, it is used to generate random data. If argument is None, np.random is used to generate random data. Default value is None.
- Returns
a sequence of empirical distributions.
- Return type
List[List[Tuple[int, np.ndarray]]]
- Raises
ValueError – the length of
prob_distsdoes not equal the length oflist_num_sums.