Sampling device and sampling method
The sampling device optimizes control flows in stochastic programs to enhance efficiency by eliminating unnecessary samples, addressing the inefficiencies in existing methods and improving resource utilization.
Patent Information
- Application Number
- JP2022573033
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2020-12-28
- Filing Date
- 2021-12-23
- Publication Date
- 2025-01-29
- Estimated Expiration
- 2041-12-23
AI Technical Summary
Existing stochastic programming methods face challenges in efficiently generating samples due to lack of smoothness in probability distribution transitions and inefficient resource utilization, particularly when dealing with rare events, leading to wasted computational resources.
A sampling device that selects and optimizes control flows within stochastic programs using conversion rules to eliminate unnecessary samples and improve efficiency by generating samples that logically contribute to the output, utilizing a control flow selection portion and program optimization unit.
The solution enhances sampling efficiency by eliminating wasteful calculations and optimizing sample generation, ensuring that only relevant samples are produced, thereby improving resource utilization and reducing computational waste.
Smart Images

Figure 0007623553000005 
Figure 0007623553000006 
Figure 0007623553000007
Abstract
Description
[Technical field]
[0001] The present disclosure relates to a sampling device and a sampling method. [Background technology]
[0002] Bayesian inference is a statistical method for probabilistically inferring inferred events (causal events that are the cause of observed events) from observed events (observed facts). For example, Bayesian inference is applied to many fields, including rocket control, autonomous driving, collision avoidance, spam filtering, medical interviews, academic achievement tests, voice analysis and synthesis, genome analysis, astronomy, psychology, drug discovery, materials, energy, semantic search, online shopping promotion, and deep learning.
[0003] Probabilistic programming (PPL) is used to realize Bayesian estimation. By using probabilistic programming, statistical models can be expressed in the form of a program, and various methods can be provided for analyzing statistical models.
[0004] Frameworks based on sampling are often used as statistical models. For example, Sequential Monte Carlo (SMC), Markov Chain Monte Carlo (MCMC), and Variational Inference (VI) are well-known sampling methods. [Prior art documents] [Non-patent literature]
[0005] [Non-Patent Document 1] Aditya V. Nori and Chung-Kil Hur, “R2: an efficient MCMC sampler for probabilistic programs,” AAAI'14: Proceedings of the Twenty-Eighth AAAI Conference on Artificial Intelligence, July 2014, pp 2476-2482 [Non-Patent Document 2] Yuan Zhou, Hongseok Yang, Yee Whye Teh and Tom Rainforth, “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 [Problem to be solved by the invention]
[0006] The objective of this disclosure is to provide a novel sampling technique for probabilistic programming. [Means for solving the problem]
[0007] In order to solve the above problems, one aspect of the present invention relates to a sampling device having a control flow selection unit that selects a control flow corresponding to each branch of a probabilistic program, a program optimization unit that applies a predetermined conversion rule to a program of the selected control flow by backpropagation, thereby optimizing the program, and a sampling unit that generates samples according to the optimized program. Effect of the Invention
[0008] According to the present disclosure, a novel sampling technique for probabilistic programming can be provided. [Brief description of the drawings]
[0009] [Figure 1] FIG. 1 is a schematic diagram showing a specific example of Bayesian estimation. [Diagram 2] FIG. 13 is a code diagram showing a probabilistic program for Bayesian inference. [Diagram 3] FIG. 1 is a schematic diagram illustrating different distributions in a probabilistic program. [Figure 4]FIG. 1 is a schematic diagram showing sampling results by a probabilistic program. [Diagram 5] FIG. 1 is a schematic diagram illustrating a sampling device according to one embodiment of the present disclosure. [Figure 6] 1 is a block diagram showing a hardware configuration of a sampling device according to an embodiment of the present disclosure. [Figure 7] 1 is a block diagram showing a functional configuration of a sampling device according to an embodiment of the present disclosure. [Figure 8] FIG. 2 is a schematic diagram illustrating a control flow according to an embodiment of the present disclosure. [Figure 9] FIG. 2 is a schematic diagram illustrating transformation rules for probabilistic programming according to one embodiment of the present disclosure. [Figure 10] FIG. 2 is a schematic diagram illustrating transformation rules for probabilistic programming according to one embodiment of the present disclosure. [Figure 11] FIG. 2 is a schematic diagram illustrating a transformation process of a probabilistic program according to an embodiment of the present disclosure. [Figure 12] FIG. 1 is a schematic diagram illustrating a simulation result according to an embodiment of the present disclosure. [Figure 13] FIG. 2 is a code diagram illustrating a probabilistic program according to one embodiment of the present disclosure. [Figure 14] 1 is a flowchart illustrating a sampling process according to an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0010] In the following examples, a sampling apparatus for probabilistic programming is disclosed. [Bayesian Estimation and Probabilistic Programming] Bayesian estimation is the derivation of a posterior distribution P(X|D) from a prior distribution P(X) and a conditional distribution P(D|X) by Bayes' theorem. For example, a probability model for Bayesian estimation can be described by a Bayesian network as shown in Figure 1. By using Bayesian estimation, it is possible to derive, as a posterior probability, the probability P(B|JohnCalls=true&MaryCalls=true) of the occurrence of event B, that a robbery occurs, when both the event (JohnCalls) reported by John and the event (MaryCalls) reported by Marry hold true as prior probabilities (JohnCalls=true&MarryCalls=true) from the Bayesian network shown in the figure. 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.
[0011] In order to realize such Bayesian estimation, probabilistic programming is used. The probabilistic model shown in Fig. 1 can be described as a probabilistic program as shown in Fig. 2. Here, the desired posterior probability P(B|JohnCalls=true&MaryCalls=true) can be output by "return burglary" when "observe(johnCalls&&maryCalls)" holds in the probabilistic program shown in the figure.
[0012] In the illustrated stochastic program, a flip function that randomly returns a Boolean value is used, but in stochastic programming, sampling functions that follow various probability distributions can be used. For example, in the stochastic program shown in FIG. 3, a sampling function "uniform" that follows a uniform distribution, a sampling function "beta" that follows a beta distribution, and a sampling function "gamma" that follows a gamma distribution are used. Then, depending on whether the parameter z0 is negative or non-negative, the process branches into a control flow that uses a beta function and a control flow that uses a gamma function. However, when multiple different probability distributions are used in this way, there is a problem that the probability distribution between the control flows lacks smoothness. In this case, in the MCMC method that moves randomly to obtain the target distribution, it is difficult to determine the timing of switching the probability distribution, and in the VI method that uses a distribution template to fit the data, it is difficult to find a template suitable for a distribution that lacks smoothness.
[0013] In addition, in the probabilistic program shown in Figure 2, JohnCalls=true&MaryCalls=true is an event that occurs rarely, and as shown in Figure 4, samples for which "observe(johnCalls&&maryCalls)" is true are generated only rarely. In other words, most of the samples generated are not used, resulting in a waste of computational resources. [Summary] As shown in FIG. 5, when a sampling device 100 according to an embodiment of the present disclosure receives a stochastic program, it extracts a plurality of control flows by focusing on a conditional branch structure such as an if statement of the received stochastic program. Then, the sampling device 100 selects one of the control flows, optimizes the program of the selected control flow according to condition propagation described later, and generates samples according to the optimized program. In this condition propagation, the program is converted according to a predetermined conversion rule so that samplings that do not logically satisfy the condition for "observe" are eliminated. Then, the sampling device 100 selects the next control flow based on the sampling result, optimizes the program of the selected control flow in the same manner, and generates samples according to the optimized program.
[0014] Here, the sampling device 100 may have a hardware configuration including a processor 101 such as a CPU (Central Processing Unit), a memory 102 such as a RAM (Random Access Memory) or a flash memory, storage 103, and an input / output (I / O) interface 104, for example, as shown in FIG. 6.
[0015] The processor 101 executes various processes of the sampling device 100, which will be described later.
[0016] The memory 102 stores various data and programs in the sampling device 100, and functions in particular as a working memory for working data, programs being executed, etc. Specifically, the memory 102 stores programs for executing and controlling various processes described later that are loaded from the hard disk 103, and functions as a working memory while the processor 101 is executing the programs.
[0017] The hard disk 103 stores various data and programs for the sampling device 100 .
[0018] The I / O interface 104 is an interface for receiving commands and input data from a user, displaying and playing back output results, and inputting and outputting data between an external device. For example, the I / O interface 104 may be a device for inputting and outputting various types of data, such as a USB (Universal Serial Bus), a communication line, a keyboard, a mouse, a display, a microphone, and a speaker.
[0019] However, the sampling device 100 according to the present disclosure is not limited to the above-mentioned hardware configuration and may have any other suitable hardware configuration. For example, one or more of the processes performed by the sampling device 100 may be realized by a processing circuit or an electronic circuit that is hardwired to realize the process. [Sampling device] Next, a sampling device 100 according to an embodiment of the present disclosure will be described with reference to Figures 7 to 13. Figure 7 is a block diagram showing a functional configuration of the sampling device 100 according to an embodiment of the present disclosure.
[0020] As shown in FIG. 7, the sampling apparatus 100 includes a control flow selection unit 110, a program optimization unit 120, and a sampling unit .
[0021] The control flow selection unit 110 selects a control flow corresponding to each branch of the stochastic program. Specifically, when a stochastic program to be processed is given, the control flow selection unit 110 identifies a control structure related to branches such as an if statement in the stochastic program, and extracts a processing path (control flow) corresponding to each branch of the stochastic program. For example, when a stochastic program including one if statement as shown in FIG. 3 is given, the control flow selection unit 110 identifies the if statement and extracts control flows 1 and 2 as shown in FIG. 8. Here, the control flow 1 corresponds to a processing path when the condition "z0<0" in the if statement is true, and the beta function is used as a sampling function. On the other hand, the control flow 2 corresponds to a processing path when the condition "z0<0" in the if statement is false, and the gamma function is used as a sampling function.
[0022] When each control flow in the stochastic program is extracted, the control flow selection unit 110 constructs a serial program of each control flow from the stochastic program. For example, as a serial program corresponding to control flow 1, the control flow selection unit 110 replaces "if(z0<0)" in the stochastic program with "observe(z0<0)" as shown in Fig. 5. Although not shown, as a serial program corresponding to control flow 2, the control flow selection unit 110 similarly replaces "if(z0≧0)" in the stochastic program with "observe(z0≧0)".
[0023] When a serial program for each control flow is constructed in this manner, 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 randomly select one control flow. Thereafter, the control flow selection unit 110 may select the next control flow based on the sampling result of the optimized program, as described below.
[0024] The program optimization unit 120 applies a predetermined conversion rule to the program of the selected control flow by backpropagation to optimize the program. Specifically, when the control flow is acquired from the control flow selection unit 110, the program optimization unit 120 sequentially applies a predetermined conversion rule in the reverse direction to the processing order of the serial program of the acquired control flow, and optimizes the program by converting the instructions of each line from the lowest line to the highest line of the program. For example, the program optimization unit 120 converts each line of the program in the reverse direction to the processing order using a roller that scans the program from the lowest line to the highest line. The roller has an internal state, and converts each line of the program in accordance with the conversion rule described later while transitioning the internal state according to the scan.
[0025] As a first conversion rule, when the line to be converted is "return x", the program optimization unit 120 deletes the line and sets the internal state to "const(1)". Here, "const(1)" is a function that always returns the value 1. For example, when the line to be converted is "return z", the conversion rule converts the line to "const(1)" and sets the internal state to "const(1)".
[0026] As a second conversion rule, when the line to be converted is a deterministic assignment command "x:=e", the program optimization unit 120 replaces the internal state f with "f[e / x]" and maintains "x:=e" as shown in FIG. 9. Here, "f[e / x]" is obtained by replacing the variable x in f with e. For example, when the line to be converted is "z:=z0+y" and the internal state is "char(0<=z<=2)", the conversion rule maintains the line and sets the internal state to "char(0<=z0+y<=2). Here, "char(x)" is a characteristic function of the logical formula x, which returns 1 if x is true and 0 if not.
[0027] As a third conversion rule, when the conversion target line is a weighting instruction "weight(g)", the program optimization unit 120 replaces the internal state f with "f×g" and deletes "weight(g)" as shown in FIG. 9. Here, "f×g" is a function that returns the product of the output value of function f and the output value of function g. Also, "observe(x)" is an abbreviation of "weight(char(x))". For example, when the conversion target line is "observe(z0<0)" and the internal state is "char(-1<=z0<=2)", the conversion rule deletes the line and sets the internal state to "char((-1<=z0<=2)∧(z0<0))=char(-1<=z0<0)".
[0028] As a fourth conversion rule, when the row to be converted is a probabilistic assignment command “x~Dist(e)” and x does not appear in the internal state f, the program optimization unit 120 maintains the command and the internal state as shown in FIG. 10.
[0029] As a fifth conversion rule, when the row to be converted is a probabilistic assignment command "x~Dist(e)" and x appears in the internal state f, as shown in FIG. 10, the program optimization unit 120 sets the internal state f to "char(ψ)", maintains the command, and adds "weight f". Since x is involved in the internal state f, the internal state f needs to be used for weighting (weight f). ψ is expressed as follows:
[0030]
number
[0031] Here, the choice of ψ is as follows:
[0032]
number
[0033]
number
[0034] Furthermore, as an improved version of the fifth conversion rule, when the row to be converted is a probabilistic assignment command "x~Dist(e)" and x appears in the internal state f, it is possible to improve the efficiency by restricting the area. If this improved version is applicable, that is, when ξ,ψ that satisfy the conditions described below are found, this improved version is applied, and if not, the above-mentioned fifth conversion rule may be applied. If the logical formula ξ,ψ is
[0035]
number
[0036] For example, the program optimization unit 120 applies the above-mentioned conversion rules to optimize the serial program of the control flow 1 as shown in FIG.
[0037] First, the program optimization unit 120 applies the first conversion rule to the lowest line "return z" of the serial program, sets the internal state to "const(1)", and deletes the line.
[0038] Next, the program optimization unit 120 applies the third conversion rule to "observe(0<=z<=2)" of the serial program, sets the internal state to "char(0<=z<=2)", and deletes the line.
[0039] Next, the program optimization unit 120 applies the second conversion rule to "z:=z0+y" of the serial program, sets the internal state to "char(0<=z0+y<=2)", and maintains the line "z:=z0+y".
[0040] Next, the program optimization unit 120 applies the fifth conversion rule to “y~beta(1,1)” of the serial program, sets the internal state to “char(-1<=z0<=2)”, and converts the line to “y~beta(1,1)” and “observe(0<=z0+y<=2)”.
[0041] Next, the program optimization unit 120 applies the third conversion rule to “observe(z0<0)” of the serial program, sets the internal state to “char(-1<=z0<0)” (=char((-1<=z0<=2)∧(z0<0))), and erases the line.
[0042] Finally, the program optimization unit 120 applies an improved version of the fifth conversion rule to the top line of the serial program “z0~uniform(-4,4)”, sets the internal state to “const(1)”, and converts the line to “z0~uniform(-1,0)” and “weight(const(1 / 8)”. In the above conversion rule, ψ is True, and char(ψ) is always 1, that is, const(1). In addition, in the conversion rule, x corresponds to z0, and ξ corresponds 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.
[0043] The program optimization unit 120 passes the optimized program to the sampling unit 130 .
[0044] The sampling unit 130 generates samples according to the optimized program. Specifically, the sampling unit 130 generates a predetermined number of samples according to an optimized program of the serial program of the selected control flow. The generated samples are those from which samples that do not logically contribute to calculating the output of the serial program have been excluded in advance, improving sampling efficiency. After generating the predetermined number of samples, 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 selected randomly, or may be an unselected control flow. In the same manner, the program optimization unit 120 optimizes the serial program of the selected control flow, and the sampling unit 130 generates a predetermined number of samples according to the optimized program.
[0045] For the samples pooled in this way, the sampling unit 130 calculates the likelihood of the sample generated for each control flow, and notifies the control flow selection unit 110 of the calculated likelihood as the sampling result. Here, the likelihood of a sample is the product of the weights given by the weighting instructions passed when the sample was generated. Since "observe(x)" is an abbreviation of "weight(char(x))", if the sample does not satisfy the logical formula x when the "observe(x)" instruction is passed, the likelihood of the sample is 0. The control flow selection unit 110 may select a control flow based on the acquired likelihood. For example, the control flow selection unit 110 may 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.
[0046] For example, as shown in Fig. 12, a simulation showed that the likelihood of a sample generated from control flow 1 was 0.063, and the likelihood of a sample generated from control flow 2 was 0.13. By convolving the samples generated from control flows 1 and 2, the distribution of samples as shown in the figure can be obtained.
[0047] In the above-mentioned stochastic program, the control flow is extracted based on the if statement. However, the present disclosure is not limited to this, and the control flow may be extracted based on the while statement as a branch control structure. For example, the present disclosure may be applied to a stochastic program as shown in FIG. 13. For example, the control flow may be extracted according to the number of loops of a while loop. That is, a serial program when the while loop is executed once, a serial program when the while loop is executed twice, ..., a serial program when the while loop is executed n times are respectively extracted, and the above-mentioned program optimization and sampling processing are performed on the extracted serial programs. [Sampling process] Next, a sampling process according to an embodiment of the present disclosure will be described with reference to Fig. 14. The sampling process is executed by the above-described sampling device 100, and can be realized, for example, by one or more processors executing a program stored in one or more memories of the sampling device 100. Fig. 14 is a flowchart showing the sampling process according to an embodiment of the present disclosure.
[0048] 14, in step S101, the sampling device 100 acquires a probabilistic program. Specifically, the sampling device 100 acquires a probabilistic program for implementing Bayesian estimation.
[0049] In step S102, the sampling device 100 selects a control flow corresponding to each branch of the stochastic program. Specifically, the sampling device 100 extracts a control flow corresponding to each branch of an if statement in the acquired stochastic program, and selects a control flow to be processed from the extracted control flows. Then, the sampling device 100 extracts a serial program corresponding to the selected control flow.
[0050] In step S103, the sampling device 100 back-propagates a predetermined conversion rule to the program of the selected control flow to optimize the program. Specifically, the sampling device 100 applies a predetermined conversion rule to each line in the reverse direction of the processing order of the serial program of the selected control flow to convert the serial program. The optimized program is one in which samples that do not logically contribute to calculating the output of the serial program have been removed in advance.
[0051] In step S104, the sampling device 100 generates samples according to the optimized program. Specifically, the sampling device 100 repeatedly executes the optimized program to generate a predetermined number of samples, and stores the generated samples. In addition, the sampling device 100 calculates the likelihood for each control flow for the stored samples.
[0052] In step S105, sampling apparatus 100 determines whether a termination condition is satisfied. The termination condition may be, for example, that steps S101 to S104 have been executed a predetermined number of times.
[0053] If the end condition is satisfied (S105: YES), the sampling device 100 ends the sampling process. On the other hand, if the end condition is not satisfied (S105: NO), the sampling device 100 returns to step S102 and selects the next control flow.
[0054] The above-described sampling device 100 and sampling process may be applied to sampling for testing an automatic driving system, for example. That is, events such as accidents generally do not occur with a high probability. For example, the event X in the "observe(X)" to be analyzed is also a rare event, and most of the samples collected by sampling to analyze the event are likely to be discarded. By using the sampling method disclosed herein, it is possible to exclude in advance the range in which the event X cannot logically occur, and it becomes possible to efficiently generate samples suitable for the analysis target.
[0055] Although the embodiments of the present invention have been described in detail above, the present invention is not limited to the specific embodiments described above, and various modifications and variations are possible within the scope of the gist of the present invention as defined in the claims.
[0056] This international application claims priority based on Japanese Patent Application No. 2020-218906, filed on December 28, 2020, the entire contents of which are hereby incorporated by reference into this international application. [Explanation of symbols]
[0057] 100 Sampling Device 110 Control flow selection section 120 Program Optimization Department 130 Sampling section
Claims
1. a control flow selection unit for selecting a control flow corresponding to each branch of the probabilistic program; a program optimization unit that applies a predetermined transformation rule to the program of the selected control flow by backpropagation to optimize the program; a sampling unit for generating samples according to the optimized program; A sampling device having:
2. 2. The sampling device according to claim 1, wherein the program optimization unit applies a predetermined transformation rule including a restriction on a probability distribution application domain to the program of the selected control flow by back propagation.
3. The sampling device according to claim 1 , wherein the control flow selection unit selects the control flow based on a sampling result.
4. The sampling device of claim 1 , wherein the probabilistic program includes a program for implementing Bayesian estimation.
5. selecting a control flow corresponding to each branch of the probabilistic program; applying predetermined transformation rules to the selected control flow program by backpropagation to optimize the program; generating samples according to the optimized program; The computer performs the sampling method.
6. 6. The sampling method according to claim 5, wherein the step of optimizing the program applies a predetermined transformation rule, including a restriction of a probability distribution application domain, to the program of the selected control flow by back propagation.
7. The sampling method according to claim 5 , wherein the selecting step selects the control flow based on a sampling result.
8. The sampling method according to claim 5 , wherein the probabilistic program includes a program for implementing Bayesian estimation.
Citation Information
Patent Citations
Compiler for Probabilistic Programs
US20090319458A1
Data-parallel probabilistic inference
US20150095277A1
Probabilistic Assertions and Verifying Them
US20160063390A1