• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java IndexedSparseVector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testBinaryVector

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public void testBinaryVector ()
{
  IndexedSparseVector binary1 = new IndexedSparseVector (idxs, null, idxs.length, idxs.length,
                                           false, false, false);
  IndexedSparseVector binary2 = new IndexedSparseVector (idx2, null, idx2.length, idx2.length,
                                          false, false, false);

  assertEquals (3, binary1.dotProduct (binary2), 0.0001);
  assertEquals (3, binary2.dotProduct (binary1), 0.0001);

  assertEquals (15.0, binary1.dotProduct (s1), 0.0001);
  assertEquals (15.0, s1.dotProduct (binary1), 0.0001);

  assertEquals (9.0, binary2.dotProduct (s1), 0.0001);
  assertEquals (9.0, s1.dotProduct (binary2), 0.0001);

  IndexedSparseVector dblVec = (IndexedSparseVector) s1.cloneMatrix ();
  dblVec.plusEqualsSparse (binary1);
  checkAnswer (dblVec, new double[] { 2, 3, 4, 5, 6 });

  IndexedSparseVector dblVec2 = (IndexedSparseVector) s1.cloneMatrix ();
  dblVec2.plusEqualsSparse (binary2);
  checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 });
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:25,代码来源:TestIndexedSparseVector.java


示例2: readSparse

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public List<SparseVector> readSparse(File mat) throws IOException {
	Scanner sc = new Scanner(mat);
	List<SparseVector> ret = new ArrayList<SparseVector>();
	int nrows = sc.nextInt();
	int ncols = sc.nextInt();
	int nz = sc.nextInt();
	for (int j = 0; j < ncols; j++) {
		int cnz = sc.nextInt();
		int[] indices = new int[cnz];
		double[] values = new double[cnz];
		for (int i = 0; i < cnz; i++) {
			indices[i] = sc.nextInt();
			values[i] = sc.nextDouble();
		}
		ret.add(new IndexedSparseVector(indices, values));
	}
	sc.close();
	return ret;
}
 
开发者ID:siqil,项目名称:udaner,代码行数:20,代码来源:SVDLIBC.java


