本文整理汇总了Java中cern.colt.matrix.DoubleMatrix2D.set方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMatrix2D.set方法的具体用法?Java DoubleMatrix2D.set怎么用?Java DoubleMatrix2D.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cern.colt.matrix.DoubleMatrix2D
的用法示例。
在下文中一共展示了DoubleMatrix2D.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSparseMatrix
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
private DoubleMatrix2D createSparseMatrix(int M, int R, double sparcityPercentage) {
// TODO: add varying scale factor.
// Create sparse matrix.
DoubleMatrix2D D = DoubleFactory2D.sparse.random(M, R);
double[] rowSums = new double[M];
for (int m = 0; m < M; m++) {
for (int r = 0; r < R; r++) {
if (rand.nextDouble() < sparcityPercentage) {
D.set(m, r, 0);
}
rowSums[m] += D.get(m, r);
}
}
// Normalise rows.
for (int m = 0; m < M; m++) {
for (int r = 0; r < R; r++) {
double val = D.get(m, r);
D.set(m, r, val/rowSums[m]);
}
}
return D;
}
示例2: logMatrixMult
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static void logMatrixMult(DoubleMatrix2D result, DoubleMatrix2D A, DoubleMatrix2D B, DoubleMatrix1D ri, boolean noMatrixMult) {
DoubleDoubleFunction sumFunc = new SumFunc();
if (noMatrixMult)
result.assign(B);
else {
for (int i = 0; i < A.rows(); i++) {
for (int j = 0; j < B.columns(); j++) {
double value = LOG0;
for (int k = 0; k < B.rows(); k++) {
value = logSumExp(value, A.get(i,k)+B.get(k, j));
}
result.set(i, j, value);
}
}
}
for (int i = 0; i < A.rows(); i++) {
result.viewRow(i).assign(ri, sumFunc);
}
}
示例3: computeLogMiTrainMode
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
protected boolean computeLogMiTrainMode(FeatureGenerator featureGen, double lambda[],
DataSequence dataSeq, int i,
DoubleMatrix2D Mi_YY,
DoubleMatrix1D Ri_Y, boolean takeExp, boolean reuseM, boolean initMDone) {
boolean retVal = Trainer.computeLogMi(featureGen,lambda,dataSeq,i,fMi_YY,Ri_Y,false,reuseM,initMDone);
int iterNum = icall;
for (int c = 0; c < Ri_Y.size();c++) {
int loss = (dataSeq.y(i)!=c)?1:0;
Ri_Y.set(c,eta*C*(Ri_Y.get(c)+iterNum*loss));
/*
* don't need loss for this since it is already accounted for in Ri_Y
*/
if (i > 0) {
for (int r = 0; r < Mi_YY.rows(); r++) {
Mi_YY.set(r,c,eta*C*(fMi_YY.get(r,c)));
}
}
}
return retVal;
}
示例4: computeLogMi
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
protected void computeLogMi(DataSequence dataSeq, int i, DoubleMatrix2D kMi, DoubleMatrix1D kRi, DataSequence consData, YSequence yseq, double alpha) {
if (consData==null) return;
for (int j = 0; j < consData.length(); j++) {
int consY = yseq.getY(j);
int ypp = consData.y(j);
if (consY != ypp) {
double kval = kernelValue(dataSeq, i, consData, j);
kRi.set(consY, kRi.get(consY)-alpha*kval);
kRi.set(ypp, kRi.get(ypp)+alpha*kval);
}
if ((i > 0) && (j > 0)) {
int consPrevY = yseq.getY(j-1);
int yprev = consData.y(j-1);
if ((consY != consData.y(j)) || (consPrevY != consData.y(j-1))) {
kMi.set(consPrevY, consY, kMi.get(consPrevY, consY)-alpha);
kMi.set(yprev, ypp, kMi.get(yprev, ypp)+alpha);
}
}
}
}
示例5: doubleTest
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
*/
public static void doubleTest() {
int rows = 4;
int columns = 5; // make a 4*5 matrix
DoubleMatrix2D master = new DenseDoubleMatrix2D(rows,columns);
System.out.println(master);
master.assign(1); // set all cells to 1
System.out.println("\n"+master);
master.viewPart(2,1,2,3).assign(2); // set [2,1] .. [3,3] to 2
System.out.println("\n"+master);
DoubleMatrix2D copyPart = master.viewPart(2,1,2,3).copy();
copyPart.assign(3); // modify an independent copy
copyPart.set(0,0,4);
System.out.println("\n"+copyPart); // has changed
System.out.println("\n"+master); // master has not changed
DoubleMatrix2D view1 = master.viewPart(0,3,4,2); // [0,3] .. [3,4]
DoubleMatrix2D view2 = view1.viewPart(0,0,4,1); // a view from a view
System.out.println("\n"+view1);
System.out.println("\n"+view2);
}
示例6: simplifyRelations
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static LogRelations simplifyRelations(LogReader logReader, LogRelations logRelations) {
LogAbstraction logAbstraction = new LogAbstractionImpl(logReader, true);
try {
DoubleMatrix2D parallel = logRelations.getParallelMatrix();
DoubleMatrix2D causalFollower = logRelations.getCausalFollowerMatrix();
DoubleMatrix2D directFollow = logAbstraction.getFollowerInfo(1);
makeBasicRelations(logReader, directFollow, 0.8);
for(int i = 0; i < logRelations.getNumberElements(); i++) {
for(int j = i + 1; j < logRelations.getNumberElements(); j++) {
if(parallel.get(i, j) > 0) {
double ij = directFollow.get(i, j);
double ji = directFollow.get(j, i);
double num = ij - ji;
double den = ij + ji + 1;
double val = Math.abs(num) / den;
if(val > 0.7) {
System.out.println("Changing");
parallel.set(i, j, 0);
parallel.set(j, i, 0);
if(num > 0) {
causalFollower.set(i, j, 1);
}else {
causalFollower.set(j, i, 1);
}
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return logRelations;
}
示例7: computeVoltagePotentialMatrix
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* The idea here is based on the metaphor of an electric circuit. We assume
* that an undirected graph represents the structure of an electrical
* circuit where each edge has unit resistance. One unit of current is
* injected into any arbitrary vertex s and one unit of current is extracted
* from any arbitrary vertex t. The voltage at some vertex i for source
* vertex s and target vertex t can then be measured according to the
* equation: V_i^(s,t) = T_is - T-it where T is the voltage potential matrix
* returned by this method. *
*
* @param graph
* an undirected graph representing an electrical circuit
* @return the voltage potential matrix
* @see "P. Doyle and J. Snell, 'Random walks and electric networks,', 1989"
* @see "M. Newman, 'A measure of betweenness centrality based on random walks', pp. 5-7, 2003"
*/
public static <V,E> DoubleMatrix2D computeVoltagePotentialMatrix(
UndirectedGraph<V,E> graph)
{
int numVertices = graph.getVertexCount();
//create adjacency matrix from graph
DoubleMatrix2D A = GraphMatrixOperations.graphToSparseMatrix(graph,
null);
//create diagonal matrix of vertex degrees
DoubleMatrix2D D = GraphMatrixOperations
.createVertexDegreeDiagonalMatrix(graph);
DoubleMatrix2D temp = new SparseDoubleMatrix2D(numVertices - 1,
numVertices - 1);
//compute D - A except for last row and column
for (int i = 0; i < numVertices - 1; i++)
{
for (int j = 0; j < numVertices - 1; j++)
{
temp.set(i, j, D.get(i, j) - A.get(i, j));
}
}
Algebra algebra = new Algebra();
DoubleMatrix2D tempInverse = algebra.inverse(temp);
DoubleMatrix2D T = new SparseDoubleMatrix2D(numVertices, numVertices);
//compute "voltage" matrix
for (int i = 0; i < numVertices - 1; i++)
{
for (int j = 0; j < numVertices - 1; j++)
{
T.set(i, j, tempInverse.get(i, j));
}
}
return T;
}
示例8: initLogMi
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
public static double initLogMi(double defaultValue, Iterator constraints,
DoubleMatrix2D Mi, DoubleMatrix1D Ri) {
if (constraints != null) {
defaultValue = RobustMath.LOG0;
if (Mi != null) Mi.assign(defaultValue);
Ri.assign(defaultValue);
for (; constraints.hasNext();) {
Constraint constraint = (Constraint)constraints.next();
if (constraint.type() == Constraint.ALLOW_ONLY) {
RestrictConstraint cons = (RestrictConstraint)constraint;
/*
for (int c = cons.numAllowed()-1; c >= 0; c--) {
Ri.set(cons.allowed(c),0);
}
*/
for (cons.startScan(); cons.hasNext();) {
cons.advance();
int y = cons.y();
int yprev = cons.yprev();
if (yprev < 0) {
Ri.set(y,0);
} else {
if (Mi != null) Mi.set(yprev,y,0);
}
}
}
}
} else {
if (Mi != null) Mi.assign(defaultValue);
Ri.assign(defaultValue);
}
return defaultValue;
}
示例9: getLogMi
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
/**
* @param i
* @param mi_YY
* edge features are constrainted to have "=s" and >=s" as the start and end boundaries
*/
public void getLogMi(int i, DoubleMatrix2D mi_YY) {
double DEFAULT_VALUE = RobustMath.LOG0;
mi_YY.assign(DEFAULT_VALUE);
for (Iterator<Feature> iter = edgeFeatures.get(i).iterator(); iter.hasNext(); ) {
Feature f = iter.next();
double oldVal = mi_YY.get(f.yprev(), f.y());
if (oldVal == DEFAULT_VALUE)
oldVal = 0;
mi_YY.set(f.yprev(),f.y(),oldVal+lambda[f.index()]*f.value());
}
}
示例10: calcTerms
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
private void calcTerms(DoubleMatrix2D terms){
terms.assign(0.0);
for(int x=0;x<windowLength;++x){
for(int y=0;y<featureLength;++y){
for(int i=0;i<k;++i){
for(int j=0;j<l;++j){
terms.set(featureLength*x+y,l*i+j,Math.pow(x,i)*Math.pow(y,j));
}
}
}
}
}
示例11: calcTerms
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
private void calcTerms(DoubleMatrix2D terms){
terms.assign(0.0);
for(int x=0;x<windowLength;++x){
for(int y=0;y<featureLength;++y){
for(int i=0;i<k;++i){
for(int j=0;j<l;++j){
terms.set(l*i+j,featureLength*x+y,Math.pow(x,i)*Math.pow(y,j));
}
}
}
}
}
示例12: calcTerms
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
private void calcTerms(DoubleMatrix2D terms){
terms.assign(0.0);
for(int x=0;x<windowLength;++x){
for(int y=0;y<featureLength;++y){
for(int i=0;i<xDim;++i){
for(int j=0;j<yDim;++j){
terms.set(yDim*i+j,featureLength*x+y,Math.pow(x,i)*Math.pow(y,j));
}
}
}
}
}
示例13: inverseDense
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
static public List<DoubleMatrix1D> inverseDense(List<DoubleMatrix1D> A) {
List<DoubleMatrix1D> C = null;
DoubleMatrix2D A1 = new DenseDoubleMatrix2D(A.size(), A.get(0).size());
for (int i = 0; i < A.size(); ++i) {
DoubleMatrix1D vector = A.get(0);
for (int j = 0; j < vector.size(); ++j ) {
A1.set(i, j, vector.get(j));
}
}
double tol = 0.001;
for (int i = 0; i < A.size(); ++i) {
A1.set(i, i, A1.get(i, i) + tol);
}
Algebra algebra = new Algebra();
DoubleMatrix2D C1 = algebra.inverse(A1);
C = new ArrayList<DoubleMatrix1D>();
for (int i = 0; i < A.size(); ++i) {
C.add(new ColtDenseVector(A.get(0).size()));
}
for (int i = 0; i < C1.rows(); ++i) {
for (int j = 0; j < C1.columns(); ++j ) {
C.get(i).set(j, C1.get(i, j));
}
}
return C;
}
示例14: inverseSparse
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
static public List<DoubleMatrix1D> inverseSparse(List<DoubleMatrix1D> A) {
// TODO: optimize this code
List<DoubleMatrix1D> C = null;
DoubleMatrix2D A1 = new SparseDoubleMatrix2D(A.size(), A.get(0).size());
for (int i = 0; i < A.size(); ++i) {
DoubleMatrix1D vector = A.get(i);
for (int j = 0; j < vector.size(); ++j ) {
A1.set(i, j, vector.get(j));
}
}
double tol = 0.001;
for (int i = 0; i < A.size(); ++i) {
A1.set(i, i, A1.get(i, i) + tol);
}
Algebra algebra = new Algebra();
DoubleMatrix2D C1 = algebra.inverse(A1);
C = new ArrayList<DoubleMatrix1D>();
for (int i = 0; i < A.size(); ++i) {
C.add(new ColtSparseVector(A.get(0).size()));
}
for (int i = 0; i < C1.rows(); ++i) {
for (int j = 0; j < C1.columns(); ++j ) {
C.get(i).set(j, C1.get(i, j));
}
}
return C;
}
示例15: makeBasicRelations
import cern.colt.matrix.DoubleMatrix2D; //导入方法依赖的package包/类
private static void makeBasicRelations(LogReader log, DoubleMatrix2D causalSuccession, double causalityFall) {
events = log.getLogSummary().getLogEvents();
longRangeSuccessionCount = DoubleFactory2D.dense.make(events.size(), events.size(), 0);
log.reset();
while (log.hasNext()) {
ProcessInstance pi = log.next();
AuditTrailEntries ate = pi.getAuditTrailEntries();
int i = 0;
boolean terminate = false;
while (!terminate) {
ate.reset();
// Skip the first i entries of the trace
for (int j = 0; j < i; j++) {
ate.next();
}
// Work with the other entries.
AuditTrailEntry begin = ate.next();
// Find the correct row of the matices
int row = events.findLogEventNumber(begin.getElement(),
begin.getType());
int distance = 0;
boolean foundSelf = false;
HNSubSet done = new HNSubSet();
terminate = (!ate.hasNext());
while (ate.hasNext() && (!foundSelf)) {
AuditTrailEntry end = ate.next();
int column = events.findLogEventNumber(end.
getElement(),
end.getType()
);
foundSelf = (row == column);
distance++;
if (done.contains(column)) {
continue;
}
done.add(column);
// update long range matrix
longRangeSuccessionCount.set(row, column, longRangeSuccessionCount.get(row,
column) + 1);
// update causal matrix
// System.out.println("Change from " + causalSuccession.get(row,
// column) + " to " + causalSuccession.get(row,
// column) + Math.pow(causalityFall, distance - 1));
causalSuccession.set(row, column, causalSuccession.get(row,
column) + Math.pow(causalityFall, distance - 1));
}
i++;
}
}
// calculate causalSuccesion (==> not yet used during heuristics process mining!!!
for (int i = 0; i < causalSuccession.rows(); i++) {
for (int j = 0; j < causalSuccession.columns(); j++) {
if (causalSuccession.get(i, j) == 0) {
continue;
}
causalSuccession.set(i, j, causalSuccession.get(i, j) /
longRangeSuccessionCount.get(i, j));
}
}
}