本文整理汇总了Java中cern.colt.matrix.impl.SparseDoubleMatrix1D类的典型用法代码示例。如果您正苦于以下问题:Java SparseDoubleMatrix1D类的具体用法?Java SparseDoubleMatrix1D怎么用?Java SparseDoubleMatrix1D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparseDoubleMatrix1D类属于cern.colt.matrix.impl包,在下文中一共展示了SparseDoubleMatrix1D类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: normalise
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
/**
* Normalizes the sum of the vector elements to 1
* @param vector The vector to normalize
*/
public static void normalise(DoubleMatrix1D vector)
{
double sum = vector.zSum();
if( sum == 0 )
return;
// Treat sparse vectors different
if( vector instanceof SparseDoubleMatrix1D ){
IntArrayList indexList = new IntArrayList();
DoubleArrayList valueList = new DoubleArrayList();
vector.getNonZeros(indexList, valueList);
for(int i=0; i<indexList.size(); i++){
int indexpos = indexList.getQuick(i);
double value = valueList.getQuick(i);
vector.set(indexpos, value/sum );
}
return;
}
// Dense vectors come here
SeqBlas.seqBlas.dscal(1/sum, vector);
}
示例2: setLimits
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
/**
* Cut a value at its limits
* @param vector The value to evaluate
* @param min The minimal value
* @param max The maximal value
* @return <pre>min <= x <= max</pre>
*/
public static void setLimits(DoubleMatrix1D vector, double min, double max)
{
// Treat sparse vectors different
if( vector instanceof SparseDoubleMatrix1D ){
IntArrayList indexList = new IntArrayList();
DoubleArrayList valueList = new DoubleArrayList();
vector.getNonZeros(indexList, valueList);
for(int i=0; i<indexList.size(); i++){
int indexpos = indexList.getQuick(i);
vector.set(indexpos, MathUtils.setLimits(vector.get(indexpos), min, max));
}
return;
}
else
{
for(int indexpos=0; indexpos<vector.size(); indexpos++)
vector.set(indexpos, MathUtils.setLimits(vector.get(indexpos), min, max));
}
}
示例3: match
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
@Override
public DoubleMatrix1D match(DoubleMatrix1D matrix1D) throws MatrixSizeException {
SparseDoubleMatrix1D matchedMatrix = new SparseDoubleMatrix1D(matrix1D.size());
int windowSize;
try {
windowSize = getWindowSize(matrix1D);
} catch (MatrixSizeException e) {
logger.error(String.format("Similarity Vector has %d cells. It cannot be generated from NxN matrix",
matrix1D.size()), e);
throw e;
}
for (int startigIndex = 0; startigIndex < matrix1D.size(); startigIndex += windowSize) {
DoubleMatrix1D row = matrix1D.viewPart(startigIndex, windowSize);
Map.Entry<Double, Integer> maxScoreEntry = getMaxEntryInRow(windowSize, startigIndex, row);
matchedMatrix.setQuick(maxScoreEntry.getValue(), maxScoreEntry.getKey());
}
return matchedMatrix;
}
示例4: product
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
static public double product(DoubleMatrix1D v1, DoubleMatrix1D v2) {
if (v1 instanceof SparseDoubleMatrix1D) {
return productQuick(v1, v2);
} else if (v2 instanceof SparseDoubleMatrix1D) {
return productQuick(v2, v1);
} else {
return v1.zDotProduct(v2);
}
}
示例5: MarkovCentrality
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
public MarkovCentrality(DirectedGraph<V,E> graph, Set<V> rootNodes, Map<E,Number> edgeWeightKey) {
super.initialize(graph, true, false);
setPriors(rootNodes);
if (edgeWeightKey == null)
assignDefaultEdgeTransitionWeights();
else
setEdgeWeights(edgeWeightKey);
normalizeEdgeTransitionWeights();
mIndexer = Indexer.<V>create(graph.getVertices());
mRankings = new SparseDoubleMatrix1D(graph.getVertexCount());
}
示例6: forEachNonZero
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
public SparseDoubleMatrix1D forEachNonZero(IntDoubleFunction func) {
for (int y = 0; y < size(); y++) {
if (getQuick(y) != 0)
setQuick(y,func.apply(y,get(y)));
}
return this;
}
示例7: getFeatures
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
public DoubleMatrix1D getFeatures(final DoubleMatrix1D state) {
// check if we already calculated the features
DoubleMatrix1D cached = cache.get(state);
if(cacheEnabled && cached != null && cached.size() == this.size() )
return cached;
// do not apply adaption rule if the cache contains s because the rule
// has been applied already
adaptionRule.changeNet(state);
DoubleMatrix1D feat = new SparseDoubleMatrix1D(net.size());
feat.assign(this.featureGenerator.getFeatureVector(state));
//log4j.debug("Network size: " + net.size());
if(isNormalized) {
double sum = feat.zSum();
if (sum != 0) {
IntArrayList indexList = new IntArrayList();
DoubleArrayList valueList = new DoubleArrayList();
feat.getNonZeros(indexList, valueList);
// log4j.debug(indexList.size()+ " nonzeros" );
for(int i=0; i<indexList.size(); i++) {
int indexpos = indexList.getQuick(i);
double value = valueList.getQuick(i);
feat.set(indexpos, value/sum );
}
}
}
if (this.cacheEnabled)
cache.put(state, feat);
return feat;
}
示例8: testNormalizeSparse
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
public static void testNormalizeSparse()
{
final double DELTA = 0.000001;
DoubleMatrix1D v = new SparseDoubleMatrix1D(5000000);
for(int i=0; i<50; i++){
v.set(Uniform.staticNextIntFromTo(0, v.size()-1), Uniform.staticNextDouble());
}
VectorUtils.normalise(v);
assertEquals(1.0, v.zSum(),DELTA);
}
示例9: MarkovCentrality
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
public MarkovCentrality(DirectedGraph graph, Set rootNodes, String edgeWeightKey) {
super.initialize(graph, true, false);
setPriors(rootNodes);
if (edgeWeightKey == null)
assignDefaultEdgeTransitionWeights();
else
setUserDefinedEdgeWeightKey(edgeWeightKey);
normalizeEdgeTransitionWeights();
mIndexer = Indexer.getIndexer(graph);
mRankings = new SparseDoubleMatrix1D(graph.numVertices());
}
示例10: make
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
/**
* Constructs a matrix with the given shape, each cell initialized with zero.
*/
public DoubleMatrix1D make(int size) {
if (this==sparse) return new SparseDoubleMatrix1D(size);
return new DenseDoubleMatrix1D(size);
}
示例11: getFeatures
import cern.colt.matrix.impl.SparseDoubleMatrix1D; //导入依赖的package包/类
public DoubleMatrix1D getFeatures(DoubleMatrix1D feat)
{
DoubleMatrix1D featureVector = new SparseDoubleMatrix1D(getFeatureVectorSize());
featureVector.set(sSet.indexOf(feat), 1);
return featureVector;
}