Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampling random variables #95

Open
tclose opened this issue Apr 4, 2015 · 1 comment
Open

Sampling random variables #95

tclose opened this issue Apr 4, 2015 · 1 comment

Comments

@tclose
Copy link
Contributor

tclose commented Apr 4, 2015

Andrew raised the issue in the meeting that many neuroscience models (unwisely) redraw negative tails of normally distributed random variables, and we didn’t have a way to do this in the current spec. While this use case is not recommended we want to be able to represent legacy models, and there other cases where this is a good idea. For example, if you want to sample uniformly distributed points on a disc/ball/etc… the easiest way to do this is to uniformly sample from a square and throw away the points that are outside the disc.

In order to handle these cases I have come up with the following syntax for redrawing random variables on some rejection condition.

  <!-- Redraw random variable(s) if a reject condition is met. Uniform sampling
    on a disc. -->
  <Redraw>
    <RandomVariable name="x" units="none">
      <un:UniformDistribution xmlns:un="www.uncertml.org/distributions">
        <un:low>0</un:low>
        <un:high>1</un:high>
      </un:UniformDistribution>
    </RandomVariable>
    <RandomVariable name="y" units="none">
      <un:UniformDistribution xmlns:un="www.uncertml.org/distributions">
        <un:low>0</un:low>
        <un:high>1</un:high>
      </un:UniformDistribution>
    </RandomVariable>
    <Reject>
      <MathInline>x * x + y * y &gt; 1.0</MathInline>
    </Reject>
  </Redraw>

or for the negative tails of normal distributions

  <!-- Redraw random variable(s) if a reject condition is met. Uniform sampling
    on a disc. -->
  <Redraw>
    <RandomVariable name="x" units="none">
      <un:UniformDistribution xmlns:un="www.uncertml.org/distributions">
        <un:low>0</un:low>
        <un:high>1</un:high>
      </un:UniformDistribution>
    </RandomVariable>
    <Reject>
      <MathInline>x &lt; 0.0</MathInline>
    </Reject>
  </Redraw>

Let me know what you think

@tclose
Copy link
Contributor Author

tclose commented Jun 1, 2015

I have been thinking that that instead of introducing a Redraw element it would be a good idea to introduce a RandomSample element that is placed within the scope that a sample is drawn from the random distribution. This way RandomVariables could be always defined in the top level scope and it would still be explicit where and when a new values are drawn from them. These values would then be accessible within the current scope and all nested scopes. E.g.

<ConnectionRule name="MeaninglessExample">
  <Parameter name="variance" dimension="length"/>
  <Select action="add">
    <Mask>...</Mask>
    <Select action="add">
      <Number>
        <MathInline>ceil(number)</MathInline>
      </Number>
      <RandomSample>
        <Reference name="number"/>
      </RandomSample>
      <Select action="remove">
        <Number>
          <MathInline>20 - ceil(number)</MathInline>
        </Number>
      </Select>
    </Select>
  </Select>
  <Alias name="scaled_variance">
    <MathInline>variance/one_um</MathInline>
  </Alias>
  <RandomVariable name="number" units="um">
    <un:NormalDistribution xmlns:un="http://uncertml.org">
      <un:mean>0.0</un.mean>
      <un:variance>scaled_variance</un.variance>
    </un:NormalDistribution>
  </RandomVariable>
  <Constant name="one_um" value="1.0" units="um"/>
</ConnectionRule>

It would be invalid to refer to a random variable that has not been drawn in the current or parent scopes, and it would be also invalid to draw a value in a nested scope that has already been drawn in one of its parents.

This format it could then handle the rejection of random samples with something like

<ConnectionRule name="AnotherMeaninglessExample">
  <Parameter name="variance" dimension="length"/>
  <PropertyReceivePort name="src_x" dimension="length" container="source"/>
  <PropertyReceivePort name="src_y" dimension="length" container="source"/>
  <Select action="add" perspective="source">
     <Mask>
        <MathInline>src_x &lt; x &amp;&amp; src_y &lt; y</MathInline>
     </Mask>
     <RandomSample>
       <Reference name="x"/>
       <Reference name="y"/>
       <Reject>
         <MathInline>x*x + y*y &gt; 2*variance</MathInline>
       </Reject>
     </RandomSample>
  </Select>
  <Alias name="scaled_variance">
    <MathInline>variance/one_um</MathInline>
  </Alias>
  <RandomVariable name="x" units="um">
    <un:NormalDistribution xmlns:un="http://uncertml.org">
      <un:mean>0.0</un.mean>
      <un:variance>scaled_variance</un.variance>
    </un:NormalDistribution>
  </RandomVariable>
  <RandomVariable name="y" units="um">
    <un:NormalDistribution xmlns:un="http://uncertml.org">
      <un:mean>0.0</un.mean>
      <un:variance>scaled_variance</un.variance>
    </un:NormalDistribution>
  </RandomVariable>
  <Constant name="one_um" value="1.0" units="um"/>
</ConnectionRule>

@tclose tclose changed the title Redrawing random variables Sampling random variables Jun 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant