ValueError: Domain error in arguments scipy rv_continuous
<p>I was trying to sample random variables subject to a given probability density function (pdf) with scipy.stats.rv_continuous:</p>

<pre><code>class Distribution(stats.rv_continuous):
    def _pdf(self,x, _a, _c):
        return first_hitting_time(x, _a, _c)
</code></pre>

<p>where the function <em>first_hitting_time</em> is</p>

<pre><code>#pdf of first hitting time of W_t + c*t on a. 
def first_hitting_time(_t, _a, _c=0.0):
    return _a/_t*np.exp(-0.5/_t*(_a-_c*_t)**2)/np.sqrt(2.0*np.pi*_t)
</code></pre>

<p>then I continue with</p>

<pre><code>myrv= Distribution(name='hittingtime', a=0.002,b=30.0)
data3= myrv.rvs(size=10000, _a=1.0, _c=0.0)
</code></pre>

<p>and interpreter starts to complain-</p>

<pre><code>Traceback (most recent call last):

  File "&lt;ipython-input-246-71f67047462b&gt;", line 1, in &lt;module&gt;
    data3= myrv.rvs(size=10000, _a=1.0, _c=0.0)

  File "C:\Users\ME\AppData\Local\Continuum\Anaconda2\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 856, in rvs
    raise ValueError("Domain error in arguments.")

ValueError: Domain error in arguments.
</code></pre>

<p>it seems if I set <code>_c</code> to be some number larger than 0.0, it works fine, but not for <code>_c</code> less than 0. </p>

<p>I am a bit confused about this. Any help would be appreciated. </p>

<p>From <a href="https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.stats.rv_continuous.html" rel="nofollow">the documentation</a>:</p>

<blockquote>
  <h3>Subclassing</h3>
  
  <p>New random variables can be defined by subclassing the rv_continuous
  class and re-defining at least the <code>_pdf</code> or the <code>_cdf</code> method (normalized
  to location 0 and scale 1).</p>
  
  <p><strong>If positive argument checking is not correct</strong> for your RV then you will
  also need to re-define the <code>_argcheck</code> method.</p>
</blockquote>

<p>It's not clear to me from your function what <code>_a</code> and <code>_c</code> represent, but it looks like you want to allow them to be negative.</p>

<p>See the default implementation <a href="https://github.com/scipy/scipy/blob/master/scipy/stats/_distn_infrastructure.py#L859-L869" rel="nofollow">in the source of <code>_distn_infrastructure</code></a></p>

python numpy scipy