Generate Priors. Generate the label priors.

@param	L	number of labels
@param	z	desired label cardinality
@param	r	random number generator
@param	skew	whether to be very skewed or not (@NOTE not currently used)
@return	P	label prior distribution
11031
private double[] generatePriors(Random r, int L, double z, boolean skew) {
        double P[] = new double[L];
        for (int i = 0; i < L; i++) {
            P[i] = r.nextDouble();
            //P[i] = 1.0; // @temp
        }
        // normalise to z
        do {
            double c = Utils.sum(P) / z;
            for (int i = 0; i < L; i++) {
                P[i] = Math.min(1.0, P[i] / c); // must be in [0,1]
            }
        } while (Utils.sum(P) < z);
        return P;
    }
1094820
def lnprob(self,theta):
        
        global niter
        params,priors,loglike = self.params,self.priors,self.loglike
        # Avoid extra likelihood calls with bad priors
        _lnprior = self.lnprior(theta)
        if np.isfinite(_lnprior):
            _lnlike = self.lnlike(theta)
        else:
            _lnprior = -np.inf
            _lnlike = -np.inf

        _lnprob = _lnprior + _lnlike
     
        if (niter%100==0):
            msg = "%i function calls ...\n"%niter
            msg+= ', '.join('%s: %.3f'%(k,v) for k,v in zip(params,theta))
            msg+= '\nlog(like): %.3f, log(prior): %.3f'%(_lnprior,_lnlike)
            logger.debug(msg)
        niter+=1
        return _lnprob
311907
def generate_samples(label, num_splits, sampler):
    
    def listify(x):
        return x if isinstance(x, list) else [x]
    label_splits = listify(label.split(num_splits, axis=0))
    prob_samples = []
    prob_targets = []
    samples = []
    for label_split in label_splits:
        label_split_2d = label_split.reshape((-1,1))
        sampled_value = sampler.draw(label_split_2d)
        sampled_classes, exp_cnt_true, exp_cnt_sampled = sampled_value
        samples.append(sampled_classes.astype(np.float32))
        prob_targets.append(exp_cnt_true.astype(np.float32).reshape((-1,1)))
        prob_samples.append(exp_cnt_sampled.astype(np.float32))
    return samples, prob_samples, prob_targets
489312
public static void calculateFromPrior(LPC lpc, long[] R, LPC priorLPC) {
    int coeffCount = lpc.order;

    //calculate first iteration directly
    double[] A = lpc.rawCoefficients;
    for(int i = 0; i < coeffCount+1; i++) A[i] = 0.0;
    A[0] = 1;
    double E = R[0];
    int startIter = 0;
    if(priorLPC != null && priorLPC.order < lpc.order) {
      startIter = priorLPC.order;
      E = priorLPC.rawError;
      System.arraycopy(priorLPC.rawCoefficients, 0, A, 0, startIter+1);
    }
    //calculate remaining iterations
    if(R[0] == 0) {
      for(int i = 0; i < coeffCount+1; i++)
        A[i] = 0.0;
    }
    else {
      double[] ATemp = lpc.tempCoefficients;
      for(int i = 0; i < coeffCount+1; i++) ATemp[i] = 0.0;

      for(int k = startIter; k < coeffCount; k++) {
        double lambda = 0.0;
        double temp = 0.0;
        for(int j = 0; j <= k; j++) {
          temp -= A[j]*R[k-j+1];
        }
        lambda = temp/E;

        for(int i = 0; i <= k+1; i++) {
          ATemp[i] = A[i]+lambda*A[k+1-i];
        }
        System.arraycopy(ATemp, 0, A, 0, coeffCount+1);
        E = (1-lambda*lambda)*E;
      }
    }
    lpc.rawError = E;
  }
622882
public void setRotation(float r) {
		double d = 2.0 * Math.PI;
		rotationRadians = (float) ((r + initialRotation) % d);
		if (rotationRadians < 0) {
			rotationRadians += d;
		}
		float[] matrix = matrix();
		scaledWidth = matrix[DX] - matrix[CX];
		scaledHeight = matrix[DY] - matrix[CY];
	}
82123
@Override
    public INDArray rand(int[] shape, Distribution r) {
        INDArray ret = r.sample(shape);
        return ret;
    }
