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


Java DoubleMatrix1D.zSum方法代码示例

本文整理汇总了Java中cern.colt.matrix.DoubleMatrix1D.zSum方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix1D.zSum方法的具体用法?Java DoubleMatrix1D.zSum怎么用?Java DoubleMatrix1D.zSum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cern.colt.matrix.DoubleMatrix1D的用法示例。


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

示例1: CalculatePortfolioStandardDeviation

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的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

示例2: calculate

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
@Override
public double calculate(final double[] parameters) {
    // 20 fitness values
    DoubleMatrix1D f = DoubleFactory1D.dense.make(20);

    // 19 parameters are estimated, passed in parameters[]
    for (int i = 0; i < parameters.length; i++) f.setQuick(i, parameters[i]);

    // One is fixed
    f.setQuick(19, Constants.FITNESS_FIXED_FOR_RELATIVE);

    double mean = f.zSum() / 20.0;
    f.assign(Functions.minus(mean));
    return -coefficient * f.aggregate(Functions.plus, Functions.pow(2.0));
}
 
开发者ID:tamuri,项目名称:swmutsel,代码行数:16,代码来源:MVNPenalty.java

示例3: zdemo1

import cern.colt.matrix.DoubleMatrix1D; //导入方法依赖的package包/类
/**
 * Demonstrates advanced sorting.
 * Sorts by sum of row.
 */
public static void zdemo1() {
	Sorting sort = quickSort;
	DoubleMatrix2D matrix = DoubleFactory2D.dense.descending(4,3);
	DoubleMatrix1DComparator comp = new DoubleMatrix1DComparator() {
		public int compare(DoubleMatrix1D a, DoubleMatrix1D b) {
			double as = a.zSum(); double bs = b.zSum();
			return as < bs ? -1 : as == bs ? 0 : 1;
		}
	};
	System.out.println("unsorted:"+matrix);
	System.out.println("sorted  :"+sort.sort(matrix,comp));
}
 
开发者ID:dmcennis,项目名称:jAudioGIT,代码行数:17,代码来源:Sorting.java


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