本文整理汇总了Java中cc.mallet.util.ArrayUtils类的典型用法代码示例。如果您正苦于以下问题:Java ArrayUtils类的具体用法?Java ArrayUtils怎么用?Java ArrayUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayUtils类属于cc.mallet.util包,在下文中一共展示了ArrayUtils类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testSample
import cc.mallet.util.ArrayUtils; //导入依赖的package包/类
public void testSample ()
{
Variable v = new Variable (3);
double[] vals = new double[] { 1, 3, 2 };
TableFactor ptl = new TableFactor (v, vals);
int[] sampled = new int [100];
Randoms r = new Randoms (32423);
for (int i = 0; i < sampled.length; i++) {
sampled[i] = ptl.sampleLocation (r);
}
double sum = MatrixOps.sum (vals);
double[] counts = new double [vals.length];
for (int i = 0; i < vals.length; i++) {
counts[i] = ArrayUtils.count (sampled, i);
}
MatrixOps.print (counts);
for (int i = 0; i < vals.length; i++) {
double prp = counts[i] / ((double) sampled.length);
assertEquals (vals[i] / sum, prp, 0.1);
}
}
开发者ID:mimno,项目名称:GRMM,代码行数:25,代码来源:TestTableFactor.java
示例2: testMultipleNodePotentials
import cc.mallet.util.ArrayUtils; //导入依赖的package包/类
/**
* Tests that models can be created that have multiple factors over the same variable, and that
* potentialOfVertex returns the product in that case.
*/
public void testMultipleNodePotentials ()
{
Variable var = new Variable (2);
FactorGraph mdl = new FactorGraph (new Variable[]{var});
Factor ptl1 = new TableFactor (var, new double[]{0.5, 0.5});
mdl.addFactor (ptl1);
Factor ptl2 = new TableFactor (var, new double[]{0.25, 0.25});
mdl.addFactor (ptl2);
// verify that factorOf(var) doesn't work
try {
mdl.factorOf (var);
fail ();
} catch (RuntimeException e) {} // expected
List factors = mdl.allFactorsOf (var);
Factor total = TableFactor.multiplyAll (factors);
double[] expected = {0.125, 0.125};
assertTrue ("Arrays not equal\n Expected " + ArrayUtils.toString (expected)
+ "\n Actual " + ArrayUtils.toString (((TableFactor) total).toValueArray ()),
Arrays.equals (expected, ((TableFactor) total).toValueArray ()));
}
开发者ID:mimno,项目名称:GRMM,代码行数:29,代码来源:TestUndirectedModel.java
示例3: checkAllSingles
import cc.mallet.util.ArrayUtils; //导入依赖的package包/类
private void checkAllSingles (RegionGraph rg, Region[] nodeRegions)
{
for (Iterator it = rg.iterator (); it.hasNext ();) {
Region region = (Region) it.next ();
if (region.vars.size() == 1) {
if (ArrayUtils.indexOf (nodeRegions, region) < 0) {
throw new IllegalStateException ("huh?");
}
}
}
}
开发者ID:mimno,项目名称:GRMM,代码行数:12,代码来源:Kikuchi4SquareRegionGenerator.java
示例4: testMarginalize
import cc.mallet.util.ArrayUtils; //导入依赖的package包/类
public void testMarginalize ()
{
Variable[] vars = new Variable[] { new Variable (2), new Variable (2) };
TableFactor ptl = new TableFactor (vars, new double[] { 1, 2, 3, 4});
TableFactor ptl2 = (TableFactor) ptl.marginalize (vars[1]);
assertEquals ("FAILURE: Potential has too many vars.\n "+ptl2, 1, ptl2.varSet ().size ());
assertTrue ("FAILURE: Potential does not contain "+vars[1]+":\n "+ptl2, ptl2.varSet ().contains (vars[1]));
double[] expected = new double[] { 4, 6 };
assertTrue ("FAILURE: Potential has incorrect values. Expected "+ArrayUtils.toString (expected)+"was "+ptl2,
Maths.almostEquals (ptl2.toValueArray (), expected, 1e-5));
}
开发者ID:mimno,项目名称:GRMM,代码行数:13,代码来源:TestTableFactor.java
示例5: testMarginalizeOut
import cc.mallet.util.ArrayUtils; //导入依赖的package包/类
public void testMarginalizeOut ()
{
Variable[] vars = new Variable[] { new Variable (2), new Variable (2) };
TableFactor ptl = new TableFactor (vars, new double[] { 1, 2, 3, 4});
TableFactor ptl2 = (TableFactor) ptl.marginalizeOut (vars[0]);
assertEquals ("FAILURE: Potential has too many vars.\n "+ptl2, 1, ptl2.varSet ().size ());
assertTrue ("FAILURE: Potential does not contain "+vars[1]+":\n "+ptl2, ptl2.varSet ().contains (vars[1]));
double[] expected = new double[] { 4, 6 };
assertTrue ("FAILURE: Potential has incorrect values. Expected "+ArrayUtils.toString (expected)+"was "+ptl2,
Maths.almostEquals (ptl2.toValueArray (), expected, 1e-5));
}
开发者ID:mimno,项目名称:GRMM,代码行数:13,代码来源:TestTableFactor.java
示例6: testExtractMaxLogSpace
import cc.mallet.util.ArrayUtils; //导入依赖的package包/类
public void testExtractMaxLogSpace ()
{
Variable[] vars = new Variable[] { new Variable (2), new Variable (2) };
LogTableFactor ptl = LogTableFactor.makeFromValues (vars, new double[]{1, 2, 3, 4});
LogTableFactor ptl2 = (LogTableFactor) ptl.extractMax (vars[1]);
assertEquals ("FAILURE: Potential has too many vars.\n "+ptl2, 1, ptl2.varSet ().size ());
assertTrue ("FAILURE: Potential does not contain "+vars[1]+":\n "+ptl2, ptl2.varSet ().contains (vars[1]));
double[] expected = new double[] { 3, 4 };
assertTrue ("FAILURE: Potential has incorrect values. Expected "+ArrayUtils.toString (expected)+"was "+ptl2,
Maths.almostEquals (ptl2.toValueArray (), expected, 1e-5));
}
开发者ID:mimno,项目名称:GRMM,代码行数:14,代码来源:TestLogTableFactor.java
示例7: testMultipleEdgePotentials
import cc.mallet.util.ArrayUtils; //导入依赖的package包/类
/**
* Tests that models can be created that have multiple factors over the same edge, and that
* potentialOfEdge returns the product in that case.
*/
public void testMultipleEdgePotentials ()
{
Variable v1 = new Variable (2);
Variable v2 = new Variable (2);
Variable[] vars = new Variable[]{v1, v2};
FactorGraph mdl = new FactorGraph (vars);
Factor ptl1 = new TableFactor (vars, new double[]{0.5, 0.5, 0.5, 0.5});
mdl.addFactor (ptl1);
Factor ptl2 = new TableFactor (vars, new double[]{0.25, 0.25, 0.5, 0.5});
mdl.addFactor (ptl2);
try {
mdl.factorOf (v1, v2);
fail ();
} catch (RuntimeException e) {}
Collection factors = mdl.allFactorsContaining (new HashVarSet (vars));
assertEquals (2, factors.size ());
assertTrue (factors.contains (ptl1));
assertTrue (factors.contains (ptl2));
double[] vals = {0.125, 0.125, 0.25, 0.25};
Factor total = TableFactor.multiplyAll (factors);
Factor expected = new TableFactor (vars, vals);
assertTrue ("Arrays not equal\n Expected " + ArrayUtils.toString (vals)
+ "\n Actual " + ArrayUtils.toString (((TableFactor) total).toValueArray ()),
expected.almostEquals (total, 1e-10));
}
开发者ID:mimno,项目名称:GRMM,代码行数:37,代码来源:TestUndirectedModel.java
示例8: getWeightsIndex
import cc.mallet.util.ArrayUtils; //导入依赖的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
示例9: AgglomerativeNeighbor
import cc.mallet.util.ArrayUtils; //导入依赖的package包/类
/**
*
* @param original
* @param modified
* @param cluster1 Instance indices for one cluster that was merged.
* @param cluster2 Instance indices for other cluster that was merged.
* @return
*/
public AgglomerativeNeighbor (Clustering original,
Clustering modified,
int[][] oldClusters) {
super(original, modified);
if (oldClusters.length != 2)
throw new IllegalArgumentException("Agglomerations of more than 2 clusters not yet implemented.");
this.oldClusters = oldClusters;
this.newCluster = ArrayUtils.append(oldClusters[0], oldClusters[1]);
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:18,代码来源:AgglomerativeNeighbor.java
注:本文中的cc.mallet.util.ArrayUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论