Consolitading this code:
Added to the calculation a histograms to verify the Sum of probabilities
row1,col1 - > the histograms are saved into the output file, so one can quickly check this