本文整理汇总了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 });
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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]);
}
}
示例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]);
}
}
示例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]);
}
}
示例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 ()));
}