Computes the marginal distribution of the ith element.

        See http://en.wikipedia.org/wiki/Dirichlet_distribution
        #Marginal_distributions

        i: int

        Returns: Beta object
552652
def MarginalBeta(self, i):
        
        alpha0 = self.params.sum()
        alpha = self.params[i]
        return Beta(alpha, alpha0 - alpha)
1364382
def get_zeta_i_j_given_separate_counts(self, y_i, y_j):
		'''
		
		'''
		n_i, n_j = y_i.sum(), y_j.sum()
		delta_i_j = (np.log((y_i + 1) / (1. + n_i - y_i))
		             - np.log((y_j + 1) / (1. + n_j - y_j)))
		return delta_i_j
778281
def convenience_calc_probs(self, params):
        
        orig_nest_coefs, betas = self.convenience_split_params(params)
        natural_nest_coefs = nc.naturalize_nest_coefs(orig_nest_coefs)

        args = [natural_nest_coefs,
                betas,
                self.design,
                self.rows_to_obs,
                self.rows_to_nests]
        kwargs = {"chosen_row_to_obs": self.chosen_row_to_obs,
                  "return_type": "long_and_chosen_probs"}

        probability_results = general_calc_probabilities(*args, **kwargs)

        return probability_results
478492
def _get_internal_delta(self):
        

        if self._transformation is None:

            return self._delta

        else:

            delta_int = None

            for i in range(2):

                # Try using the low bound

                low_bound_ext = self.value - self.delta

                # Make sure we are within the margins

                if low_bound_ext > self.min_value:

                    # Ok, let's use that for the delta
                    low_bound_int = self._transformation.forward(low_bound_ext)

                    delta_int = abs(low_bound_int - self._get_internal_value())

                    break

                else:

                    # Nope, try with the hi bound

                    hi_bound_ext = self.value + self._delta

                    if hi_bound_ext < self.max_value:

                        # Ok, let's use it
                        hi_bound_int = self._transformation.forward(hi_bound_ext)
                        delta_int = abs(hi_bound_int - self._get_internal_value())

                        break

                    else:

                        # Fix delta
                        self.delta = abs(self.value - self.min_value) / 4.0

                        if self.delta == 0:

                            # Parameter at the minimum
                            self.delta = abs(self.value - self.max_value) / 4.0

                        # Try again
                        continue

            assert delta_int is not None, "Bug"

            return delta_int
550243
private double delta(double y, double bMutationParameter) {
    double rand = randomGenenerator.getRandomValue();
    int it, maxIt;
    it = currentIteration;
    maxIt = maxIterations;

    return (y * (1.0 -
        Math.pow(rand,
            Math.pow((1.0 - it / (double) maxIt), bMutationParameter)
        )));
  }
1316296
def _get_covariance(self, X):
        
        result = pd.DataFrame(index=range(len(X)))
        column_names = self.get_column_names(X)
        for column_name in column_names:
            column = self.get_column(X, column_name)
            distrib = self.distribs[column_name]

            # get original distrib's cdf of the column
            cdf = distrib.cumulative_distribution(column)

            if distrib.constant_value is not None:
                # This is to avoid np.inf in the case the column is constant.
                cdf = np.ones(column.shape) - EPSILON

            # get inverse cdf using standard normal
            result = self.set_column(result, column_name, stats.norm.ppf(cdf))

        # remove any rows that have infinite values
        result = result[(result != np.inf).all(axis=1)]
        return pd.DataFrame(data=result).cov().values
1336809
def distribution(self, limit=1024):
        
        res = self._qexec("%s, count(*) as __cnt" % self.name(), group="%s" % self.name(),
                          order="__cnt DESC LIMIT %d" % limit)
        dist = []
        cnt = self._table.size()
        for i, r in enumerate(res):
            dist.append(list(r) + [i, r[1] / float(cnt)])

        self._distribution = pd.DataFrame(dist, columns=["value", "cnt", "r", "fraction"])
        self._distribution.index = self._distribution.r

        return self._distribution
