Sampling device and sampling method

By using a sampling device to select and optimize the control flow of the probability program, the smoothness problem between multiple probability distributions in Bayesian estimation is solved, the sample generation efficiency is improved, and the waste of computational resources is reduced.

CN116670642BActive Publication Date: 2026-06-23UNIV SHARED USE AGENCY INFORMATION & SYST RES INST

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
UNIV SHARED USE AGENCY INFORMATION & SYST RES INST
Filing Date
2021-12-23
Publication Date
2026-06-23

AI Technical Summary

Technical Problem

Existing techniques in Bayesian estimation struggle to effectively handle the smoothness of control flow between multiple probability distributions, leading to wasted computational resources and inefficient sample generation.

Method used

The control flow selection unit, program optimization unit, and sampling unit in the sampling device select the control flow corresponding to the branch of the probabilistic program, and apply the backpropagation transformation rule to optimize the program and generate logically valid samples.

Benefits of technology

It improves the sampling efficiency of Bayesian estimation, reduces the waste of computational resources, generates logically useful samples, and improves the efficiency of sample generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116670642B_ABST
    Figure CN116670642B_ABST
Patent Text Reader

Abstract

The present disclosure provides a new sampling method for probabilistic programming. One embodiment of the present invention relates to a sampling device having: a control flow selection section that selects a control flow corresponding to each branch of a probabilistic program; a program optimization section that applies a prescribed transformation rule to a program of the selected control flow by backpropagation and optimizes the program; and a sampling section that generates a sample in accordance with the optimized program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to a sampling device and a sampling method. Background Technology

[0002] Bayesian estimation is a statistical method used to infer, in a probabilistic sense, what is estimated from observed events (observed facts) as causal events. For example, Bayesian estimation has been applied in numerous fields such as rocket control, autonomous driving, collision avoidance, spam filtering, medical diagnosis, academic aptitude testing, speech analysis and synthesis, genome analysis, astronomy, psychology, drug discovery, materials, energy, semantic search, online shopping promotion, and deep learning.

[0003] To implement Bayesian estimation, probabilistic programming (PPL) is used. By using probabilistic programming, statistical models can be expressed in programmatic form, and various methods can be provided during statistical model analysis.

[0004] Sampling-based frameworks are commonly used as statistical models. For example, known sampling methods include Continuous Monte Carlo (SMC), Markov Chain Monte Carlo (MCMC), and Variational Inference (VI).

[0005] [Existing Technical Documents]

[0006] [Non-patent literature]

[0007] Non-patent literature 1: Aditya V. Nori and Chung-Kil Hur, “R2: an efficient MCMCsampler for probabilistic programs,” AAAI'14: Proceedings of the Twenty-Eighth AAAI Conference on Artificial Intelligence, July 2014, pp 2476-2482

[0008] Non-patent document 2: Yuan Zhou, Hongseok Yang, Yee Whye Teh and TomRainforth, "Divide, Conquer, and Combine: a New Inference Strategy for Probabilistic Programs with Stochastic Support", (https: / / arxiv.org / pdf / 1910.13324.pdf) Summary of the Invention

[0009] [The problem this invention aims to solve]

[0010] The subject of this disclosure is to provide a novel sampling method for probabilistic programming.

[0011] Methods for solving problems

[0012] To address the aforementioned issues, one aspect of the present invention relates to a sampling apparatus comprising: a control flow selection unit that selects control flows corresponding to branches of a probabilistic program; a program optimization unit that applies a predetermined transformation rule to the selected control flow program via backpropagation and optimizes the program; and a sampling unit that generates samples based on the optimized program.

[0013] [The effects of the invention]

[0014] According to this disclosure, a novel sampling method for probabilistic programming can be provided. Attached Figure Description

[0015] Figure 1 This is a schematic diagram illustrating a specific example of Bayesian estimation.

[0016] Figure 2 This is a code diagram illustrating the probability procedure for Bayesian estimation.

[0017] Figure 3 This is a schematic diagram illustrating different distributions in a probability procedure.

[0018] Figure 4 This is a schematic diagram illustrating the sampling results based on a probability procedure.

