original_docstring: 
      The mean and variance of the true posterior when |A|=2.
      
docstring: The mean and variance of the true posterior when |A|=2.
docstring_tokens: The mean and variance of the true posterior when |A| = 2 .
code: def posterior_numeric_exact(n_means, n_vars, c_mean, c_var, reward, discount, terminal, varTH = 1e-10,
          scale_factor=1.0, num_interval=2000, width=10.0, noise=0.0, batch=False, REW_VAR = REW_VAR_0):
      """
      The mean and variance of the true posterior when |A|=2.
      """
      assert(len(n_means) == 2)
      target_means = reward + discount*np.array(n_means, dtype = DTYPE) 
      target_vars = discount*discount*np.array(n_vars, dtype = DTYPE)        
      
      bar_vars = 1./(1/c_var + 1./(target_vars + noise))
      bar_means = bar_vars*(c_mean/c_var + target_means/(target_vars+noise))
  
      cdf1 = norm.cdf((bar_means[0]-target_means[1])/np.sqrt(bar_vars[0]+target_vars[1]))
      cdf2 = norm.cdf((bar_means[1]-target_means[0])/np.sqrt(bar_vars[1]+target_vars[0]))
      pdf1 = norm.pdf((bar_means[0]-target_means[1])/np.sqrt(bar_vars[0]+target_vars[1]))/np.sqrt(bar_vars[0]+target_vars[1])
      pdf2 = norm.pdf((bar_means[1]-target_means[0])/np.sqrt(bar_vars[1]+target_vars[0]))/np.sqrt(bar_vars[1]+target_vars[0])
  
      c1 = norm.pdf((target_means[0]-c_mean)/np.sqrt(c_var+target_vars[0]))/np.sqrt(c_var+target_vars[0])
      c2 = norm.pdf((target_means[1]-c_mean)/np.sqrt(c_var+target_vars[1]))/np.sqrt(c_var+target_vars[1])
  
      Z = c1*cdf1 + c2*cdf2
      mean = (c1*(bar_means[0]*cdf1+ bar_vars[0]*pdf1) + c2*(bar_means[1]*cdf2+bar_vars[1]*pdf2))/Z
      sec_moment = c1*((bar_means[0]**2 + bar_vars[0])*cdf1 +2*bar_means[0]*bar_vars[0]*pdf1 - (bar_means[0]-target_means[1])/(bar_vars[0]+target_vars[1])*bar_vars[0]**2*pdf1) \
              + c2*((bar_means[1]**2 + bar_vars[1])*cdf2 +2*bar_means[1]*bar_vars[1]*pdf2 - (bar_means[1]-target_means[0])/(bar_vars[1]+target_vars[0])*bar_vars[1]**2*pdf2)
      var = sec_moment/Z - mean**2
      return mean, var
code_tokens: def posterior_numeric_exact ( n_means , n_vars , c_mean , c_var , reward , discount , terminal , varTH = 1e-10 , scale_factor = 1.0 , num_interval = 2000 , width = 10.0 , noise = 0.0 , batch = False , REW_VAR = REW_VAR_0 ) : assert ( len ( n_means ) == 2 ) target_means = reward + discount * np . array ( n_means , dtype = DTYPE ) target_vars = discount * discount * np . array ( n_vars , dtype = DTYPE ) bar_vars = 1. / ( 1 / c_var + 1. / ( target_vars + noise ) ) bar_means = bar_vars * ( c_mean / c_var + target_means / ( target_vars + noise ) ) cdf1 = norm . cdf ( ( bar_means [ 0 ] - target_means [ 1 ] ) / np . sqrt ( bar_vars [ 0 ] + target_vars [ 1 ] ) ) cdf2 = norm . cdf ( ( bar_means [ 1 ] - target_means [ 0 ] ) / np . sqrt ( bar_vars [ 1 ] + target_vars [ 0 ] ) ) pdf1 = norm . pdf ( ( bar_means [ 0 ] - target_means [ 1 ] ) / np . sqrt ( bar_vars [ 0 ] + target_vars [ 1 ] ) ) / np . sqrt ( bar_vars [ 0 ] + target_vars [ 1 ] ) pdf2 = norm . pdf ( ( bar_means [ 1 ] - target_means [ 0 ] ) / np . sqrt ( bar_vars [ 1 ] + target_vars [ 0 ] ) ) / np . sqrt ( bar_vars [ 1 ] + target_vars [ 0 ] ) c1 = norm . pdf ( ( target_means [ 0 ] - c_mean ) / np . sqrt ( c_var + target_vars [ 0 ] ) ) / np . sqrt ( c_var + target_vars [ 0 ] ) c2 = norm . pdf ( ( target_means [ 1 ] - c_mean ) / np . sqrt ( c_var + target_vars [ 1 ] ) ) / np . sqrt ( c_var + target_vars [ 1 ] ) Z = c1 * cdf1 + c2 * cdf2 mean = ( c1 * ( bar_means [ 0 ] * cdf1 + bar_vars [ 0 ] * pdf1 ) + c2 * ( bar_means [ 1 ] * cdf2 + bar_vars [ 1 ] * pdf2 ) ) / Z sec_moment = c1 * ( ( bar_means [ 0 ] ** 2 + bar_vars [ 0 ] ) * cdf1 + 2 * bar_means [ 0 ] * bar_vars [ 0 ] * pdf1 - ( bar_means [ 0 ] - target_means [ 1 ] ) / ( bar_vars [ 0 ] + target_vars [ 1 ] ) * bar_vars [ 0 ] ** 2 * pdf1 ) + c2 * ( ( bar_means [ 1 ] ** 2 + bar_vars [ 1 ] ) * cdf2 + 2 * bar_means [ 1 ] * bar_vars [ 1 ] * pdf2 - ( bar_means [ 1 ] - target_means [ 0 ] ) / ( bar_vars [ 1 ] + target_vars [ 0 ] ) * bar_vars [ 1 ] ** 2 * pdf2 ) var = sec_moment / Z - mean ** 2 return mean , var
short_docstring: The mean and variance of the true posterior when |A|=2.
short_docstring_tokens: The mean and variance of the true posterior when |A| = 2 .
comment: """
      The mean and variance of the true posterior when |A|=2.
      """