本文整理了Java中org.apache.mahout.math.Matrix.getColumnLabelBindings()
方法的一些代码示例,展示了Matrix.getColumnLabelBindings()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.getColumnLabelBindings()
方法的具体详情如下:
包路径:org.apache.mahout.math.Matrix
类名称:Matrix
方法名:getColumnLabelBindings
[英]Return a map of the current column label bindings of the receiver
[中]返回接收器当前列标签绑定的映射
代码示例来源:origin: apache/mahout
@Test
public void testLabelBindingSerialization() {
assertNull("row bindings", test.getRowLabelBindings());
assertNull("col bindings", test.getColumnLabelBindings());
Map<String, Integer> rowBindings = Maps.newHashMap();
rowBindings.put("Fee", 0);
rowBindings.put("Fie", 1);
rowBindings.put("Foe", 2);
test.setRowLabelBindings(rowBindings);
assertEquals("row", rowBindings, test.getRowLabelBindings());
Map<String, Integer> colBindings = Maps.newHashMap();
colBindings.put("Foo", 0);
colBindings.put("Bar", 1);
colBindings.put("Baz", 2);
test.setColumnLabelBindings(colBindings);
assertEquals("col", colBindings, test.getColumnLabelBindings());
}
代码示例来源:origin: apache/mahout
@Test
public void testLabelBindingSerialization() {
Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
{1, 4, 2}});
assertNull("row bindings", m.getRowLabelBindings());
assertNull("col bindings", m.getColumnLabelBindings());
Map<String, Integer> rowBindings = new HashMap<>();
rowBindings.put("Fee", 0);
rowBindings.put("Fie", 1);
rowBindings.put("Foe", 2);
m.setRowLabelBindings(rowBindings);
assertEquals("row", rowBindings, m.getRowLabelBindings());
Map<String, Integer> colBindings = new HashMap<>();
colBindings.put("Foo", 0);
colBindings.put("Bar", 1);
colBindings.put("Baz", 2);
m.setColumnLabelBindings(colBindings);
assertEquals("col", colBindings, m.getColumnLabelBindings());
}
}
代码示例来源:origin: apache/mahout
flags |= FLAG_SEQUENTIAL;
if (matrix.getRowLabelBindings() != null || matrix.getColumnLabelBindings() != null) {
flags |= FLAG_LABELS;
writeLabelBindings(out, matrix.getColumnLabelBindings(), matrix.getRowLabelBindings());
代码示例来源:origin: apache/mahout
@Test(expected = IllegalStateException.class)
public void testSettingLabelBindings() {
assertNull("row bindings", test.getRowLabelBindings());
assertNull("col bindings", test.getColumnLabelBindings());
test.set("Fee", "Foo", 1, 1, 9);
assertNotNull("row", test.getRowLabelBindings());
assertNotNull("row", test.getRowLabelBindings());
assertEquals("Fee", 1, test.getRowLabelBindings().get("Fee").intValue());
assertEquals("Foo", 1, test.getColumnLabelBindings().get("Foo").intValue());
assertEquals("FeeFoo", test.get(1, 1), test.get("Fee", "Foo"), EPSILON);
test.get("Fie", "Foe");
}
代码示例来源:origin: apache/mahout
private static void compareMatrices(Matrix m, Matrix m2) {
assertEquals(m.numRows(), m2.numRows());
assertEquals(m.numCols(), m2.numCols());
for (int r = 0; r < m.numRows(); r++) {
for (int c = 0; c < m.numCols(); c++) {
assertEquals(m.get(r, c), m2.get(r, c), EPSILON);
}
}
Map<String,Integer> bindings = m.getRowLabelBindings();
Map<String, Integer> bindings2 = m2.getRowLabelBindings();
assertEquals(bindings == null, bindings2 == null);
if (bindings != null) {
assertEquals(bindings.size(), m.numRows());
assertEquals(bindings.size(), bindings2.size());
for (Map.Entry<String,Integer> entry : bindings.entrySet()) {
assertEquals(entry.getValue(), bindings2.get(entry.getKey()));
}
}
bindings = m.getColumnLabelBindings();
bindings2 = m2.getColumnLabelBindings();
assertEquals(bindings == null, bindings2 == null);
if (bindings != null) {
assertEquals(bindings.size(), bindings2.size());
for (Map.Entry<String,Integer> entry : bindings.entrySet()) {
assertEquals(entry.getValue(), bindings2.get(entry.getKey()));
}
}
}
代码示例来源:origin: apache/mahout
@Test(expected = IllegalStateException.class)
public void testSettingLabelBindings() {
Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
{1, 4, 2}});
assertNull("row bindings", m.getRowLabelBindings());
assertNull("col bindings", m.getColumnLabelBindings());
m.set("Fee", "Foo", 1, 2, 9);
assertNotNull("row", m.getRowLabelBindings());
assertNotNull("row", m.getRowLabelBindings());
assertEquals("Fee", 1, m.getRowLabelBindings().get("Fee").intValue());
assertEquals("Fee", 2, m.getColumnLabelBindings().get("Foo").intValue());
assertEquals("FeeFoo", m.get(1, 2), m.get("Fee", "Foo"), EPSILON);
m.get("Fie", "Foe");
}
代码示例来源:origin: apache/mahout
@Test
public void testLabelBindings() {
Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
{1, 4, 2}});
assertNull("row bindings", m.getRowLabelBindings());
assertNull("col bindings", m.getColumnLabelBindings());
Map<String, Integer> rowBindings = new HashMap<>();
rowBindings.put("Fee", 0);
rowBindings.put("Fie", 1);
rowBindings.put("Foe", 2);
m.setRowLabelBindings(rowBindings);
assertEquals("row", rowBindings, m.getRowLabelBindings());
Map<String, Integer> colBindings = new HashMap<>();
colBindings.put("Foo", 0);
colBindings.put("Bar", 1);
colBindings.put("Baz", 2);
m.setColumnLabelBindings(colBindings);
assertEquals("row", rowBindings, m.getRowLabelBindings());
assertEquals("Fee", m.get(0, 1), m.get("Fee", "Bar"), EPSILON);
double[] newrow = {9, 8, 7};
m.set("Foe", newrow);
assertEquals("FeeBaz", m.get(0, 2), m.get("Fee", "Baz"), EPSILON);
}
代码示例来源:origin: apache/mahout
@Test
public void testLabelBindings() {
assertNull("row bindings", test.getRowLabelBindings());
assertNull("col bindings", test.getColumnLabelBindings());
Map<String, Integer> rowBindings = Maps.newHashMap();
rowBindings.put("Fee", 0);
rowBindings.put("Fie", 1);
test.setRowLabelBindings(rowBindings);
assertEquals("row", rowBindings, test.getRowLabelBindings());
Map<String, Integer> colBindings = Maps.newHashMap();
colBindings.put("Foo", 0);
colBindings.put("Bar", 1);
test.setColumnLabelBindings(colBindings);
assertEquals("row", rowBindings, test.getRowLabelBindings());
assertEquals("Fee", test.get(0, 1), test.get("Fee", "Bar"), EPSILON);
double[] newrow = {9, 8};
test.set("Fie", newrow);
assertEquals("FeeBar", test.get(0, 1), test.get("Fee", "Bar"), EPSILON);
}
代码示例来源:origin: apache/mahout
private static void doTestMatrixWritableEquals(Matrix m) throws IOException {
Writable matrixWritable = new MatrixWritable(m);
MatrixWritable matrixWritable2 = new MatrixWritable();
writeAndRead(matrixWritable, matrixWritable2);
Matrix m2 = matrixWritable2.get();
compareMatrices(m, m2);
doCheckBindings(m2.getRowLabelBindings());
doCheckBindings(m2.getColumnLabelBindings());
}
代码示例来源:origin: org.apache.mahout/mahout-core
public void setMatrix(Matrix m) {
int length = confusionMatrix.length;
if (m.numRows() != m.numCols()) {
throw new IllegalArgumentException(
"ConfusionMatrix: matrix(" + m.numRows() + ',' + m.numCols() + ") must be square");
}
for (int r = 0; r < length; r++) {
for (int c = 0; c < length; c++) {
confusionMatrix[r][c] = (int) Math.round(m.get(r, c));
}
}
Map<String,Integer> labels = m.getRowLabelBindings();
if (labels == null) {
labels = m.getColumnLabelBindings();
}
if (labels != null) {
String[] sorted = sortLabels(labels);
verifyLabels(length, sorted);
labelMap.clear();
for (int i = 0; i < length; i++) {
labelMap.put(sorted[i], i);
}
}
}
代码示例来源:origin: org.apache.mahout/mahout-mrlegacy
public void setMatrix(Matrix m) {
int length = confusionMatrix.length;
if (m.numRows() != m.numCols()) {
throw new IllegalArgumentException(
"ConfusionMatrix: matrix(" + m.numRows() + ',' + m.numCols() + ") must be square");
}
for (int r = 0; r < length; r++) {
for (int c = 0; c < length; c++) {
confusionMatrix[r][c] = (int) Math.round(m.get(r, c));
}
}
Map<String,Integer> labels = m.getRowLabelBindings();
if (labels == null) {
labels = m.getColumnLabelBindings();
}
if (labels != null) {
String[] sorted = sortLabels(labels);
verifyLabels(length, sorted);
labelMap.clear();
for (int i = 0; i < length; i++) {
labelMap.put(sorted[i], i);
}
}
}
代码示例来源:origin: org.apache.mahout/mahout-mr
public void setMatrix(Matrix m) {
int length = confusionMatrix.length;
if (m.numRows() != m.numCols()) {
throw new IllegalArgumentException(
"ConfusionMatrix: matrix(" + m.numRows() + ',' + m.numCols() + ") must be square");
}
for (int r = 0; r < length; r++) {
for (int c = 0; c < length; c++) {
confusionMatrix[r][c] = (int) Math.round(m.get(r, c));
}
}
Map<String,Integer> labels = m.getRowLabelBindings();
if (labels == null) {
labels = m.getColumnLabelBindings();
}
if (labels != null) {
String[] sorted = sortLabels(labels);
verifyLabels(length, sorted);
labelMap.clear();
for (int i = 0; i < length; i++) {
labelMap.put(sorted[i], i);
}
}
}
代码示例来源:origin: org.apache.mahout/mahout-core
/** Writes a typed Matrix instance to the output stream */
public static void writeMatrix(DataOutput out, Matrix matrix) throws IOException {
int flags = 0;
Vector row = matrix.viewRow(0);
if (row.isDense()) {
flags |= FLAG_DENSE;
}
if (row.isSequentialAccess()) {
flags |= FLAG_SEQUENTIAL;
}
if (matrix.getRowLabelBindings() != null || matrix.getColumnLabelBindings() != null) {
flags |= FLAG_LABELS;
}
out.writeInt(flags);
out.writeInt(matrix.rowSize());
out.writeInt(matrix.columnSize());
for (int i = 0; i < matrix.rowSize(); i++) {
VectorWritable.writeVector(out, matrix.viewRow(i), false);
}
if ((flags & FLAG_LABELS) != 0) {
writeLabelBindings(out, matrix.getColumnLabelBindings(), matrix.getRowLabelBindings());
}
}
}
代码示例来源:origin: cloudera/mahout
@Test
public void testLabelBindingSerialization() {
assertNull("row bindings", test.getRowLabelBindings());
assertNull("col bindings", test.getColumnLabelBindings());
Map<String, Integer> rowBindings = Maps.newHashMap();
rowBindings.put("Fee", 0);
rowBindings.put("Fie", 1);
rowBindings.put("Foe", 2);
test.setRowLabelBindings(rowBindings);
assertEquals("row", rowBindings, test.getRowLabelBindings());
Map<String, Integer> colBindings = Maps.newHashMap();
colBindings.put("Foo", 0);
colBindings.put("Bar", 1);
colBindings.put("Baz", 2);
test.setColumnLabelBindings(colBindings);
assertEquals("col", colBindings, test.getColumnLabelBindings());
}
代码示例来源:origin: cloudera/mahout
@Test
public void testLabelBindingSerialization() {
Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
{1, 4, 2}});
assertNull("row bindings", m.getRowLabelBindings());
assertNull("col bindings", m.getColumnLabelBindings());
Map<String, Integer> rowBindings = Maps.newHashMap();
rowBindings.put("Fee", 0);
rowBindings.put("Fie", 1);
rowBindings.put("Foe", 2);
m.setRowLabelBindings(rowBindings);
assertEquals("row", rowBindings, m.getRowLabelBindings());
Map<String, Integer> colBindings = Maps.newHashMap();
colBindings.put("Foo", 0);
colBindings.put("Bar", 1);
colBindings.put("Baz", 2);
m.setColumnLabelBindings(colBindings);
assertEquals("col", colBindings, m.getColumnLabelBindings());
}
}
代码示例来源:origin: cloudera/mahout
@Test(expected = IllegalStateException.class)
public void testSettingLabelBindings() {
assertNull("row bindings", test.getRowLabelBindings());
assertNull("col bindings", test.getColumnLabelBindings());
test.set("Fee", "Foo", 1, 1, 9);
assertNotNull("row", test.getRowLabelBindings());
assertNotNull("row", test.getRowLabelBindings());
assertEquals("Fee", 1, test.getRowLabelBindings().get("Fee").intValue());
assertEquals("Foo", 1, test.getColumnLabelBindings().get("Foo").intValue());
assertEquals("FeeFoo", test.get(1, 1), test.get("Fee", "Foo"), EPSILON);
test.get("Fie", "Foe");
}
代码示例来源:origin: cloudera/mahout
@Test(expected = IllegalStateException.class)
public void testSettingLabelBindings() {
Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
{1, 4, 2}});
assertNull("row bindings", m.getRowLabelBindings());
assertNull("col bindings", m.getColumnLabelBindings());
m.set("Fee", "Foo", 1, 2, 9);
assertNotNull("row", m.getRowLabelBindings());
assertNotNull("row", m.getRowLabelBindings());
assertEquals("Fee", 1, m.getRowLabelBindings().get("Fee").intValue());
assertEquals("Fee", 2, m.getColumnLabelBindings().get("Foo").intValue());
assertEquals("FeeFoo", m.get(1, 2), m.get("Fee", "Foo"), EPSILON);
m.get("Fie", "Foe");
}
代码示例来源:origin: cloudera/mahout
@Test
public void testLabelBindings() {
Matrix m = matrixFactory(new double[][]{{1, 3, 4}, {5, 2, 3},
{1, 4, 2}});
assertNull("row bindings", m.getRowLabelBindings());
assertNull("col bindings", m.getColumnLabelBindings());
Map<String, Integer> rowBindings = Maps.newHashMap();
rowBindings.put("Fee", 0);
rowBindings.put("Fie", 1);
rowBindings.put("Foe", 2);
m.setRowLabelBindings(rowBindings);
assertEquals("row", rowBindings, m.getRowLabelBindings());
Map<String, Integer> colBindings = Maps.newHashMap();
colBindings.put("Foo", 0);
colBindings.put("Bar", 1);
colBindings.put("Baz", 2);
m.setColumnLabelBindings(colBindings);
assertEquals("row", rowBindings, m.getRowLabelBindings());
assertEquals("Fee", m.get(0, 1), m.get("Fee", "Bar"), EPSILON);
double[] newrow = {9, 8, 7};
m.set("Foe", newrow);
assertEquals("FeeBaz", m.get(0, 2), m.get("Fee", "Baz"), EPSILON);
}
代码示例来源:origin: cloudera/mahout
@Test
public void testLabelBindings() {
assertNull("row bindings", test.getRowLabelBindings());
assertNull("col bindings", test.getColumnLabelBindings());
Map<String, Integer> rowBindings = Maps.newHashMap();
rowBindings.put("Fee", 0);
rowBindings.put("Fie", 1);
test.setRowLabelBindings(rowBindings);
assertEquals("row", rowBindings, test.getRowLabelBindings());
Map<String, Integer> colBindings = Maps.newHashMap();
colBindings.put("Foo", 0);
colBindings.put("Bar", 1);
test.setColumnLabelBindings(colBindings);
assertEquals("row", rowBindings, test.getRowLabelBindings());
assertEquals("Fee", test.get(0, 1), test.get("Fee", "Bar"), EPSILON);
double[] newrow = {9, 8};
test.set("Fie", newrow);
assertEquals("FeeBar", test.get(0, 1), test.get("Fee", "Bar"), EPSILON);
}
代码示例来源:origin: org.apache.mahout/mahout-mrlegacy
private static void doTestMatrixWritableEquals(Matrix m) throws IOException {
Writable matrixWritable = new MatrixWritable(m);
MatrixWritable matrixWritable2 = new MatrixWritable();
writeAndRead(matrixWritable, matrixWritable2);
Matrix m2 = matrixWritable2.get();
compareMatrices(m, m2);
doCheckBindings(m2.getRowLabelBindings());
doCheckBindings(m2.getColumnLabelBindings());
}
内容来源于网络,如有侵权,请联系作者删除!