[0019] Figure 5 This is a schematic diagram illustrating a sampling apparatus according to an embodiment of the present disclosure.

[0020] Figure 6 This is a block diagram illustrating the hardware structure of a sampling device according to an embodiment of the present disclosure.

[0021] Figure 7 This is a block diagram illustrating the functional structure of a sampling device according to an embodiment of the present disclosure.

[0022] Figure 8 This is a schematic diagram illustrating the control flow according to an embodiment of the present disclosure.

[0023] Figure 9 This is a schematic diagram illustrating the transformation rules of probabilistic programming according to an embodiment of the present disclosure.

[0024] Figure 10 This is a schematic diagram illustrating the transformation rules of probabilistic programming according to an embodiment of the present disclosure.

[0025] Figure 11 This is a schematic diagram illustrating the conversion process of a probability procedure according to an embodiment of the present disclosure.

[0026] Figure 12 This is a schematic diagram illustrating simulation results according to an embodiment of the present disclosure.

[0027] Figure 13 This is a code diagram illustrating a probability procedure according to an embodiment of the present disclosure.

[0028] Figure 14 This is a flowchart illustrating a sampling process according to an embodiment of the present disclosure. Detailed Implementation

[0029] In the following embodiments, a sampling device for probabilistic programming is disclosed.

[0030] [Bayesian Estimation and Probabilistic Programming]

[0031] Bayesian estimation refers to deriving the posterior distribution P(X|D) from the prior distribution P(X) and the conditional distribution P(D|X) using Bayes' theorem. For example, a probability model used for Bayesian estimation can be derived from... Figure 1 The illustrated Bayesian network is described as follows. Through Bayesian estimation, from the illustrated Bayesian network, for example, in the case where both events reported by John (JohnCalls) and events reported by Mary (MaryCalls) are true beforehand (JohnCalls=true & MaryCalls=true), the probability P(B|JohnCalls=true & MaryCalls=true) of the event B of a burglary can be derived as a posterior probability. In the illustrated example, P(B|JohnCalls=true & MaryCalls=true) = P(JohnCalls=true & MaryCalls=true|B)·P(B) / P(JohnCalls=true & MaryCalls=true) ~ 0.2841.

[0032] To achieve this Bayesian estimation, probabilistic programming is used. Figure 1 The probability model shown can be described as, for example... Figure 2 The probability procedure shown in the figure is as follows. In this probability procedure, the expected posterior probability P(B|JohnCalls=true&MaryCalls=true) can be output by the "returnburglary" output if "observe(johnCalls&&maryCalls)" is true.

[0033] In the illustrated probabilistic procedure, the `flip` function, which randomly returns a Boolean value, is used. However, in a probabilistic procedure, it is possible to utilize sampling functions that follow various probability distributions. For example, in... Figure 3 The probabilistic procedure shown uses sampling functions uniform, beta, and gamma, all following a uniform distribution. Then, the processing branch is determined based on whether the parameter z0 is negative or non-negative, resulting in control flows using either the beta or gamma function. However, in this case of using multiple different probability distributions, the lack of smoothness in the probability distributions between the control flows must be considered. In this situation, in the MCMC method where the target distribution is obtained through random shifting, it is difficult to determine the timing of probability distribution switching. Furthermore, in the VI method, which uses distribution templates to apply to the data, it is difficult to find a suitable template for distributions lacking smoothness.

[0034] In addition, Figure 2 In the probability procedure shown, JohnCalls=true & MaryCalls=true are rare events, and as... Figure 4 As shown, very few samples are generated where "observe(johnCalls&&maryCalls)" is true. In other words, most of the generated samples are not used, which wastes computational resources.

[0035] [summary]

[0036] like Figure 5 As shown, in one embodiment of this disclosure, the sampling device 100, upon receiving a probabilistic program, extracts multiple control flows by examining the conditional branch structures such as if statements in the received probabilistic program. Then, the sampling device 100 selects any one control flow and optimizes the program of the selected control flow according to the conditional propagation described later, generating samples based on the optimized program. In this conditional propagation, the program is transformed according to a predetermined transformation rule to exclude samples that logically do not satisfy the "observe" condition. Then, the sampling device 100 selects the next control flow based on the sampling results, similarly optimizing the program of the selected control flow and generating samples based on the optimized program.

