CDF: $$ F(x) = \begin{cases} 0 & x <0,\\ x & 0 \leq x < 0.5,\\ \frac{x}{2} + 0.5 & 0.5 \leq x \leq 1\\ 1 & x>2 \end{cases} $$

PDF:

$$ f(x) = \begin{cases} 0 & x <0,\\ 1 & 0 \leq x < 0.5,\\ \frac{1}{2} & 0.5 \leq x \leq 1\\ 0 & x>2 \end{cases} $$

$\int f(t) dt = 0.75$??

What's missing?

p[X=0.5] = 0.25. But defining such a probability should be $0$ for a PDF.[It's technically a 'PMF'. The mass at 0.5 being 1/4]


In [15]:
%matplotlib inline
from __future__ import division
def F(x):
    if x<0:
        return 0
    if x<0.5:
        return x
    if x>=0.5 and x<=1:
        return x/2+0.5
    return 1
    
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2,2, num=100)
fx =[F(i) for i in x]
pos = np.where((x<=0.51) & (x>=0.49))[0]

x[pos] = np.nan
fx[pos] = np.nan
plt.plot(x,fx)


/home/saket/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:19: DeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
Out[15]:
[<matplotlib.lines.Line2D at 0x7f95e581c410>]