本文整理汇总了Java中cern.colt.matrix.impl.DenseDoubleMatrix2D类的典型用法代码示例。如果您正苦于以下问题:Java DenseDoubleMatrix2D类的具体用法?Java DenseDoubleMatrix2D怎么用?Java DenseDoubleMatrix2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DenseDoubleMatrix2D类属于cern.colt.matrix.impl包,在下文中一共展示了DenseDoubleMatrix2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
public static void main(String[] args) {
System.out.println("Hello World!");
double[][] vals = { { 0, 4, 10 }, { 3, 0, 3 }, { 8, 15, 0 } };
DenseDoubleMatrix2D mat = new DenseDoubleMatrix2D(vals);
SpectralClusteringSolver.SolveSpectralClustering(mat, 3);
}
示例2: clone
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
@Override
public GaussianKernel clone() {
if (!ready) {
throw new IllegalStateException("This kernel has to be init() first");
}
GaussianKernel newKernel = new GaussianKernel(dm.clone());
newKernel.bandwidth = bandwidth;
if (this.sigma != null) {
newKernel.sigma = new double[sigma.length][];
for (int i = 0; i < sigma.length; i++) {
newKernel.sigma[i] = MatrixOp.copy(sigma[i]);
}
}
if (this.invSigma != null) {
newKernel.invSigma = Algebra.DEFAULT.inverse(new DenseDoubleMatrix2D(sigma)).toArray();
}
newKernel.normConst = normConst;
newKernel.ready = true;
return newKernel;
}
示例3: getNonNormalizedValueCov
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
protected double getNonNormalizedValueCov(double[] center, double[] vector) {
//if(true)return MultiNormalDist.density(center, sigma, vector);
if (!ready) {
throw new IllegalStateException("kernel not initialized!");
}
if (invSigma == null) {
invSigma = Algebra.DEFAULT.inverse(new DenseDoubleMatrix2D(sigma)).toArray();
}
double[] vec = MatrixOp.copy(vector);
MatrixOp.mult(vec, -1);
double[] diff = MatrixOp.sum(center, vec);
double exp = Math.exp(-0.5 * MatrixOp.mult(MatrixOp.mult(invSigma, diff), diff));
exp *= normConst;
if (Double.isNaN(exp)) {
logger.print("NaN exp", MatrixOp.mult(MatrixOp.mult(invSigma, diff), diff), MultiNormalDist.density(center, sigma, vector));
}
if (Double.isInfinite(exp)) {
logger.print("Inf exp", MatrixOp.mult(MatrixOp.mult(invSigma, diff), diff), MultiNormalDist.density(center, sigma, vector));
}
//logger.print((exp*normConst) / MultiNormalDist.density(center, sigma, vec));
return exp;
}
示例4: printContigencyTable
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
private static void printContigencyTable(ClusterSet cs, int numClasses) {
try {
double[][] contigTable = new double[cs.getClusters().length][numClasses];
Cluster[] cl = cs.getClusters();
for (int i = 0; i < cl.length; i++) {
for (ClusterMember cm : cl[i].getClusterMembers()) {
int cid = Integer.parseInt(cm.getDatapoint().getFullName().substring(2, cm.getDatapoint().getFullName().indexOf("_", 2)));
contigTable[i][cid] += 1.0 / SIZES[cid];
}
}
logger.print(new DenseDoubleMatrix2D(contigTable));
} catch (Exception e) {
logger.print(e);
}
}
示例5: printContigencyTable
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
private static void printContigencyTable(ClusterSet cs, int numClasses) {
try {
double[][] contigTable = new double[cs.getClusters().length][numClasses];
Cluster[] cl = cs.getClusters();
for (int i = 0; i < cl.length; i++) {
for (ClusterMember cm : cl[i].getClusterMembers()) {
int cid = Integer.parseInt(cm.getDatapoint().getName().substring(2, cm.getDatapoint().getName().indexOf("_", 2)));
contigTable[i][cid] += 1.0 / SIZES[cid];
}
}
logger.print(new DenseDoubleMatrix2D(contigTable));
} catch (Exception e) {
logger.print(e);
}
}
示例6: error
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
@Override
public double error(DenseDoubleMatrix2D p, DenseDoubleMatrix2D q, FastPreferenceData<U, I> data) {
// TODO: add regularization
return data.getUidxWithPreferences().parallel().mapToDouble(uidx -> {
DoubleMatrix1D pu = p.viewRow(uidx);
DoubleMatrix1D su = q.zMult(pu, null);
double err1 = data.getUidxPreferences(uidx).mapToDouble(iv -> {
double rui = iv.v2;
double sui = su.getQuick(iv.v1);
double cui = confidence.applyAsDouble(rui);
return cui * (rui - sui) * (rui - sui) - confidence.applyAsDouble(0) * sui * sui;
}).sum();
double err2 = confidence.applyAsDouble(0) * su.assign(x -> x * x).zSum();
return (err1 + err2) / data.numItems();
}).sum() / data.numUsers();
}
示例7: error
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
@Override
public double error(DenseDoubleMatrix2D p, DenseDoubleMatrix2D q, FastPreferenceData<U, I> data) {
// TODO: add regularization, unify with HKVFactorizer's error
return data.getUidxWithPreferences().parallel().mapToDouble(uidx -> {
DoubleMatrix1D pu = p.viewRow(uidx);
DoubleMatrix1D su = q.zMult(pu, null);
double err1 = data.getUidxPreferences(uidx).mapToDouble(iv -> {
double rui = iv.v2;
double sui = su.getQuick(iv.v1);
double cui = confidence.applyAsDouble(rui);
return cui * (rui - sui) * (rui - sui) - confidence.applyAsDouble(0) * sui * sui;
}).sum();
double err2 = confidence.applyAsDouble(0) * su.assign(x -> x * x).zSum();
return (err1 + err2) / data.numItems();
}).sum() / data.numUsers();
}
示例8: getGt
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
private static DoubleMatrix2D getGt(final DenseDoubleMatrix2D p, final DenseDoubleMatrix2D q, double lambda) {
final int K = p.columns();
DenseDoubleMatrix2D A1 = new DenseDoubleMatrix2D(K, K);
q.zMult(q, A1, 1.0, 0.0, true, false);
for (int k = 0; k < K; k++) {
A1.setQuick(k, k, lambda + A1.getQuick(k, k));
}
EigenvalueDecomposition eig = new EigenvalueDecomposition(A1);
DoubleMatrix1D d = eig.getRealEigenvalues();
DoubleMatrix2D gt = eig.getV();
for (int k = 0; k < K; k++) {
double a = sqrt(d.get(k));
gt.viewColumn(k).assign(x -> a * x);
}
return gt;
}
示例9: getRecommendation
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
@Override
public FastRecommendation getRecommendation(int uidx, IntStream candidates) {
DoubleMatrix1D pu;
pu = factorization.getUserVector(uidx2user(uidx));
if (pu == null) {
return new FastRecommendation(uidx, new ArrayList<>());
}
DenseDoubleMatrix2D q = factorization.getItemMatrix();
List<Tuple2id> items = candidates
.mapToObj(iidx -> tuple(iidx, q.viewRow(iidx).zDotProduct(pu)))
.sorted(comparingDouble(Tuple2id::v2).reversed())
.collect(toList());
return new FastRecommendation(uidx, items);
}
示例10: load
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
@Override
public <U, I> Factorization<U, I> load(InputStream in, FastUserIndex<U> uIndex, FastItemIndex<I> iIndex) throws IOException {
int K;
DenseDoubleMatrix2D userMatrix;
DenseDoubleMatrix2D itemMatrix;
try (ZipInputStream zip = new ZipInputStream(in)) {
zip.getNextEntry();
BufferedReader reader = new BufferedReader(new InputStreamReader(zip));
int numUsers = parseInt(reader.readLine());
int numItems = parseInt(reader.readLine());
K = parseInt(reader.readLine());
zip.closeEntry();
zip.getNextEntry();
userMatrix = loadDenseDoubleMatrix2D(zip, numUsers, K);
zip.closeEntry();
zip.getNextEntry();
itemMatrix = loadDenseDoubleMatrix2D(zip, numItems, K);
zip.closeEntry();
}
return new Factorization<>(uIndex, iIndex, userMatrix, itemMatrix, K);
}
示例11: ColtDenseDoubleMatrix2D
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
public ColtDenseDoubleMatrix2D(DoubleMatrix2D m) {
super(m.rows(), m.columns());
if (m instanceof DenseDoubleMatrix2D) {
this.matrix = (DenseDoubleMatrix2D) m;
} else {
this.matrix = new DenseDoubleMatrix2D(m.toArray());
}
}
示例12: ModeIndependenceOperator
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
public ModeIndependenceOperator(Parameter parameter, double scaleFactor, double[][] inMatrix, double weight,
CoercionMode mode, boolean isVarianceMatrix) {
super(mode);
this.scaleFactor = scaleFactor;
this.parameter = parameter;
setWeight(weight);
dim = parameter.getDimension();
SingularValueDecomposition svd = new SingularValueDecomposition(new DenseDoubleMatrix2D(inMatrix));
if (inMatrix[0].length != svd.rank()) {
throw new RuntimeException("Variance matrix in mvnOperator is not of full rank");
}
final double[][] matrix;
if (isVarianceMatrix) {
matrix = inMatrix;
} else {
matrix = formXtXInverse(inMatrix);
}
// System.err.println("Matrix:");
// System.err.println(new Matrix(matrix));
try {
cholesky = (new CholeskyDecomposition(matrix)).getL();
} catch (IllegalDimension illegalDimension) {
throw new RuntimeException("Unable to decompose matrix in mvnOperator");
}
// System.err.println("Cholesky:");
// System.err.println(new Matrix(cholesky));
// System.exit(-1);
}
示例13: allocateScratch
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
void allocateScratch(int numY, int seqLength) {
if (Mi.length < seqLength) { //what if Mi.length > seqLength, I hope
DoubleMatrix2D tempMi[] = Mi;
DoubleMatrix1D tempRi[] = Ri;
int i;
Mi = new DenseDoubleMatrix2D[seqLength];
Ri = new DenseDoubleMatrix1D[seqLength];
for (i = 0; i < tempMi.length; i++) {
Mi[i] = tempMi[i];
Ri[i] = tempRi[i];
}
for (; i < seqLength; i++) {
Mi[i] = new DenseDoubleMatrix2D(numY, numY);
Ri[i] = new DenseDoubleMatrix1D(numY);
}
}
}
示例14: AreaPolynomialApproximationLogConstantQ
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
/**
* Constructor that sets description, dependencies, and offsets from
* FeatureExtractor
*/
public AreaPolynomialApproximationLogConstantQ() {
String name = "2D Polynomial Approximation of Log of ConstantQ";
String description = "coeffecients of 2D polynomial best describing the input matrix.";
String[] attributes = new String[] { "horizontal size (window length)",
"vertical size (number of feature dimensions)",
"number of x (horizontal) terms",
"number of y (vertical) terms" };
definition = new FeatureDefinition(name, description, true, 0,
attributes);
dependencies = new String[windowLength];
for (int i = 0; i < dependencies.length; ++i) {
dependencies[i] = "Log of ConstantQ";
}
offsets = new int[windowLength];
for (int i = 0; i < offsets.length; ++i) {
offsets[i] = 0 - i;
}
terms = new DenseDoubleMatrix2D(windowLength*featureLength,k*l);
z = new DenseDoubleMatrix2D(featureLength*windowLength,1);
calcTerms(terms);
}
示例15: setWindow
import cern.colt.matrix.impl.DenseDoubleMatrix2D; //导入依赖的package包/类
/**
* Function that must be overridden to allow this feature to be set globally
* by GlobalChange frame.
*
* @param n
* the number of windows of offset to be used in calculating this
* feature
*/
public void setWindow(int n) throws Exception {
if (n < 1) {
throw new Exception(
"Area Polynomial Approximation window length must be positive");
} else {
windowLength = n;
dependencies = new String[windowLength];
offsets = new int[windowLength];
for (int i = 0; i < windowLength; ++i) {
dependencies[i] = "Magnitude Spectrum";
offsets[i] = 0 - i;
}
terms = new DenseDoubleMatrix2D(windowLength*featureLength,k*l);
z = new DenseDoubleMatrix2D(1,featureLength*windowLength);
calcTerms(terms);
}
}