[0037] Here, as Figure 6 As shown, the sampling device 100 may have a hardware structure consisting of a processor 101 (such as a CPU (central processing unit)), a memory 102 (such as RAM (random access memory), flash memory, etc.), a storage 103, and an input / output (I / O) interface 104.

[0038] The processor 101 performs various processes of the sampling device 100, which will be described later.

[0039] The memory 102 stores various data and programs in the sampling device 100, and in particular serves as working memory for working data, programs being executed, etc. Specifically, the memory 102 stores programs loaded from the memory 103 for executing and controlling various processes described later, and functions as working memory during the execution of programs by the processor 101.

[0040] The storage device 103 stores various data and programs in the sampling device 100.

[0041] I / O interface 104 is an interface used to accept instructions and input data from users, display and reproduce output results, and input and output data with external devices. For example, I / O interface 104 can be a device for inputting and outputting various data, such as USB (Universal Serial Bus), communication lines, keyboards, mice, monitors, microphones, and speakers.

[0042] However, the sampling device 100 according to this disclosure is not limited to the hardware structure described above, but may have any other suitable hardware structure. For example, one or more of the various processes performed by the sampling device 100 may be implemented by wiring processing circuits or electronic circuits capable of implementing these processes.

[0043] [Sampling device]

[0044] Next, we will refer to Figures 7-13 A sampling apparatus 100 according to an embodiment of the present disclosure is described. Figure 7 This is a block diagram illustrating the functional structure of a sampling device 100 according to an embodiment of the present disclosure.

[0045] like Figure 7 As shown, the sampling device 100 includes a control flow selection unit 110, a program optimization unit 120, and a sampling unit 130.

[0046] The control flow selection unit 110 selects the control flow corresponding to each branch of the probability program. Specifically, when a probability program for the object being processed is provided, the control flow selection unit 110 determines the control structures related to branches such as if statements in the probability program and extracts the processing path (control flow) corresponding to each branch of the probability program. For example, if a probability program including... Figure 3 In a probabilistic program with an if statement, the control flow selection unit 110 specifies the if statement and extracts... Figure 8The control flows 1 and 2 are shown. Here, control flow 1 corresponds to the processing path when the condition "z0<0" in the if statement is true, and the beta function is used as the sampling function. On the other hand, control flow 2 corresponds to the processing path when the condition "z0<0" in the if statement is false, and the gamma function is used as the sampling function.

[0047] When each control flow in the probability program is extracted, the control flow selection unit 110 constructs a serial program for each control flow based on the probability program. For example, as a serial program corresponding to control flow 1, such as Figure 5 As shown, the control flow selection unit 110 replaces "if(z0<0)" in the probability program with "observe(z0<0)". Although not shown, as a serial program corresponding to control flow 2, the control flow selection unit 110 also replaces "if(z0≥0)" in the probability program with "observe(z0≥0)".

[0048] Thus, when the sequence of control flows is constructed, the control flow selection unit 110 selects one of the extracted control flows and passes it to the program optimization unit 120. Initially, the control flow selection unit 110 may also randomly select one control flow. Subsequently, as described later, the control flow selection unit 110 may also select the next control flow based on the sampling results obtained from the optimized program.

[0049] The program optimization unit 120 optimizes the program by applying predetermined transformation rules to the selected control flow program through back propagation. Specifically, when a control flow is obtained from the control flow selection unit 110, the program optimization unit 120 optimizes the program by sequentially applying predetermined transformation rules in the direction opposite to the processing order of the serial program of the obtained control flow, transforming the commands of each line of the program from the bottom line to the top line. For example, the program optimization unit 120 uses a roller that scans the program from the bottom line to the top line, transforming each line of the program in the direction opposite to the processing order. The roller has an internal state, and while transforming the internal state according to the scan, it transforms each line of the program according to the transformation rules described later.

[0050] As the first transformation rule, when the line to be transformed is "return x", the program optimization unit 120 deletes the line and sets its internal state to "const(1)". Here, "const(1)" is a function that always returns a value of 1. For example, when the line to be transformed is "return z", the transformation rule transforms the line to "const(1)" and sets its internal state to "const(1)".

