Machine learning--Probability map model (HOMEWORK:MCMC)

Source: Internet
Author: User

In addition to precise reasoning, we also have the means to solve the distribution of a single variable in a probability graph by non-precise inference. In many cases, the probability map can not be simplified into a cluster tree, or simplified the number of random variables in a single regiment after the formation of a cluster, resulting in the efficiency of the mission tree calibration is low. As an example of image segmentation, if each pixel's label is a random variable, there will be 30W random variables (a small 30W pixel camera). And the 30W random variables are seriously coupled with each other (4 adjacency, multi-loopback), the group tree algorithm is not efficient to obtain the possible value of a single pixel label. So, in addition to accurate reasoning, we use the means of non-precise inference to estimate the probability distribution of a node.

1. Loopy Confidence Propagation

BP is the concept of accurate reasoning, we send a message from root to the leaf, and then accept a message to complete the calibration of the cluster tree, this process is called confidence propagation. However, in a multi-loopback tree, BP is very difficult to execute, because the presence of the ring will cause a node has been unable to emit a message state (at this time the group tree is not called the group tree, should be called "cluster Diagram"). However, the theory proves that if we give a sequence of message delivery in advance, and ensure that the node I-J propagates and propagates only once, the message will eventually converge to some definite value. Once the message converges to a certain value, it is agreed between the nodes on a certain variable, and we get a feasible distribution of probability plots. At this point, the variables in the cluster diagram are marginalized, and a valid univariate distribution can be obtained.

Loopy confidence propagation has 3 extremely important tasks:

1. Ensure that the propagation order is propagated only once between nodes (this order is obviously not unique)

2. Get the updated message after each propagation

3. Judging the final convergence of messages

  

1List = [];2Edges_ =p.edges;3    fori = 1: Length (p.clusterlist)4j = Find (Edges_ (i,:), 8);5list = [List; j'Linspace (I,i,length (j))'];6 End7Length_list =length (List);8Array_ = mod (m,length_list) +1;9IJ =List (Array_,:);Teni = IJ (1); Onej = IJ (2);
View Code
1Length_c =length (p.clusterlist);2      form = 1: Length_c3         ifM ~= j&&p.edges (m,i) ==14Belief (i) =Factorproduct (Belief (i), Lastmessages (M, i));5 End6 End7Belief (i). val = Belief (i). val/sum (Belief (i). val);8MESSAGES (I,J) =Factormarginalization (Belief (i), Setdiff (Belief (i). var,...9 MESSAGES (i,j). Var));TenMESSAGES (i,j). val = MESSAGES (i,j). Val/sum (MESSAGES (i,j). val);
View Code
1converged =true;2Thresh = 1.0e-6;3%converged should be 1ifconverged, 0 otherwise.4 5%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%6%YOUR CODE here7%8%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%9[A_,b_] =size (mnew);TenLength_m = a_*b_; OneM_new_array = Reshape (mnew,length_m,1); AM_old_array = Reshape (mold,length_m,1); -  fori = 1: Length_m -diff = M_new_array (i). Val-M_old_array (i). val; the     ifMax (ABS (diff)) >Thresh -converged =false; -         return - End +End
View Code

If the message converges, we can get the joint distribution of each cluster in the cluster graph, and each cluster may only correspond to one or two random variables, it is easy to find the distribution of all the random variables.

2, MCMC

MCMC is the abbreviation of MARCOF Montecaro. Markov refers to Markov chain, Monte Carlo refers to the random variable distribution method based on frequency. It is worth noting that although Markov chains and Markov fields have Markov, these two things are completely different. Markov chain is a model to describe the sampling process, and Markov field is a probabilistic graph model. Studying Markov fields can help us model random variables, and studying Markov chains can help us solve Markov fields better. For Markov chains, we can move from any state (one assignment of all Var) to another state. The probability of moving to another state is determined by the MRF. Finally, the number of occurrences of the states represents the assignment corresponding Val.

2.1 Gibbs Sampling