356698
function (D, perplexity, tol) {
		var Nf = Math.sqrt(D.length); // this better be an integer
		var N = Math.floor(Nf);
		assert(N === Nf, "D should have square number of elements.");
		var Htarget = Math.log(perplexity); // target entropy of distribution
		var P = zeros(N * N); // temporary probability matrix

		var prow = zeros(N); // a temporary storage compartment
		for (var i = 0; i < N; i++) {
			var betamin = -Infinity;
			var betamax = Infinity;
			var beta = 1; // initial value of precision
			var done = false;
			var maxtries = 50;

			// perform binary search to find a suitable precision beta
			// so that the entropy of the distribution is appropriate
			var num = 0;
			while (!done) {
				//debugger;

				// compute entropy and kernel row with beta precision
				var psum = 0.0;
				for (var j = 0; j < N; j++) {
					var pj = Math.exp(-D[i * N + j] * beta);
					if (i === j) {
						pj = 0;
					} // we dont care about diagonals
					prow[j] = pj;
					psum += pj;
				}
				// normalize p and compute entropy
				var Hhere = 0.0;
				for (var j = 0; j < N; j++) {
					var pj = prow[j] / psum;
					prow[j] = pj;
					if (pj > 1e-7) Hhere -= pj * Math.log(pj);
				}

				// adjust beta based on result
				if (Hhere > Htarget) {
					// entropy was too high (distribution too diffuse)
					// so we need to increase the precision for more peaky distribution
					betamin = beta; // move up the bounds
					if (betamax === Infinity) {
						beta = beta * 2;
					}
					else {
						beta = (beta + betamax) / 2;
					}

				} else {
					// converse case. make distrubtion less peaky
					betamax = beta;
					if (betamin === -Infinity) {
						beta = beta / 2;
					}
					else {
						beta = (beta + betamin) / 2;
					}
				}

				// stopping conditions: too many tries or got a good precision
				num++;
				if (Math.abs(Hhere - Htarget) < tol) {
					done = true;
				}
				if (num >= maxtries) {
					done = true;
				}
			}

			// console.log('data point ' + i + ' gets precision ' + beta + ' after ' + num + ' binary search steps.');
			// copy over the final prow to P at row i
			for (var j = 0; j < N; j++) {
				P[i * N + j] = prow[j];
			}

		} // end loop over examples i

		// symmetrize P and normalize it to sum to 1 over all ij
		var Pout = zeros(N * N);
		var N2 = N * 2;
		for (var i = 0; i < N; i++) {
			for (var j = 0; j < N; j++) {
				Pout[i * N + j] = Math.max((P[i * N + j] + P[j * N + i]) / N2, 1e-100);
			}
		}

		return Pout;
	}
1167254
def vp(self):
        
        return np.sqrt(self.mu * (2 / (self.rp) - 1 / self.kep.a))
987219
def _call_marginalizevperp(self,o,integrate_method='dopr54_c',**kwargs):
        """"""
        #Get d, l, vlos
        l= o.ll(obs=[1.,0.,0.],ro=1.)*_DEGTORAD
        vlos= o.vlos(ro=1.,vo=1.,obs=[1.,0.,0.,0.,0.,0.])
        R= o.R(use_physical=False)
        phi= o.phi(use_physical=False)
        #Get local circular velocity, projected onto the los
        if isinstance(self._pot,list):
            vcirc= calcRotcurve([p for p in self._pot if not p.isNonAxi],R)[0]
        else:
            vcirc= calcRotcurve(self._pot,R)[0]
        vcirclos= vcirc*math.sin(phi+l)
        #Marginalize
        alphalos= phi+l
        if not 'nsigma' in kwargs or ('nsigma' in kwargs and \
                                          kwargs['nsigma'] is None):
            nsigma= _NSIGMA
        else:
            nsigma= kwargs['nsigma']
        kwargs.pop('nsigma',None)
        #BOVY: add asymmetric drift here?
        if math.fabs(math.sin(alphalos)) < math.sqrt(1./2.):
            sigmaR1= nu.sqrt(self._initdf.sigmaT2(R,phi=phi,
                                                  use_physical=False)) #Slight abuse
            cosalphalos= math.cos(alphalos)
            tanalphalos= math.tan(alphalos)
            return integrate.quad(_marginalizeVperpIntegrandSinAlphaSmall,
                                  -nsigma,nsigma,
                                  args=(self,R,cosalphalos,tanalphalos,
                                        vlos-vcirclos,vcirc,
                                        sigmaR1,phi),
                                  **kwargs)[0]/math.fabs(cosalphalos)*sigmaR1
        else:
            sigmaR1= nu.sqrt(self._initdf.sigmaR2(R,phi=phi,
                                                  use_physical=False))
            sinalphalos= math.sin(alphalos)
            cotalphalos= 1./math.tan(alphalos)
            return integrate.quad(_marginalizeVperpIntegrandSinAlphaLarge,
                                  -nsigma,nsigma,
                                  args=(self,R,sinalphalos,cotalphalos,
                                        vlos-vcirclos,vcirc,sigmaR1,phi),
                                  **kwargs)[0]/math.fabs(sinalphalos)*sigmaR1