[0051] As the second transformation rule, when the line of the transformation object is the decisive substitution command "x:=e", the program optimization unit 120, as follows: Figure 9As shown, the internal state f is replaced with "f[e / x]", while maintaining "x:=e". Here, "f[e / x]" replaces the variable x in f with e. For example, if the row of the transformed object is "z:=z0+y" and the internal state is "char(0<=z<=2)", this transformation rule maintains the row and sets the internal state to "char(0<=z0+y<=2)". Here, "char(x)" is a characteristic function of the logical expression x, returning 1 if x is true and 0 otherwise.

[0052] As the third transformation rule, when the row of the transformation object is a weighted command "weight(g)", such as Figure 9 As shown, the program optimization unit 120 replaces the internal state f with "f×g" and deletes "weight(g)". Here, "f×g" is a function that returns the product of the output values ​​of function f and function g. In addition, "observe(x)" is an abbreviation of "weight(char(x))". For example, if the row of the transformation object is "observe(z0<0)" and the internal state is "char(-1<=z0<=2)", the transformation rule deletes the row and sets the internal state to "char((-1<=z0<=2)∧(z0<0)))=char(-1<=z0<0)".

[0053] As the fourth transformation rule, when the row of the transformation object is a probabilistic substitution command "x ~ Dist(e)" and x does not appear in the internal state f, such as Figure 10 As shown, the program optimization unit 120 maintains the command and internal state.

[0054] As the fifth transformation rule, when the row of the transformation object is a probabilistic substitution command "x ~ Dist(e)" and x appears in the internal state f, such as Figure 10 As shown, the program optimization unit 120 sets the internal state f to "char(ψ)", maintains this command, and appends "weight f". Since x involves the internal state f, the internal state f needs to be used for weighting (weight f). ψ can be any logical expression that satisfies the following formula.

[0055]

Number 1

[0056]

[0057] Here, ψ must be a Boolean logical expression, not a fuzzy notation.

[0058] Here, as a method of choosing ψ, the following logical expression can be used as ψ.

[0059]

Number 2

[0060]

[0061] However, the quantizer ∃ makes logical operations very difficult. Furthermore, ψ can be set to true. However, since there is no information content and no effect of saving invalid samples, True is only chosen when the following selection method cannot be applied. Therefore, the truth about f・>0 is monotonic with respect to x, i.e., f・(x1)>0 and x1≤x2 implies f・(x2)>0.

[0062]

Number 3

[0063]

[0064] Furthermore, when assuming the above expression has an upper limit xsup, ψ is chosen as f·(xsup)>0. For example, when the row of the transformed object is “y~beta(1,1)” and the internal state is “char(0<=z0+y)”, the transformation rule maintains the row and sets the internal state to “char(0<=z0+1)”.

[0065] Furthermore, as an improvement to the fifth transformation rule, when the row to be transformed is a random substitution command "x ~ Dist(e)" and x appears in the internal state f, efficiency improvements such as region restrictions can be achieved. This improved version can be applied when ξ and ψ satisfy the conditions described later are found; otherwise, the fifth transformation rule described above can be applied.

[0066]

Number 4

[0067]

[0068] When the logical expressions ξ and ψ satisfy the conditions of the above expression, such as Figure 10 As shown, the program optimization unit 120 sets the internal state f to "char(ψ)", replaces the command with "x~(Dist(e)|ξ)", and adds "weight(p(ξ|x~Dist(e))" and "weight(f)". Here, "Dist(e)|ξ" is the probability distribution that restricts the probability distribution "Dist(e)" to the region where ξ is true, and "p(ξ|x~Dist(e)" is the probability that ξ is set to true along x selected along Dist(e).

[0069] For example, the program optimization unit 120 applies the above-mentioned transformation rules, such as... Figure 11 As shown, the cascaded program of control flow 1 is optimized.

[0070] First, the program optimization unit 120 applies the first transformation rule to the lowest line "return z" of the serial program, sets the internal state to "const(1)", and deletes the line.

[0071] Next, the program optimization unit 120 applies the third transformation rule to the "observe(0<=z<=2)" line of the serial program, sets the internal state to "char(0<=z<=2)", and deletes the line.