The Gibbs sampling uses a very naïve concept, and for a given assignment, if the VAR1 value is replaced at this point, it is turned to the next state. The distribution of var1 itself may be known, but the joint distribution of the probability associated with VAR1 is determined by cluster. As long as the var1 of all the information in MRF is summarized, and the previous assignment as a "Posteriori", then the edge distribution of var1 " at this time" can be obtained. The sampling is done by determining the value of a var1 and updating the assignment based on this edge distribution.

So there are 3 important places in the Gibbs sample:

1, to find the distribution related to VAR1

2. The posterior distribution of var1 under the previous assignment condition is obtained.

3, according to the result distribution update var1 value

1Var_array = 1: Length (A);2EVDCE = [Var_array'A'];3Factorlists =g.var2factors (V);4  forj = 1: Length (factorlists)5Factorlist =factorlists{j};6distribution_= F (factorlist (1));7Length_flist =length (factorlist);8     ifLength_flist>19          fori = 2: Length_flistTenDistribution_ =factorproduct (distribution_,f (Factorlist (i))); One End A End - End -  theEvdce_var =Setdiff (distribution_.var,v); -Evdce =evdce (Evdce_var,:); -Target_var =observeevidence (DISTRIBUTION_,EVDCE); -Target_var =factormarginalization (Target_var,setdiff (distribution_.var,v)); +Logbs =Target_var.val; -Logbs = log (Logbs);
View Code
Randsample ();
View Code2.2 Metropolis Hasting Sampling

In Gibbs sampling, there is a risk of falling into a local sampling cycle. In short, if the VAR1,VAR2,VAR3 is strongly correlated, it is difficult for var1 to fetch other values in the given VAR2,VAR3 condition. Also, the initial conditions can easily plunge the Gibbs sample into one of the MC loops, making it impossible to traverse the entire state space. Results that eventually lead to errors. MH sampling differs from Gibbs sampling in that MH updates all var assignment at once, as well as state transitions, and it is clear that MH will move farther. As to the MC, it must satisfy the steady state nature, qualitatively: if the probability of the occurrence of a state is higher, then the possibility of its transfer to other probabilities must be very small, in order to guarantee a high self-transfer probability.

If there are two states s1,s2, if we force from S1 to S2, then you must decide how much the probability from S1 to S2. Qualitatively, if the S1 is difficult to occur S2 is very easy to happen, then the probability of this transfer should be relatively high. If both are easy/difficult to take place, the probability of this transfer occurring should generally occur easily. If the S1 is easy to happen, the transfer will be difficult to come by. Depending on the transfer stability Formula modeling, there is a probability that this transfer will occur:

In the formula: Q is the probability of a planned transfer, and Pi is the probability of assignment occurring. A is the probability of acceptance. The function of a is for any q, the forced transfer conforms to the stable nature. Here are two things that are unknown: 1, q,2, A. The opposite pi is known. Because the sampling-based algorithm is used for image segmentation and other fields, Var is very small, and the orc is the opposite. Card small advantage is that we can directly find the joint distribution, in accordance with the joint distribution of the query, we can obtain pi.

Q's design is said to be a value of 60W knife annual salary job, dare not to speculate. Here we assume that Q is given (UNIFORM/SW) **********************************************

The MH sampling process is as follows:

1, given assignment, according to the F to find Pi (Assignment)

2, according to the above formula to calculate the acceptance probability a

3, decide whether to accept, complete the sampling update assignment

3. Summary

The exact inference algorithm based on the cluster tree can well complete the inference of tree structure cluster graph and runs fast. For multi-loop structures We can choose the LBP algorithm and the sampling-based algorithm. The weakness of the LBP algorithm is that the message is difficult to converge and takes a long time, but it guarantees that all assignment can be traversed. Sampling-based algorithms also take some time, but this time is controllable, it depends on the number of iterations we need, and some tasks can sacrifice precision to reduce the number of iterations.

At this point, we have done all the work of reasoning related jobs. However, this is not a complete probability map, in the previous study, we all assume that factor Val is known, this Val is from the autumn mountains of the mysterious license plate? Obviously not. It comes from machine learning.

Because Coursera Honor code, no longer publish the source code.

 

Machine learning--Probability map model (HOMEWORK:MCMC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.