800640
def rbeta(alpha, beta, size=None):
    
    from scipy.stats.distributions import beta as sbeta
    return sbeta.ppf(np.random.random(size), alpha, beta)
1183039
def convenience_calc_probs(self, params):
        
        shapes, intercepts, betas = self.convenience_split_params(params)

        prob_args = (betas,
                     self.design_3d,
                     self.alt_id_vector,
                     self.rows_to_obs,
                     self.rows_to_alts,
                     self.utility_transform)
        prob_kwargs = {"chosen_row_to_obs": self.chosen_row_to_obs,
                       "return_long_probs": True}
        probability_results = general_calc_probabilities(*prob_args,
                                                         **prob_kwargs)

        return probability_results
1311409
def marginal_zero(repertoire, node_index):
    """"""
    index = [slice(None)] * repertoire.ndim
    index[node_index] = 0

    return repertoire[tuple(index)].sum()
554591
def _getScalesRand(self):
        
        if self.P>1:
            scales = []
            for term_i in range(self.n_terms):
                _scales = SP.randn(self.diag[term_i].shape[0])
                if self.offset[term_i]>0:
                    _scales = SP.concatenate((_scales,SP.array([SP.sqrt(self.offset[term_i])])))
                scales.append(_scales)
            scales = SP.concatenate(scales)
        else:
            scales=SP.randn(self.vd.getNumberScales())

        return scales
115440
def sd(self):
        ''''''
        v = self.var()
        if len(v):
            return np.sqrt(v)
        else:
            return None
1337693
def convenience_calc_probs(self, params):
        
        shapes, intercepts, betas = self.convenience_split_params(params)

        prob_args = [betas,
                     self.design,
                     self.alt_id_vector,
                     self.rows_to_obs,
                     self.rows_to_alts,
                     self.utility_transform]

        prob_kwargs = {"intercept_params": intercepts,
                       "shape_params": shapes,
                       "chosen_row_to_obs": self.chosen_row_to_obs,
                       "return_long_probs": True}
        prob_results = cc.calc_probabilities(*prob_args, **prob_kwargs)

        return prob_results
1286929
double betaFunction(List<Double> x, int type) {
    double beta;
    beta = 0;
    int dim = x.size();

    if (dim == 0) {
      beta = 0;
    }

    if (type == 1) {
      beta = 0;
      for (int i = 0; i < dim; i++) {
        beta += x.get(i) * x.get(i);
      }
      beta = 2.0 * beta / dim;
    }

    if (type == 2) {
      beta = 0;
      for (int i = 0; i < dim; i++) {
        beta += Math.sqrt(i + 1) * x.get(i) * x.get(i);
      }
      beta = 2.0 * beta / dim;
    }

    if (type == 3) {
      double sum = 0, xx;
      for (int i = 0; i < dim; i++) {
        xx = 2 * x.get(i);
        sum += (xx * xx - Math.cos(4 * Math.PI * xx) + 1);
      }
      beta = 2.0 * sum / dim;
    }

    if (type == 4) {
      double sum = 0, prod = 1, xx;
      for (int i = 0; i < dim; i++) {
        xx = 2 * x.get(i);
        sum += xx * xx;
        prod *= Math.cos(10 * Math.PI * xx / Math.sqrt(i + 1));
      }
      beta = 2.0 * (sum - 2 * prod + 2) / dim;
    }

    return beta;
  }