[0072] Next, the program optimization unit 120 applies the second transformation rule to the "z:=z0+y" of the serial program, sets the internal state to "char(0<=z0+y<=2)", and maintains the line "z:=z0+y".

[0073] Next, the program optimization unit 120 applies the 5th transformation rule to the "y~beta(1,1)" of the serial program, sets the internal state to "char(-1<=z0<=2)", and transforms the line into "y~beta(1,1)" and "observe(0<=z0+y<=2)".

[0074] Next, the program optimization unit 120 applies the third transformation rule to the "observe(z0<0)" line of the serial program, sets the internal state to "char(-1<=z0<0)" (=char(((-1<=z0<=2)∧(z0<0))), and deletes the line.

[0075] Finally, the program optimization unit 120 applies an improved version of the fifth transformation rule to the topmost line "z0~uniform(-4, 4)" of the serial program, sets the internal state to "const(1)", and transforms the line into "z0~uniform(-1, 0)" and "weight(const(1 / 8)". In the above transformation rule, ψ is True, and char(ψ) is always 1, i.e., const(1). In addition, x in the transformation rule is equivalent to z0, and ξ is equivalent to -1<=z0<=0. Dist(e) is uniform(-4, 4), Dist(e)|ξ) is uniform(-1, 0), and p(ξ|x~Dist(e)) is the probability that -1<=z0<=0 is satisfied when z0 is selected from uniform(-4, 4), which is 1 / 8.

[0076] The program optimization unit 120 provides the optimized program to the sampling unit 130.

[0077] The sampling unit 130 generates samples according to an optimized program. Specifically, the sampling unit 130 generates a predetermined number of samples based on an optimized program of the selected control flow serialization program. The generated samples are those that have been pre-excluded from those that do not logically contribute to the output of the serialization program, thus improving sampling efficiency. When the predetermined number of samples is generated, the sampling unit 130 causes the control flow selection unit 110 to select the next control flow. For example, the next control flow may be randomly selected or an unselected control flow. Similarly, the program optimization unit 120 optimizes the serialization program of the selected control flow, and the sampling unit 130 generates a predetermined number of samples based on the optimized program.

[0078] For the aggregated samples, the sampling unit 130 calculates the likelihood of the samples generated for each control flow and notifies the control flow selection unit 110 of the calculated likelihood as a sampling result. Here, the likelihood of a sample refers to the weighted product of the weighted instructions used to generate the sample. Since "observe(x)" is an abbreviation for "weight(char(x))", if the sample does not satisfy the logical expression x when using the "observe(x)" instruction, then the likelihood of the sample is 0. The control flow selection unit 110 can select a control flow based on the obtained likelihood. For example, the control flow selection unit 110 can select a control flow with a relatively high likelihood with a high probability and a control flow with a relatively low likelihood with a low probability.

[0079] For example, such as Figure 12 As shown in the figure, through simulation, the likelihood of the samples generated from control flow 1 is 0.063, while the likelihood of the samples generated from control flow 2 is 0.13. By superimposing the samples generated from control flow 1 and 2, the sample distribution shown in the figure can be obtained.

[0080] Furthermore, in the above probabilistic program, control flow is extracted based on the if statement. However, this disclosure is not limited to this; control structures that extract control flow as branches can also be based on the while statement. For example, this disclosure can be applied to, for example... Figure 13 The probabilistic program is shown. For example, the control flow can be extracted based on the number of iterations of the while loop. That is, the serial program executed once by the while loop, the serial program executed twice by the while loop, ..., the serial program executed n times by the while loop, and the above-mentioned program optimization and sampling processing are performed on the extracted serial programs.

[0081] [Sampling Processing]

[0082] Next, we will refer to Figure 14The sampling process according to one embodiment of the present disclosure is described. This sampling process is performed by the sampling apparatus 100 described above, and can be implemented, for example, by one or more processors executing programs stored in one or more memories of the sampling apparatus 100. Figure 14 This is a flowchart illustrating a sampling process according to an embodiment of the present disclosure.

[0083] like Figure 14 As shown, in step S101, the sampling device 100 acquires a probability program. Specifically, the sampling device 100 acquires a probability program for implementing Bayesian estimation.