556358
public void orizzonte5( double delta, int quadrata, double beta, double alfa, RandomIter elevImageIterator,
            WritableRaster curvatureImage, int[][] shadow ) {
        int rows = curvatureImage.getHeight();
        int cols = curvatureImage.getWidth();
        /*=====================*/

        int y, I, J;
        double zenith;

        /*======================*/

        for( int j = quadrata; j >= 0; j-- ) {
            I = -1;
            J = -1;
            y = 0;
            for( int jj = j; jj < quadrata; jj++ ) {
                for( int i = rows - (int) floor(1 / tan(beta) * (jj - j)) - 1; i >= rows
                        - (int) floor(1 / tan(beta) * (jj - j + 1)) - 1
                        && i >= 0; i-- ) {
                    if (jj >= quadrata - cols && !isNovalue(elevImageIterator.getSampleDouble(jj - (quadrata - cols), i, 0))) {
                        /*shadow.element[i][jj-(quadrata-Z0.nch)]=j;}}}}*/
                        if (curvatureImage.getSampleDouble(jj - (quadrata - cols), i, 0) == 1 && I == -1) {
                            I = i;
                            J = jj - (quadrata - cols);
                            y = 1;
                        } else if (curvatureImage.getSampleDouble(jj - (quadrata - cols), i, 0) == 1 && I != -1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(jj
                                    - (quadrata - cols), i, 0))
                                    / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                            + pow((double) (J - (jj - (quadrata - cols))) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[i][jj - (quadrata - cols)] = 0;
                                I = i;
                                J = jj - (quadrata - cols);
                            } else {
                                shadow[i][jj - (quadrata - cols)] = 1;
                            }
                        } else if (curvatureImage.getSampleDouble(jj - (quadrata - cols), i, 0) == 0 && y == 1) {
                            zenith = (elevImageIterator.getSampleDouble(J, I, 0) - elevImageIterator.getSampleDouble(jj
                                    - (quadrata - cols), i, 0))
                                    / sqrt(pow((double) (I - i) * (double) delta, (double) 2)
                                            + pow((double) (J - (jj - (quadrata - cols))) * (double) delta, (double) 2));
                            if (zenith <= tan(alfa)) {
                                shadow[i][jj - (quadrata - cols)] = 0;
                                y = 0;
                            } else {
                                shadow[i][jj - (quadrata - cols)] = 1;
                            }
                        }
                    }
                }
            }
        }

    }
1176008
function zOrder(x, y, minX, minY, invSize) {
       // coords are transformed into non-negative 15-bit integer range
       x = 32767 * (x - minX) * invSize;
       y = 32767 * (y - minY) * invSize;

       x = (x | (x << 8)) & 0x00FF00FF;
       x = (x | (x << 4)) & 0x0F0F0F0F;
       x = (x | (x << 2)) & 0x33333333;
       x = (x | (x << 1)) & 0x55555555;

       y = (y | (y << 8)) & 0x00FF00FF;
       y = (y | (y << 4)) & 0x0F0F0F0F;
       y = (y | (y << 2)) & 0x33333333;
       y = (y | (y << 1)) & 0x55555555;

       return x | (y << 1);
   }
1139542
public static double pdf(double x, double mu, double sigma, double skew) {
    if(x != x) {
      return Double.NaN;
    }
    x = (x - mu) / sigma; // Scale
    if(skew == 0.) {
      return MathUtil.ONE_BY_SQRTTWOPI / sigma * FastMath.exp(-.5 * x * x);
    }
    final double y = -FastMath.log1p(-skew * x) / skew;
    if(y != y || y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY) { // NaN
      return 0.;
    }
    return MathUtil.ONE_BY_SQRTTWOPI / sigma * FastMath.exp(-.5 * y * y) / (1 - skew * x);
  }
491921
public static final Vector3D randVertex2d() {
        float theta = random((float)(Math.PI*2.0));
        return new Vector3D(Math.cos(theta),Math.sin(theta));
    }
1199070
private void getSymmetryAxes(List<Axis> symmAxes, Matrix4d prior, int level, int firstRepeat) {
		if(level >= getNumLevels() ) {
			return;
		}

		Axis elem = axes.get(level);
		Matrix4d elemOp = elem.getOperator();

		// Current axis:
		// elementary maps B -> A
		// prior maps I -> A and J -> B
		// want J -> I = J -> B -> A <- I= inv(prior) * elementary * prior
		Matrix4d currAxisOp = new Matrix4d(prior);
		currAxisOp.invert();
		currAxisOp.mul(elemOp);
		currAxisOp.mul(prior);
		Axis currAxis = new Axis(currAxisOp,elem.getOrder(),elem.getSymmType(),level,firstRepeat);
		symmAxes.add(currAxis);

		//Remember that all degrees are at least 2
		getSymmetryAxes(symmAxes,prior,level+1,firstRepeat);
		//New prior is elementary^d*prior
		Matrix4d newPrior = new Matrix4d(elemOp);
		newPrior.mul(prior);
		int childSize = getNumRepeats(level+1);
		getSymmetryAxes(symmAxes,newPrior,level+1,firstRepeat+childSize);
		for(int d=2;d<elem.getOrder();d++) {
			newPrior.mul(elemOp,newPrior);
			getSymmetryAxes(symmAxes,newPrior,level+1,firstRepeat+childSize*d);
		}
	}
