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=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 (int, optional) – a seed used to generate random data, by default 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=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 (List[int], optional) – a list of seed, by default None
- Returns
generated dataset.
- Return type
List[List[int]]
- Raises
ValueError – the length of
prob_distsdoes not equal the length ofdata_nums.ValueError –
seedsis not None and the length ofprob_distsdoes not equal the length ofseeds.