[0084] In step S102, the sampling device 100 selects the control flow corresponding to each branch of the probabilistic program. Specifically, the sampling device 100 extracts the control flow corresponding to each branch of the if statement in the acquired probabilistic program, and selects the control flow of the object to be processed from the extracted control flow. Then, the sampling device 100 extracts the serial program corresponding to the selected control flow.

[0085] In step S103, the sampling device 100 backpropagates the prescribed transformation rules to the selected control flow program to optimize the program. Specifically, the sampling device 100 applies the prescribed transformation rules to each line in the opposite direction to the processing order of the selected control flow's serial program, transforming the serial program. The optimized program pre-excludes samples that do not logically contribute to the calculation of the serial program's output.

[0086] In step S104, the sampling device 100 generates samples according to the optimized procedure. Specifically, the sampling device 100 repeatedly executes the optimized procedure to generate a predetermined number of samples and saves the generated samples. In addition, the sampling device 100 calculates the likelihood of each control flow for the stored samples.

[0087] In step S105, the sampling device 100 determines whether the termination condition is met. For example, the termination condition could be that S101 to S104 have been executed a predetermined number of times.

[0088] If the termination condition is met (S105: Yes), the sampling device 100 terminates the sampling process. On the other hand, if the termination condition is not met (S105: No), the sampling device 100 returns to step S102 and selects the next control flow.

[0089] The aforementioned sampling device 100 and sampling processing can be applied, for example, to sampling for testing autonomous driving systems. That is, events such as accidents generally do not occur with such a high probability. For example, event X in the "observe(X)" of the analysis object is also a rare event, and most of the samples collected in the sampling used to analyze this event are likely to be discarded. By utilizing the sampling method of this disclosure, the range of logically impossible occurrences of event X can be excluded in advance, and samples suitable for the analysis object can be generated effectively.

[0090] The embodiments of the present invention have been described in detail above, but the present invention is not limited to the specific embodiments described above. Various modifications and alterations can be made within the scope of the spirit of the present invention as described in the claims.

[0091] This international application claims priority based on Japanese Patent Application No. 2020-218906, filed on December 28, 2020, the entire contents of which are incorporated herein by reference.

[0092] [Explanation of Symbols]

[0093] 100 sampling devices

[0094] 110 Control Flow Selection Unit

[0095] 120 Program Optimization Department

[0096] 130 sampling unit

Claims

1. A sampling device, comprising: Select the control flow corresponding to each branch of the probability program and extract the control flow selection part of the cascade program corresponding to the selected control flow; The program optimization unit, following the reverse order of the serial program, uses an internal state determined by commands based on the transformation object to transform the commands of the serial program corresponding to the selected control flow, thereby applying prescribed transformation rules to the serial program corresponding to the selected control flow and optimizing the serial program; and The sampling section generates samples according to the optimized concatenation procedure.

2. The sampling device according to claim 1, wherein, The program optimization unit applies a defined transformation rule, which includes restrictions on the applicable region of the probability distribution, to the serial program corresponding to the selected control flow.

3. The sampling device according to claim 1, wherein, The control flow selection unit selects the control flow based on the sampling results.

4. The sampling device according to claim 1, wherein, The probability program includes a program for implementing Bayesian estimation.

5. A sampling method that causes a computer to perform the following steps: Select the control flow corresponding to each branch of the probability program and extract the concatenated program corresponding to the selected control flow; Following the reverse order of the serial procedure, using the internal state determined by commands based on the transformation object, the commands of the serial procedure corresponding to the selected control flow are transformed, thereby applying the prescribed transformation rules to the serial procedure corresponding to the selected control flow and optimizing the serial procedure; and Samples are generated based on the optimized concatenation procedure.

6. The sampling method according to claim 5, wherein, In the step of optimizing the program, a prescribed transformation rule, which includes restrictions on the application region of the probability distribution, is applied to the concatenated program corresponding to the selected control flow.

7. The sampling method according to claim 5, wherein, In the selection step, the control flow is selected based on the sampling results.

8. The sampling method according to claim 5, wherein, The probability program includes a program for implementing Bayesian estimation.