305355
def _log_P(self, X , Z, k):
        
        r_ = self._r_
        Z_ = self._Z_
        # zero case
        if k == 0 :
            log_P = Z['log_p'] + log_K(X, Z, r_[k])
        # recursice case
        else :
            P_zk_z = np.exp( self._log_P(Z_[k], Z, k-1) )
            P_z_zk = np.exp( self._log_P(Z, Z_[k], k-1) ) 
            # flag
            if P_zk_z <= P_z_zk :
                self._N_is_0 = True
                log_P = -np.inf
            else : 
                log_P = np.log( P_zk_z - P_z_zk ) + log_K(X, Z, r_[k])
        return log_P
780473
def pdf_new(self, x, mu, sigma, skw):
        
        if skw > 1 or skw < -1:
            print("skewness %s out of range" % skw)
            skw = 1.
        e, w, a = self.map_mu_sigma_skw(mu, sigma, skw)
        pdf = self.pdf(x, e, w, a)
        return pdf
87015
public static Axis generateAxisFromCollection(List<Float> axisValues, List<String> axisValuesLabels) {
        if (axisValues.size() != axisValuesLabels.size()) {
            throw new IllegalArgumentException("Values and labels lists must have the same size!");
        }

        List<AxisValue> values = new ArrayList<AxisValue>();
        int index = 0;
        for (float value : axisValues) {
            AxisValue axisValue = new AxisValue(value).setLabel(axisValuesLabels.get(index));
            values.add(axisValue);
            ++index;
        }

        Axis axis = new Axis(values);
        return axis;
    }
172531
function ecp_sign(r, s, p, a, G, n, d, z, l) {
	var R = ecp_new(l), S = ecp_new(l), k = mpn_new(l);
	for (;;) {
		for (var i = 0; i < l; ++i) {
			k[i] = Math.random() * 0x80000000 | 0;
		}
		var r0 = ecp_proj(R, ecp_mul(S, k, G, a, p, l), p, l)[0];
		if (mpn_cmp(r0, n, l) >= 0) {
			mpn_sub(r0, r0, n, l);
		}
		if (!mpn_zero_p(r0, l)) {
			var t0 = _ecp_t0, t1 = _ecp_t1;
			fp_mul(s, fp_inv(t0, k, n, l), fp_add(t1, z, fp_mul(t1, r0, d, n, l), n, l), n, l);
			if (!mpn_zero_p(s, l)) {
				mpn_copyi(r, r0, l);
				break;
			}
		}
	}
}
765754
def param_labels(self):
        """"""

        paramnames_labels = []
        prior_class_dict = self.variable.prior_class_dict
        prior_prior_model_dict = self.variable.prior_prior_model_dict

        for prior_name, prior in self.variable.prior_tuples_ordered_by_id:
            param_string = self.label_config.label(prior_name)
            prior_model = prior_prior_model_dict[prior]
            cls = prior_class_dict[prior]
            cls_string = "{}{}".format(self.label_config.subscript(cls), prior_model.component_number + 1)
            param_label = "{}_{{\\mathrm{{{}}}}}".format(param_string, cls_string)
            paramnames_labels.append(param_label)

        return paramnames_labels
517658
def get_priors(like):
    """"""

    npar = len(like.params())

    vals = np.ones(npar)
    errs = np.ones(npar)
    has_prior = np.array([False] * npar)

    for i, p in enumerate(like.params()):

        prior = like[i].log_prior()

        if prior is None:
            continue

        par_names = pyLike.StringVector()
        prior.getParamNames(par_names)

        if not 'Mean' in par_names:
            raise Exception('Failed to find Mean in prior parameters.')

        if not 'Sigma' in par_names:
            raise Exception('Failed to find Sigma in prior parameters.')

        for t in par_names:

            if t == 'Mean':
                vals[i] = prior.parameter(t).getValue()

            if t == 'Sigma':
                errs[i] = prior.parameter(t).getValue()

        has_prior[i] = True

    return vals, errs, has_prior