当前位置: 首页>>代码示例>>Java>>正文


Java Functions类代码示例

本文整理汇总了Java中cern.jet.math.Functions的典型用法代码示例。如果您正苦于以下问题:Java Functions类的具体用法?Java Functions怎么用?Java Functions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Functions类属于cern.jet.math包,在下文中一共展示了Functions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: normalizePuz

import cern.jet.math.Functions; //导入依赖的package包/类
/**
 * Normalizes matrix of p(z|u) such that \forall_u: \sum_z p(z|u) = 1.
 *
 * @param pu_z normalized matrix of p(z|u)
 */
@Override
protected void normalizePuz(DoubleMatrix2D pu_z) {
    for (int u = 0; u < pu_z.rows(); u++) {
        DoubleMatrix1D tmp = pu_z.viewRow(u);
        double norm = tmp.aggregate(Functions.plus, Functions.identity);
        if (norm != 0.0) {
            tmp.assign(Functions.mult(1 / norm));
        }
    }
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:16,代码来源:CPLSAIAFactorizationModelFactory.java

示例2: normalizePiz

import cern.jet.math.Functions; //导入依赖的package包/类
/**
 * Normalizes matrix of p(i|z) such that \forall_z: \sum_i p(i|z) = 1.
 *
 * @param piz normalized matrix of p(i|z)
 */
@Override
protected void normalizePiz(DoubleMatrix2D piz) {
    for (int i = 0; i < piz.columns(); i++) {
        DoubleMatrix1D tmp = piz.viewColumn(i);
        double norm = tmp.aggregate(Functions.plus, Functions.identity);
        if (norm != 0.0) {
            tmp.assign(Functions.mult(1 / norm));
        }
    }
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:16,代码来源:CPLSAIAFactorizationModelFactory.java

示例3: updatePi

import cern.jet.math.Functions; //导入依赖的package包/类
/**
 * Update the initial state probabilities. 
 * Calculations done in log-space.
 */
private void updatePi() {
  //set up a matrix whose columns will hold the gamma(z_0) vector of each
  //analysis region
  DoubleMatrix2D logGamma_zeros = new DenseDoubleMatrix2D(hmm_numStates, analysisRegions.size());
  for (int i = 0; i < analysisRegions.size(); i++) {
    HMMAnalysisRegion region = analysisRegions.get(i);
    logGamma_zeros.viewColumn(i).assign(region.getLogGamma().viewRow(0));      
  }
  
  //the sums along each of the rows will be the numerators for the update eqs  
  DoubleMatrix1D hmm_LogPi_new = new DenseDoubleMatrix1D(hmm_numStates);
  for (int k = 0; k < hmm_numStates; k++) {
    hmm_LogPi_new.setQuick(k, Numerical.log_sum_exp(logGamma_zeros.viewRow(k)));
  }
  
  //summing all of those numerators will give the denominator for the update eq
  double logGammaSum = Numerical.log_sum_exp(hmm_LogPi_new);
  hmm_LogPi_new.assign(Functions.minus(logGammaSum));
  
  hmm_LogPi = hmm_LogPi_new;
}
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:26,代码来源:BindingMotifHMM.java

示例4: ridge

import cern.jet.math.Functions; //导入依赖的package包/类
/**
 * 
 * @param n => (n_max x N) Matrix where each row is state of reservoir for each time step
 * @param y => (n_max x L) Matrix where each row is state of output for each time step
 * @param alpha The idenity coefficient. This can be found using cross-validation
 * @return
 */
public static DoubleMatrix2D ridge(DoubleMatrix2D n, DoubleMatrix2D y, double alpha){
	DoubleFactory2D factory = DoubleFactory2D.dense;

	//force same type, this is giving a cast error. Bug on their part?
	DoubleMatrix2D _n = factory.make(n.toArray());
	DoubleMatrix2D _y = factory.make(y.toArray());

	
	//aI
	DoubleMatrix2D scaledIdentity = factory.identity(_n.rows()).assign(Functions.mult(alpha));
	
	
	Algebra alg = new Algebra();
	// ((n x n^T) + aI)^-1
	// (n_max x N) x (N x n_max)
	DoubleMatrix2D inverse = alg.inverse(n.zMult(_n.viewDice(), null).assign(scaledIdentity, Functions.plus));
	//System.out.println("-1=" + inverse);

	//X = ((n x n^T) + aI)^-1 x n
	// (n_max x n_max) x 
	DoubleMatrix2D X = inverse.zMult(_n, null);
	//System.out.println("X=" + X);
	//((n x n^T) + aI)^-1 x n x y
	DoubleMatrix2D weights = X.viewDice().zMult(_y, null);
	//X.viewDice()
	return weights;	
}
 
开发者ID:wil3,项目名称:lacus,代码行数:35,代码来源:MLMatrixUtils.java

示例5: log_sum_exp

import cern.jet.math.Functions; //导入依赖的package包/类
public static double log_sum_exp(DoubleMatrix1D exponents) {
  double maxExp = exponents.aggregate(Functions.max, Functions.identity);
  if (maxExp == Double.NEGATIVE_INFINITY) {
    return Double.NEGATIVE_INFINITY;
  }
  else {
    double expSum = exponents.aggregate(Functions.plus, Functions.chain(Functions.exp, Functions.minus(maxExp)));
    return maxExp + Math.log(expSum);
  }
}
 
开发者ID:seqcode,项目名称:seqcode-core,代码行数:11,代码来源:Numerical.java

示例6: plus

import cern.jet.math.Functions; //导入依赖的package包/类
public Matrix plus(double value) {
	Matrix result = new ColtSparseDoubleMatrix2D((SparseDoubleMatrix2D) matrix.copy().assign(Functions.plus(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtSparseDoubleMatrix2D.java

示例7: times

import cern.jet.math.Functions; //导入依赖的package包/类
public Matrix times(double value) {
	Matrix result = new ColtSparseDoubleMatrix2D((SparseDoubleMatrix2D) matrix.copy().assign(Functions.mult(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtSparseDoubleMatrix2D.java

示例8: divide

import cern.jet.math.Functions; //导入依赖的package包/类
public Matrix divide(double value) {
	Matrix result = new ColtSparseDoubleMatrix2D((SparseDoubleMatrix2D) matrix.copy().assign(Functions.div(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtSparseDoubleMatrix2D.java

示例9: minus

import cern.jet.math.Functions; //导入依赖的package包/类
public Matrix minus(double value) {
	Matrix result = new ColtSparseDoubleMatrix2D((SparseDoubleMatrix2D) matrix.copy()
			.assign(Functions.minus(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:10,代码来源:ColtSparseDoubleMatrix2D.java

示例10: plus

import cern.jet.math.Functions; //导入依赖的package包/类
public Matrix plus(double value) {
	Matrix result = new ColtDenseDoubleMatrix2D((DenseDoubleMatrix2D) matrix.copy().assign(Functions.plus(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtDenseDoubleMatrix2D.java

示例11: minus

import cern.jet.math.Functions; //导入依赖的package包/类
public Matrix minus(double value) {
	Matrix result = new ColtDenseDoubleMatrix2D((DenseDoubleMatrix2D) matrix.copy().assign(Functions.minus(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtDenseDoubleMatrix2D.java

示例12: times

import cern.jet.math.Functions; //导入依赖的package包/类
public Matrix times(double value) {
	Matrix result = new ColtDenseDoubleMatrix2D((DenseDoubleMatrix2D) matrix.copy().assign(Functions.mult(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtDenseDoubleMatrix2D.java

示例13: divide

import cern.jet.math.Functions; //导入依赖的package包/类
public Matrix divide(double value) {
	Matrix result = new ColtDenseDoubleMatrix2D((DenseDoubleMatrix2D) matrix.copy().assign(Functions.div(value)));
	MapMatrix<String, Object> a = getMetaData();
	if (a != null) {
		result.setMetaData(a.clone());
	}
	return result;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:9,代码来源:ColtDenseDoubleMatrix2D.java

示例14: CalculatePortfolioStandardDeviation

import cern.jet.math.Functions; //导入依赖的package包/类
/**
  * Compute the stock portfolio return standard deviation (sigma, a number).
  * 
  * A. Compute the stock portfolio covariance matrix:
  *   1. Calculate log-returns: aR(t) = log(p(t)/p(t-1)).
  *   2. Estimate the log-returns: maR(t) = d*aR(t) + (1-d)*maR(t-1) where d is memory.
  *   3. Estimate the covariance matrix:
  *      Cov(t) = d*(outer(aR(t)-maR(t),aR(t)-maR(t)) + (1-d)*Cov(t-1).
  * 
  * B. Compute the deviation of portfolio returns:
  *   1. Variance sigma**2 of the stock portfolio : sigma**2 = w**T.Cov.w 
  *   2. Assume, for simplicity, that loans have same variance.
  *   3. Return sqrt(sigma**2 + (1-sum(w))**2*s**2).
  */
static double CalculatePortfolioStandardDeviation(
   int numberOfFirmsToInvestIn,
   List<Double> firmMarketValuesNow,
   List<Double> firmMarketValuesLast,
   double[] firmStockWeights,
   double covarianceAdaptationRate,
   DoubleMatrix1D meanLogStockReturns,
   DoubleMatrix2D meanStockCovarianceMatrix
   ) {
   Algebra algebra = new Algebra();
   DenseDoubleMatrix1D logOfStockReturns = new DenseDoubleMatrix1D(numberOfFirmsToInvestIn);
   for (int i = 0; i < numberOfFirmsToInvestIn; ++i) {
      double presentOverLastValue = (firmMarketValuesNow.get(i) / firmMarketValuesLast.get(i));
      if (presentOverLastValue > 0.) 
         logOfStockReturns.set(i, Math.log(presentOverLastValue));
      else logOfStockReturns.set(i, 0.);
   }
   
   meanLogStockReturns.assign(
      logOfStockReturns.copy().assign(Functions.mult(covarianceAdaptationRate))
      .assign(meanLogStockReturns.copy().assign(Functions.mult(1. - covarianceAdaptationRate)), 
         Functions.plus));
   
   logOfStockReturns.assign(meanLogStockReturns, Functions.minus);
   DoubleMatrix2D newCovMatrix = 
      DoubleFactory2D.dense.make(numberOfFirmsToInvestIn, numberOfFirmsToInvestIn);
   algebra.multOuter(logOfStockReturns, logOfStockReturns, newCovMatrix);
   
   meanStockCovarianceMatrix.assign(
      newCovMatrix.copy().assign(Functions.mult(covarianceAdaptationRate))
      .assign(meanStockCovarianceMatrix.copy().assign(
         Functions.mult(1. - covarianceAdaptationRate)), Functions.plus));
   
   DoubleMatrix1D stockWeightsVector =
      new DenseDoubleMatrix1D(firmStockWeights);
   final double
      loanWeight = (1. - stockWeightsVector.zSum()),
      sigmaSquared = algebra.mult(stockWeightsVector,
         algebra.mult(meanStockCovarianceMatrix, stockWeightsVector));
   
   return Math.sqrt(sigmaSquared * (1. + loanWeight * loanWeight));
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:57,代码来源:ValueAtRiskLeverageTargetAlgorithm.java

示例15: checkLikelihood

import cern.jet.math.Functions; //导入依赖的package包/类
private void checkLikelihood(DoubleMatrix2D logAlpha, DoubleMatrix2D logBeta) {
	double logLikelihood = Numerical.log_sum_exp(logAlpha.viewRow(0).copy().assign(logBeta.viewRow(0), Functions.plus));
	TreeMap<Integer, Double> mismatches = new TreeMap<Integer, Double>();
	for (int m = 1; m < logAlpha.rows(); m++) {
		double currentLL = Numerical.log_sum_exp(logAlpha.viewRow(m).copy().assign(logBeta.viewRow(m), Functions.plus));
		for (int j = 0; j < hmm_numStates; j++) {
			if (isStateFixedDuration[j] && (stateDurations[j] > 1)) {
				int start = Math.max(0, m - stateDurations[j] + 1);
				for (int n = start; n < m; n++) {
					currentLL = Numerical.log_add(currentLL, (logAlpha.getQuick(n, j) + logBeta.getQuick(n,j)));
				}
			}
		}
		if (Math.abs(logLikelihood - currentLL) > (double)1E-6) {
			mismatches.put(m, currentLL);
		}
	}
	
	if (!mismatches.isEmpty()) {
		StringBuffer errormsg = new StringBuffer();
		errormsg.append("Log-Likelihood calculations from forward-backward algorithm are NaN or inconsistent\n" + "0: " + logLikelihood);
		for (int pos : mismatches.keySet()) {
			errormsg.append(pos + ": " + mismatches.get(pos) + "\n");
		}
		logger.error(errormsg.toString());
		System.exit(1);
	}
}
 
开发者ID:shaunmahony,项目名称:multigps-archive,代码行数:29,代码来源:BindingMotifHMM.java


注:本文中的cern.jet.math.Functions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。