2%> Generate and
return the **probabilistically-rounded** to the nearest integer value of the input real number.
5%> Unlike the intrinsic Fortran `nint()` function, the procedures of
this generic
6%>
interface round the input real number to the nearest integer value **probabilistically**.<br>
7%> The closer the input `val` is to its `nint(val)` result, the more likely it will be rounded to it.<br>
8%> See below
for example usage.<br>
10%> \param[in] val : The input scalar or array of the same rank as other array-like arguments,
11%> containing the number to be rounded probabilistically.<br>
14%> `whole` : The output scalar or array of the same rank and shape as the input arguments,
15%> of
default `integer` kind, containing the **probabilistically-rounded** input value to the nearest integer.<br>
20%> whole = pm.math.pnint(val);
25%> \include{lineno} example/math/
pnint/main.m
27%> \include{lineno} example/math/
pnint/main.out.m
32%> \AmirShahmoradi, April 23, 2017, 1:36 AM, Institute
for Computational Engineering and Sciences (ICES), University of Texas at Austin<br>
35 residual = val - whole; %
abs(residual) < .5 always holds.
36 urand = unifrnd(0, 1, size(val, 1), size(val, 2));
37 mask = 1 -
abs(residual) < urand;
38 mask1 = mask & residual < 0;
39 mask2 = mask & residual >= 0;
40 whole(mask1(:)) = whole(mask1(:)) - 1;
41 whole(mask2(:)) = whole(mask2(:)) + 1;
function abs(in path, in style)
Return the Get absolute canonical path of a file or folder.
function pnint(in val)
Generate and return the probabilistically-rounded to the nearest integer value of the input real numb...