本文整理汇总了Java中org.ujmp.core.Matrix类的典型用法代码示例。如果您正苦于以下问题:Java Matrix类的具体用法?Java Matrix怎么用?Java Matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Matrix类属于org.ujmp.core包,在下文中一共展示了Matrix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: ImportMatrix
import org.ujmp.core.Matrix; //导入依赖的package包/类
public static Matrix ImportMatrix(String txtPath) {
List<String> list = BResult_delete4.GetNameOrder(txtPath);
int m = list.size();
String[] listStrings = list.get(0).split(" ");
int n = listStrings.length;
Matrix matrix = Matrix.Factory.ones(m, n);
int i = 0;
for (String string : list) {
listStrings = list.get(i).split(" ");
int j = 0;
for (String str : listStrings) {
matrix.setAsDouble(Double.parseDouble(str), i, j);
j++;
}
i++;
}
return matrix;
}
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:19,代码来源:AAppearedFacet.java
示例2: AbsMax
import org.ujmp.core.Matrix; //导入依赖的package包/类
/**
* 用于计算一个矩阵的元素中,绝对值最大的那个值。
*
* @param matrix
* @return
*/
public static double AbsMax(Matrix matrix) {
double maxValue = 0.0;
long[] matrix_size = matrix.getSize();
long m = matrix_size[0];
long n = matrix_size[1];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
double absValue = matrix.getAsDouble(i, j);
if (absValue < 0.0)
absValue = absValue * (-1);
if (absValue > maxValue)
maxValue = absValue;
}
}
return maxValue;
}
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:23,代码来源:AAppearedFacet.java
示例3: printMatrix
import org.ujmp.core.Matrix; //导入依赖的package包/类
/**
* 用于把矩阵输出到文件中
*
* @param matrix
* @param outputPath
*/
public static void printMatrix(Matrix matrix, String outputPath) {
long[] size = matrix.getSize();
long m = size[0]; long n = size[1];
String cont = "";
DecimalFormat df = new DecimalFormat("#0.000000");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cont = cont + df.format(matrix.getAsDouble(i,j)) + " ";
}
cont = cont + "\n";
}
try {
FileUtils.write(new File(outputPath), cont, "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
}
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:24,代码来源:AAppearedFacet.java
示例4: NormByRow
import org.ujmp.core.Matrix; //导入依赖的package包/类
/**
* 用于把矩阵按行归一化
*
* @param oriMatrix
* @return
*/
public static Matrix NormByRow(Matrix oriMatrix) {
long[] size = oriMatrix.getSize();
long m = size[0];
long n = size[1];
Matrix normedMatrix = Matrix.Factory.zeros(m, n);
for (int i = 0; i < m; i++) {
double summary = 0.0;
for (int j = 0; j < n; j++) {
summary = summary + oriMatrix.getAsDouble(i, j);
}
if (summary == 0)
continue;
else {
for (int j = 0; j < n; j++) {
normedMatrix.setAsDouble(oriMatrix.getAsDouble(i, j) / summary, i, j);
}
}
}
return normedMatrix;
}
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:27,代码来源:AAppearedFacet.java
示例5: pca
import org.ujmp.core.Matrix; //导入依赖的package包/类
public SparseMatrix pca(SparseMatrix A, int dim) {
logger.info("Type 'pca' started (target dimensions = " + dim + ").");
centerData(A);
logger.info("Computing SVD...");
Matrix[] svd = A.svd();
Matrix U = svd[0];
Matrix S = svd[1];
logger.info("Reducing U to Uk...");
Matrix Uk = U.select(Ret.NEW, "*;0-" + dim);
logger.info("Reducing S to Sk...");
Matrix Sk = S.select(Ret.NEW, "0-" + dim + ";0-" + dim);
logger.info("Computing principal components...");
return (SparseMatrix) Uk.mtimes(Sk);
}
开发者ID:AKSW,项目名称:Resource2Vec,代码行数:21,代码来源:UjmpSVD.java
示例6: plus
import org.ujmp.core.Matrix; //导入依赖的package包/类
public synchronized Matrix plus(Ret returnType, boolean ignoreNaN, Matrix m) {
if (returnType == Ret.ORIG) {
try {
outputBB.rewind();
outputBB.putInt(PLUSMATRIX);
outputStream.write(outputBuffer, 0, outputBB.position());
outputStream.flush();
fireValueChanged();
return this;
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
return super.plus(returnType, ignoreNaN, m);
}
}
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:17,代码来源:ClientMatrix.java
示例7: trainOne
import org.ujmp.core.Matrix; //导入依赖的package包/类
public void trainOne(Matrix input, Matrix sampleWeight, Matrix desiredOutput) {
addDesiredOutputMatrix(desiredOutput.toRowVector(Ret.NEW));
if (sampleWeight == null) {
sampleWeight = Matrix.Factory.linkToValue(1.0);
}
setSampleWeight(sampleWeight.doubleValue());
predictOne(input);
getOutputErrorAlgorithm().calculate();
for (int i = networkLayers.size() - 1; i != -1; i--) {
networkLayers.get(i).calculateBackward();
}
for (int i = networkLayers.size() - 1; i != -1; i--) {
networkLayers.get(i).calculateWeightUpdate();
}
}
开发者ID:jdmp,项目名称:java-data-mining-package,代码行数:19,代码来源:MultiLayerNetwork.java
示例8: normF
import org.ujmp.core.Matrix; //导入依赖的package包/类
public static BigDecimal normF(Matrix m) {
long rows = m.getRowCount();
long cols = m.getColumnCount();
BigDecimal result = BigDecimal.ZERO;
for (long ro = 0; ro < rows; ro++) {
for (long c = 0; c < cols; c++) {
BigDecimal b = m.getAsBigDecimal(ro, c);
BigDecimal temp = BigDecimal.ZERO;
if (MathUtil.isGreater(result.abs(), b.abs())) {
temp = MathUtil.divide(b, result);
temp = MathUtil.times(result.abs(), MathUtil.sqrt(MathUtil.plus(BigDecimal.ONE,
MathUtil.times(temp, temp))));
} else if (!MathUtil.equals(BigDecimal.ZERO, b)) {
temp = MathUtil.divide(result, b);
temp = MathUtil.times(b.abs(), MathUtil.sqrt(MathUtil.plus(BigDecimal.ONE,
MathUtil.times(temp, temp))));
} else {
temp = BigDecimal.ZERO;
}
result = temp;
}
}
return result;
}
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:25,代码来源:BenchmarkUtil.java
示例9: testInvRandSmall
import org.ujmp.core.Matrix; //导入依赖的package包/类
@Test
public final void testInvRandSmall() throws Exception {
Matrix m1 = createMatrixWithAnnotation(10, 10);
do {
m1.randn(Ret.ORIG);
} while (m1.isSingular());
Matrix m2 = m1.inv();
Matrix m3 = m1.mtimes(m2);
Matrix eye = DenseDoubleMatrix2D.Factory.eye(m1.getRowCount(), m1.getColumnCount());
assertEquals(getLabel(), 0.0, eye.minus(m3).getEuklideanValue(), TOLERANCE);
if (m1 instanceof Erasable) {
((Erasable) m1).erase();
}
if (m2 instanceof Erasable) {
((Erasable) m2).erase();
}
if (m3 instanceof Erasable) {
((Erasable) m3).erase();
}
if (eye instanceof Erasable) {
((Erasable) eye).erase();
}
}
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:27,代码来源:AbstractMatrixTest.java
示例10: calculate
import org.ujmp.core.Matrix; //导入依赖的package包/类
public ListDataSet calculate(ListDataSet dataSet) throws Exception {
product1ToIds.setLabel("Product 1 Ids");
product2ToIds.setLabel("Product 2 Ids");
Matrix product1Count = new CountMatrix(product1ToIds);
product1Count.setLabel("Product 1 Count");
Matrix product2Count = new CountMatrix(product2ToIds);
product2Count.setLabel("Product 2 Count");
for (int r = 0; r < dataSet.size(); r++) {
if (r % 1000 == 0) {
System.out.println(r + " of " + dataSet.size());
}
RelationalSample s = (RelationalSample) dataSet.get(r);
Collection<?> products = s.getObjects();
if (products.size() != 0) {
addProduct1Count(products, r);
addProduct2Count(products, r);
}
}
return calculateP(minSupport);
}
开发者ID:jdmp,项目名称:java-data-mining-package,代码行数:26,代码来源:MarketBasketAnalysis.java
示例11: CountActive
import org.ujmp.core.Matrix; //导入依赖的package包/类
public ListDataSet CountActive(int number) {
ListDataSet ds = labeledDataSet("Count " + number);
double possibilites = Math.pow(2, number);
for (int i = 0; i < possibilites; i++) {
BitSet bits = BitSet.valueOf(new long[] { i });
Sample sample = Sample.Factory.labeledSample("" + i);
Matrix input = Matrix.Factory.zeros(1, number);
Matrix target = Matrix.Factory.zeros(1, number + 1);
int count = 0;
for (int j = 0; j < number; j++) {
if (bits.get(j)) {
input.setAsDouble(1, 0, j);
count++;
}
}
target.setAsDouble(1, 0, count);
sample.put(Sample.INPUT, input);
sample.put(Sample.TARGET, target);
ds.add(sample);
}
return ds;
}
开发者ID:jdmp,项目名称:java-data-mining-package,代码行数:23,代码来源:DefaultDataSetFactory.java
示例12: Selection
import org.ujmp.core.Matrix; //导入依赖的package包/类
public Selection(Matrix m, Collection<? extends Number>... selection) {
super(m);
this.selection = new long[selection.length][];
if (selection[ROW] != null) {
this.selection[ROW] = MathUtil.collectionToLongArray(selection[ROW]);
}
if (selection[COLUMN] != null) {
this.selection[COLUMN] = MathUtil.collectionToLongArray(selection[COLUMN]);
}
if (this.selection[ROW] != null && this.selection[COLUMN] != null) {
size = new long[] { this.selection[ROW].length, this.selection[COLUMN].length };
} else {
if (this.selection[ROW] == null) {
size = new long[] { getSource().getRowCount(), this.selection[COLUMN].length };
} else {
size = new long[] { this.selection[ROW].length, getSource().getColumnCount() };
}
}
createAnnotation();
}
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:21,代码来源:Selection.java
示例13: exportToXLSFile
import org.ujmp.core.Matrix; //导入依赖的package包/类
/**
* 导出矩阵到XLS EXCEL文件
* @param matrix
* @param file
* @param sheetName
* @throws IOException
*/
public static void exportToXLSFile(final Matrix matrix, final File file,
String sheetName) throws IOException
{
final Workbook workbook = new HSSFWorkbook();
//调用exportToExcelFile将矩阵方法导出到Excel文件
exportToExcelFile(workbook, matrix, file, sheetName);
//final FileOutputStream fileOutputStream = new FileOutputStream(file);
//final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
//workbook.write(fileOutputStream);
//bufferedOutputStream.close();
//fileOutputStream.close();
}
开发者ID:ansleliu,项目名称:GraphicsViewJambi,代码行数:22,代码来源:ExportNetworkToExcel.java
示例14: exportToXLSXFile
import org.ujmp.core.Matrix; //导入依赖的package包/类
/**
* 导出矩阵到XLSX EXCEL文件
* @param matrix
* @param file
* @param sheetName
* @throws IOException
*/
public static void exportToXLSXFile(final Matrix matrix, final File file,
final String sheetName)throws IOException
{
final Workbook workbook = new XSSFWorkbook();
//调用exportToExcelFile将矩阵方法导出到Excel文件
exportToExcelFile(workbook, matrix, file, sheetName);
//final FileOutputStream fileOutputStream = new FileOutputStream(file);
//final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
//workbook.write(fileOutputStream);
//bufferedOutputStream.close();
//fileOutputStream.close();
}
开发者ID:ansleliu,项目名称:GraphicsViewJambi,代码行数:22,代码来源:ExportNetworkToExcel.java
示例15: ExportImplementer
import org.ujmp.core.Matrix; //导入依赖的package包/类
public static void ExportImplementer(final String netXML,
final String odXML,
final String LocalNetXML) throws IOException
{
/////////////////////////////////////////////////////////////////
//存储从XML文件中读取的信息到矩阵
ImportSumoImplement importSumo = new ImportSumoImplement(netXML, odXML);
Matrix matrixJunction = importSumo.getMatrixJunction();
Matrix matrixEdge = importSumo.getMatrixEdge();
Matrix matrixConnection = importSumo.getMatrixConnection();
List<String> originList = importSumo.getOriginList();
List<String> destinationList = importSumo.getDestinationList();
//存储网络信息到本地Network当中
//------------------------------------------------
long exportXMLStartTime=System.currentTimeMillis(); //获取开始时间
exportXML = new ExportNetworkToXML();
addJunctionToNetwork(matrixJunction, matrixConnection); //添加路口到网络中
addExternalLinkToNetwork(matrixEdge); //添加外部连接到路网中
addODMatrix(originList, destinationList); //添加ODList到路网中
exportXML.createXMLFile(LocalNetXML); //"localnetwork\\localnetwork.xml"
long exportXMLEndTime=System.currentTimeMillis(); //获取结束时间
System.out.println("本地XML路网导出时间: " + (exportXMLEndTime-exportXMLStartTime) +"ms");
//导出本地路网信息到本地EXCEL文件
//-----------------------------------------------
//long exportStartTime=System.currentTimeMillis(); //获取开始时间
//ExportNetworkToExcel.exportToXLSXFile(matrixJunction, "localnetwork\\Junction.xlsx", "Junction");
//ExportNetworkToExcel.exportToXLSXFile(matrixEdge, "localnetwork\\Edge.xlsx", "Edge");
//ExportNetworkToExcel.exportToXLSXFile(matrixConnection, "localnetwork\\Connection.xlsx", "Connection");
//long exportEndTime=System.currentTimeMillis(); //获取结束时间
//System.out.println("本地EXCEL路网导出时间: " + (exportEndTime-exportStartTime) +"ms");
}
开发者ID:ansleliu,项目名称:GraphicsViewJambi,代码行数:36,代码来源:ExportLocalNetImplement.java
示例16: addExternalLinkToNetwork
import org.ujmp.core.Matrix; //导入依赖的package包/类
/**
* 添加外部连接到本地路网
* @param matrixEdge
*/
private static void addExternalLinkToNetwork(final Matrix matrixEdge)
{
final long edgeMatrixRowCount = matrixEdge.getRowCount();
for(int i=0; i<edgeMatrixRowCount; i++)
{
String linkName = matrixEdge.getAsString(i,0); //连接名
String linkFrom = matrixEdge.getAsString(i,1); //起始路口
String linkTo = matrixEdge.getAsString(i,2); //终止路口
String linkLaneCount = matrixEdge.getAsString(i,3); //车道数量
String linkSpeed = matrixEdge.getAsString(i,4); //速度
String linklength = matrixEdge.getAsString(i,5); //连接长度
String linkStartNode = matrixEdge.getAsString(i,6); //起始点
String linkStartNode_X = matrixEdge.getAsString(i,7);//起始点X坐标
String linkStartNode_Y = matrixEdge.getAsString(i,8);//起始点Y坐标
String linkEndNode = matrixEdge.getAsString(i,9); //终止点
String linkEndNode_X = matrixEdge.getAsString(i,10); //终止点X坐标
String linkEndNode_Y = matrixEdge.getAsString(i,11); //终止点Y坐标
String intFrom = linkStartNode + " " + linkStartNode_X + " " + linkStartNode_Y;
String intTo = linkEndNode + " " + linkEndNode_X + " " + linkEndNode_Y;
exportXML.modifyXMLAttribute("junction[@type='Other_Junction']", linkFrom, "intNode", intFrom);
exportXML.modifyXMLAttribute("junction[@type='Other_Junction']", linkTo, "intNode", intTo);
exportXML.addExtLink();
exportXML.addExtLinkConnection(linkStartNode, linkStartNode_X, linkStartNode_Y,
linkEndNode, linkEndNode_X, linkEndNode_Y);
exportXML.setExtLinkAttribute(linkName, linkFrom, linkTo,
linkLaneCount, linkSpeed, linklength);
}
}
开发者ID:ansleliu,项目名称:GraphicsViewJambi,代码行数:35,代码来源:ExportLocalNetImplement.java
示例17: main
import org.ujmp.core.Matrix; //导入依赖的package包/类
public static void main(String args[]) {
List<String> fileName = BResult_delete4.GetNameOrder(oriPath + "otherFiles\\" + domain + "_topics.txt");
List<String> facetList = BResult_delete4.GetNameOrder(oriPath + "experiment\\facet_order.txt");
// FindAppearedFacet(fileName);
Matrix f = FacetRepresentation(fileName, facetList);
Matrix p0 = CreateMatrixP0(fileName);
Matrix p1 = CreateMatrixP1(p0);
Matrix p2 = CreateMatrixP2(p1);
label_propagation_ctopk(fileName, facetList, f, p2.transpose(Ret.LINK));
BResult_delete4.GetWholeResult();
resAnalysis();
System.out.println("done.");
}
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:14,代码来源:AAppearedFacet.java
示例18: SumMatrix
import org.ujmp.core.Matrix; //导入依赖的package包/类
public static double SumMatrix(Matrix matrix) {
double value = 0.0;
long[] matrix_size = matrix.getSize();
long m = matrix_size[0];
long n = matrix_size[1];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
value = value + matrix.getAsDouble(i, j);
}
}
return value;
}
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:13,代码来源:AAppearedFacet.java
示例19: MaxLocation
import org.ujmp.core.Matrix; //导入依赖的package包/类
/**
* 用于找到一个行矩阵的最大值出现在的位置。
*
* @param matrix:这需要是一个行矩阵。一行,n列。
* @return
*/
public static long MaxLocation(Matrix matrix) {
long l = 0;
double maxValue = AbsMax(matrix);
long[] matrix_size = matrix.getSize();
long n = matrix_size[1];
for (int i = 0; i < n; i++) {
if (matrix.getAsDouble(0, i) == maxValue) {
l = i;
break;
}
}
return l;
}
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:20,代码来源:AAppearedFacet.java
示例20: CreateMatrixP2
import org.ujmp.core.Matrix; //导入依赖的package包/类
public static Matrix CreateMatrixP2(Matrix p1) {
System.out.println("正在构建矩阵P2...");
long[] p1_size = p1.getSize();
long n = p1_size[0];
Matrix p2 = NormByRow(p1);
// printMatrix(p2, oriPath + "experiment\\p2.txt");
return p2;
}
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:9,代码来源:AAppearedFacet.java
注:本文中的org.ujmp.core.Matrix类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论