本文整理了Java中org.ujmp.core.Matrix.toColumnVector()
方法的一些代码示例,展示了Matrix.toColumnVector()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.toColumnVector()
方法的具体详情如下:
包路径:org.ujmp.core.Matrix
类名称:Matrix
方法名:toColumnVector
暂无
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix predictOne(Matrix input) {
input = input.toColumnVector(Ret.NEW);
Matrix input2 = Matrix.Factory.zeros(1, selectedFeatures.size());
for (int i = 0; i < selectedFeatures.size(); i++) {
input2.setAsDouble(input.getAsDouble(0, selectedFeatures.get(i)), 0, i);
}
return learningAlgorithm.predictOne(input2);
}
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix hash(Matrix input) {
Matrix result = input.toColumnVector(Ret.NEW).mtimes(randomVectors).ge(Ret.NEW, 0);
return result;
}
代码示例来源:origin: jdmp/java-data-mining-package
public final int getClassCount() {
return (int) get(0).getAsMatrix(TARGET).toColumnVector(Ret.LINK).getColumnCount();
}
代码示例来源:origin: jdmp/java-data-mining-package
public final int getFeatureCount() {
return (int) get(0).getAsMatrix(INPUT).toColumnVector(Ret.LINK).getColumnCount();
}
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix compress(Matrix input) {
return input.toColumnVector(Ret.LINK).minus(Ret.LINK, true, mean).divide(std).mtimes(u);
}
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix predictOne(Matrix input) {
input = input.toColumnVector(Ret.LINK);
final double[] probs = new double[classCount];
final double[] logs = new double[classCount];
for (int j = 0; j < classCount; j++) {
logs[j] += Math.log(classDists[j].getProbability(1.0));
}
// for all features
for (int j = 0; j < input.getColumnCount(); j++) {
// for all classes
double probSum = 0;
for (int i = 0; i < classCount; i++) {
double value = input.getAsDouble(0, j);
double probability = dists[j][i].getProbability(value);
probs[i] = probability;
probSum += probability;
}
for (int i = 0; i < classCount; i++) {
logs[i] += Math.log(probs[i] / probSum);
}
}
final double[] finalProbs = MathUtil.logToProbs(logs);
Matrix m = Matrix.Factory.linkToArray(finalProbs).transpose();
return m;
}
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix predictOne(Matrix input) {
List<Sortable<Double, Matrix>> bestResults = new FastArrayList<Sortable<Double, Matrix>>();
for (Sample s : dataSet) {
Matrix reference = s.getAsMatrix(getInputLabel());
double distance = input.euklideanDistanceTo(reference, true);
if (bestResults.size() < k) {
bestResults.add(new Sortable<Double, Matrix>(distance, s
.getAsMatrix(getTargetLabel())));
Collections.sort(bestResults);
} else if (distance < bestResults.get(k - 1).getComparable()) {
bestResults.remove(k - 1);
bestResults.add(new Sortable<Double, Matrix>(distance, s
.getAsMatrix(getTargetLabel())));
Collections.sort(bestResults);
}
}
List<Matrix> results = new FastArrayList<Matrix>();
for (Sortable<Double, Matrix> s : bestResults) {
results.add(s.getObject().toColumnVector(Ret.LINK));
}
Matrix resultMatrix = Matrix.Factory.vertCat(results);
Matrix mean = resultMatrix.mean(Ret.NEW, Matrix.ROW, true);
return mean;
}
}
代码示例来源:origin: jdmp/java-data-mining-package
System.out.println("Converting samples: " + Math.round(((double) i / dataSet.size() * 100)) + "% done");
Matrix input = s.getAsMatrix(getInputLabel()).toColumnVector(Ret.LINK);
int targetClass = (int) s.getAsMatrix(getTargetLabel()).toColumnVector(Ret.LINK).getCoordinatesOfMaximum()[COLUMN];
prob.y[i] = targetClass;
long columnCount = input.getColumnCount();
代码示例来源:origin: jdmp/java-data-mining-package
public final void predictOne(Sample sample) {
Matrix predicted = predictOne(sample.getAsMatrix(getInputLabel()));
predicted = predicted.toColumnVector(Ret.LINK);
sample.put(PREDICTED, predicted);
if (sample.getAsMatrix(getTargetLabel()) != null) {
Matrix target = sample.getAsMatrix(getTargetLabel()).toColumnVector(Ret.LINK);
Matrix error = target.minus(predicted);
sample.put(DIFFERENCE, error);
sample.put(RMSE, Matrix.Factory.linkToValue(error.getRMS()));
}
sample.fireValueChanged();
}
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix predictOne(Matrix input) {
input = input.toColumnVector(Ret.NEW);
Matrix bias = Matrix.Factory.ones(input.getRowCount(), 1);
Matrix data = Matrix.Factory.horCat(bias, input);
Matrix result = getParameterMatrix().transpose().mtimes(data.transpose());
return result.transpose();
}
代码示例来源:origin: jdmp/java-data-mining-package
public void trainAll(ListDataSet dataSet) {
selectFeatures(dataSet);
ListDataSet newDataSet = new DefaultListDataSet();
for (Sample s1 : dataSet) {
Sample s2 = new DefaultSample();
Matrix input1 = s1.getAsMatrix(getInputLabel()).toColumnVector(Ret.NEW);
Matrix input2 = Matrix.Factory.zeros(1, selectedFeatures.size());
for (int i = 0; i < selectedFeatures.size(); i++) {
input2.setAsDouble(input1.getAsDouble(0, selectedFeatures.get(i)), 0, i);
}
s2.put(getInputLabel(), input2);
s2.put(getTargetLabel(), s1.getAsMatrix(getTargetLabel()));
newDataSet.add(s2);
}
learningAlgorithm.trainAll(newDataSet);
}
代码示例来源:origin: jdmp/java-data-mining-package
private Matrix createCompleteMatrix(ListDataSet dataSet) {
final int sampleCount = dataSet.size();
final int featureCount = getFeatureCount(dataSet);
final int targetCount = getClassCount(dataSet);
Matrix m = Matrix.Factory.zeros(sampleCount, featureCount + targetCount);
for (int r = 0; r < sampleCount; r++) {
Sample s = dataSet.get(r);
Matrix input = s.getAsMatrix(getInputLabel()).toColumnVector(Ret.NEW);
Matrix target = s.getAsMatrix(getTargetLabel()).toColumnVector(Ret.NEW);
for (int c = 0; c < featureCount; c++) {
m.setAsDouble(input.getAsDouble(0, c), r, c);
}
for (int c = 0; c < targetCount; c++) {
m.setAsDouble(target.getAsDouble(0, c), r, c + featureCount);
}
}
return m;
}
代码示例来源:origin: jdmp/java-data-mining-package
for (Sample s : dataSet) {
final Matrix sampleInput = s.getAsMatrix(getInputLabel()).toColumnVector(Ret.LINK);
final Matrix sampleTarget = s.getAsMatrix(getTargetLabel()).toColumnVector(Ret.LINK);
final double weight = s.getWeight();
代码示例来源:origin: jdmp/java-data-mining-package
public void trainAll(ListDataSet dataSet) {
featureCount = getFeatureCount(dataSet);
classCount = getClassCount(dataSet);
dimensions = featureCount + classCount;
Matrix x = Matrix.Factory.zeros(dataSet.size(), dimensions);
int i = 0;
for (Sample s : dataSet) {
Matrix input = s.getAsMatrix(getInputLabel()).toColumnVector(Ret.LINK);
for (int c = 0; c < featureCount; c++) {
x.setAsDouble(input.getAsDouble(0, c), i, c);
}
Matrix target = s.getAsMatrix(getTargetLabel()).toColumnVector(Ret.LINK);
for (int c = 0; c < classCount; c++) {
x.setAsDouble(target.getAsDouble(0, c), i, c + featureCount);
}
i++;
}
meanMatrix = x.mean(Ret.NEW, Matrix.ROW, true);
covarianceMatrix = x.cov(Ret.NEW, true, true);
try {
inverse = covarianceMatrix.inv();
factor = 1.0 / Math.sqrt(covarianceMatrix.det() * Math.pow(2.0 * Math.PI, dimensions));
} catch (Exception e) {
inverse = covarianceMatrix.pinv();
factor = 1.0;
}
}
代码示例来源:origin: jdmp/java-data-mining-package
double sampleWeight = MathUtil.getMatrix(matrices.get(SAMPLEWEIGHT)).doubleValue();
Matrix transposedInput = MathUtil.getMatrix(matrices.get(INPUT)).toColumnVector(Ret.NEW);
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix predictOne(Matrix input) {
input = input.toColumnVector(Ret.LINK);
long columnCount = input.getColumnCount();
int count = 0;
for (int j = 0; j < columnCount; j++) {
double value = input.getAsDouble(0, j);
if (value != 0.0 && !MathUtil.isNaNOrInfinite(value)) {
count++;
}
}
Feature[] x = new Feature[count];
count = 0;
for (int j = 0; j < columnCount; j++) {
double value = input.getAsDouble(0, j);
if (value != 0.0 && !MathUtil.isNaNOrInfinite(value)) {
x[count] = features.get(j + 1, value);
count++;
}
}
return predictOne(x);
}
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix predictOne(Matrix input) {
input = input.toColumnVector(Ret.NEW);
Matrix x = Matrix.Factory.zeros(1, input.getColumnCount() + 1);
for (int c = 0; c < input.getColumnCount(); c++) {
x.setAsDouble(input.getAsDouble(0, c), 0, c + 1);
}
x = x.minus(mean).divide(std);
x.setAsDouble(1, 0, 0);
Matrix result = x.mtimes(getParameterMatrix());
return result;
}
代码示例来源:origin: jdmp/java-data-mining-package
int randomIndex = MathUtil.nextInteger(dataSet.size());
Sample s = dataSet.get(randomIndex);
inputs.add(s.getAsMatrix(Sample.INPUT).toColumnVector(Ret.NEW));
targets.add(s.getAsMatrix(Sample.TARGET).toColumnVector(Ret.NEW));
代码示例来源:origin: jdmp/java-data-mining-package
public Matrix predictOne(Matrix input) {
input = input.toColumnVector(Ret.NEW);
Matrix x = Matrix.Factory.zeros(1, dimensions);
for (int i = 0; i < featureCount; i++) {
x.setAsDouble(input.getAsDouble(0, i), 0, i);
}
Matrix result = Matrix.Factory.zeros(1, classCount);
double sum = 0;
for (int i = 0; i < classCount; i++) {
if (i > 0) {
x.setAsDouble(0, 0, featureCount + i - 1);
}
x.setAsDouble(1, 0, featureCount + i);
double density = getDensity(x);
result.setAsDouble(density, 0, i);
sum += density;
}
for (int i = 0; i < classCount; i++) {
result.setAsDouble(result.getAsDouble(0, i) / sum, 0, i);
}
return result;
}
代码示例来源:origin: jdmp/java-data-mining-package
Matrix input = s.getAsMatrix(getInputLabel()).toColumnVector(Ret.LINK);
for (int c = 0; c < input.getColumnCount(); c++) {
x.setAsDouble(input.getAsDouble(0, c), i, c);
内容来源于网络,如有侵权,请联系作者删除!