示例3: setWeightsDimensionDensely

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public void setWeightsDimensionDensely ()
{
	weightsStructureChanged();
	SparseVector[] newWeights = new SparseVector [parameters.weights.length];
	int max = inputAlphabet.size();
	int numWeights = 0;
	logger.info ("CRF using dense weights, num input features = "+max);
	for (int i = 0; i < parameters.weights.length; i++) {
		int nfeatures;
		if (featureSelections[i] == null) {
			nfeatures = max;
			newWeights [i] = new SparseVector (null, new double [max],
					max, max, false, false, false);
		} else {
			// Respect the featureSelection
			FeatureSelection fs = featureSelections[i];
			nfeatures = fs.getBitSet ().cardinality ();
			int[] idxs = new int [nfeatures];
			int j = 0, thisIdx = -1;
			while ((thisIdx = fs.nextSelectedIndex (thisIdx + 1)) >= 0) {
				idxs[j++] = thisIdx;
			}
			newWeights[i] = new IndexedSparseVector (idxs, new double [nfeatures], nfeatures, nfeatures, false, false, false);
		}
		newWeights [i].plusEqualsSparse (parameters.weights [i]);
		numWeights += (nfeatures + 1);
	}
	logger.info("Number of weights = "+numWeights);
	parameters.weights = newWeights;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:31,代码来源:CRF.java


示例4: getWeightsIndex

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public int getWeightsIndex (String weightName)
{
	int wi = parameters.weightAlphabet.lookupIndex (weightName);
	if (wi == -1)
		throw new IllegalArgumentException ("Alphabet frozen, and no weight with name "+ weightName);
	if (parameters.weights == null) {
		assert (wi == 0);
		parameters.weights = new SparseVector[1];
		parameters.defaultWeights = new double[1];
		featureSelections = new FeatureSelection[1];
		parameters.weightsFrozen = new boolean [1];
		// Use initial capacity of 8
		parameters.weights[0] = new IndexedSparseVector ();
		parameters.defaultWeights[0] = 0;
		featureSelections[0] = null;
		weightsStructureChanged();
	} else if (wi == parameters.weights.length) {
		SparseVector[] newWeights = new SparseVector[parameters.weights.length+1];
		double[] newDefaultWeights = new double[parameters.weights.length+1];
		FeatureSelection[] newFeatureSelections = new FeatureSelection[parameters.weights.length+1];
		for (int i = 0; i < parameters.weights.length; i++) {
			newWeights[i] = parameters.weights[i];
			newDefaultWeights[i] = parameters.defaultWeights[i];
			newFeatureSelections[i] = featureSelections[i];
		}
		newWeights[wi] = new IndexedSparseVector ();
		newDefaultWeights[wi] = 0;
		newFeatureSelections[wi] = null;
		parameters.weights = newWeights;
		parameters.defaultWeights = newDefaultWeights;
		featureSelections = newFeatureSelections;
		parameters.weightsFrozen = ArrayUtils.append (parameters.weightsFrozen, false);
		weightsStructureChanged();
	}
	//setTrainable (false);
	return wi;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:38,代码来源:CRF.java


示例5: checkAnswer

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
private void checkAnswer (IndexedSparseVector actual, double[] ans)
{
  assertEquals ("Wrong number of locations:",
                ans.length, actual.numLocations());
  for (int i = 0; i < actual.numLocations(); i++) {
    assertEquals ("Value incorrect at location "+i+": ",
                  ans[i], actual.valueAtLocation (i) , 0.0);
  }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:10,代码来源:TestIndexedSparseVector.java


示例6: testPlusEquals

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public void testPlusEquals ()
{
  IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix ();
  s.plusEqualsSparse (s2, 2.0);
  checkAnswer (s, new double[] { 3, 5, 7, 6, 7 });

  IndexedSparseVector s2p = new IndexedSparseVector
                     (new int[] { 13 },
                      new double[] { 0.8 });
  s.plusEqualsSparse (s2p, 1.0);
  checkAnswer (s, new double[] { 3, 5, 7, 6.8, 7 });

  IndexedSparseVector s3p = new IndexedSparseVector
                     (new int[] { 14 },
                      new double[] { 0.8 });
  s.plusEqualsSparse (s3p, 1.0);
  checkAnswer (s, new double[] { 3, 5, 7, 6.8, 7 }); 		// verify s unchanged

  IndexedSparseVector s4 = new IndexedSparseVector
                    (new int[] { 7, 14, 15 },
                     new double[] { 0.2, 0.8, 1.2 });
  s.plusEqualsSparse (s4, 1.0);
  checkAnswer (s, new double[] { 3, 5, 7.2, 6.8, 8.2 });

  IndexedSparseVector s5 = new IndexedSparseVector (new int[] { 7 }, new double[] { 0.2 });
  s5.plusEqualsSparse (s1);
  for (int i = 0; i < s5.numLocations(); i++) {
    assertEquals (7, s5.indexAtLocation (i));
    assertEquals (3.2, s5.valueAtLocation (i), 0.0);
  }

  IndexedSparseVector s6 = new IndexedSparseVector (new int[] { 7 }, new double[] { 0.2 });
  s6.plusEqualsSparse (s1, 3.5);
  for (int i = 0; i < s6.numLocations(); i++) {
    assertEquals (7, s6.indexAtLocation (i));
    assertEquals (10.7, s6.valueAtLocation (i), 0.0);
  }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:39,代码来源:TestIndexedSparseVector.java


示例7: testDotProduct

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public void testDotProduct () {
  IndexedSparseVector t1 = new IndexedSparseVector (new int[] { 7 }, new double[] { 0.2 });
  assertEquals (0.6, t1.dotProduct (s1), 0.00001);
  assertEquals (0.6, s1.dotProduct (t1), 0.00001);

  assertEquals (19.0, s1.dotProduct (s2), 0.00001);
  assertEquals (19.0, s2.dotProduct (s1), 0.00001);

  assertEquals (11.9, s1.dotProduct (d1), 0.00001);
  assertEquals (10.1, s2.dotProduct (d1), 0.00001);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:TestIndexedSparseVector.java


示例8: testIncrementValue

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public void testIncrementValue ()
{
  IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix ();
  s.incrementValue (5, 0.75);

  double[] ans = new double[] {1, 2.75, 3, 4, 5};
  for (int i = 0; i < s.numLocations(); i++) {
    assertTrue (s.valueAtLocation (i) == ans[i]);
  }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:11,代码来源:TestIndexedSparseVector.java


示例9: testSetValue

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public void testSetValue ()
{
  IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix ();
  s.setValue (5, 0.3);

  double[] ans = new double[] {1, 0.3, 3, 4, 5};
  for (int i = 0; i < s.numLocations(); i++) {
    assertTrue (s.valueAtLocation (i) == ans[i]);
  }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:11,代码来源:TestIndexedSparseVector.java


示例10: testCloneMatrixZeroed

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public void testCloneMatrixZeroed ()
{
  IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrixZeroed ();
  for (int i = 0; i < s.numLocations(); i++) {
    assertTrue (s.valueAtLocation (i) == 0.0);
    assertTrue (s.indexAtLocation (i) == idxs [i]);
  }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:9,代码来源:TestIndexedSparseVector.java


示例11: testSerializable

import cc.mallet.types.IndexedSparseVector; //导入依赖的package包/类
public void testSerializable () throws IOException, ClassNotFoundException
{
  IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix ();
  IndexedSparseVector sPrime = (IndexedSparseVector) TestSerializable.cloneViaSerialization (s);
  assertEquals (s.numLocations (), sPrime.numLocations ());
  assertTrue (Arrays.equals (s.getIndices (), sPrime.getIndices ()));
  assertTrue (Arrays.equals (s.getValues (), sPrime.getValues ()));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:9,代码来源:TestIndexedSparseVector.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NiftyEventSubscriber类代码示例发布时间:2022-05-22
下一篇:
Java PubSubManager类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap