public Matrix Adj() { var rowIndices = RowIndices.OrderBy(index => index).ToList(); var columnIndices = ColumnIndices.OrderBy(index => index).ToList(); if (rowIndices.Count == 1) { return(Identity().Transpose()); } var adj = new Matrix( columnIndices, rowIndices); // Calculate cofactors. for (var rowIndexIndex = 0; rowIndexIndex < rowIndices.Count; ++rowIndexIndex) { for (var columnIndexIndex = 0; columnIndexIndex < columnIndices.Count; ++columnIndexIndex) { var rowIndex = rowIndices[rowIndexIndex]; var columnIndex = columnIndices[columnIndexIndex]; var minorRowIndices = rowIndices.Where(index => index != rowIndex).ToList(); var minorColumnIndices = columnIndices.Where(index => index != columnIndex).ToList(); var cofactorValue = Det( minorRowIndices, minorColumnIndices); adj._elements[columnIndex][rowIndex] = (rowIndexIndex + columnIndexIndex) % 2 == 0 ? cofactorValue : -cofactorValue; } } return(adj); }
public IDataFrame GetSubsetByRows(IList <int> rowIndices, bool useRowNames = false) { var newTable = new DataTable(); foreach (DataColumn col in DataTable.Columns) { newTable.Columns.Add(new DataColumn(col.ColumnName, col.DataType)); } rowIndices = useRowNames ? RowNamesToRowIndices(rowIndices) : rowIndices; foreach (var rowIdx in rowIndices) { newTable.Rows.Add(DataTable.Rows[rowIdx].ItemArray); } return(new DataFrame(newTable, RowIndices.Where((rowName, rowIdx) => rowIndices.Contains(rowIdx)).ToList())); }
public override double[] GetRows() { return(RowIndices.Select(i => rows[i - 1]).ToArray()); // get aligned rows }
public Fraction Det() { return(Det( RowIndices.OrderBy(index => index).ToList(), ColumnIndices.OrderBy(index => index).ToList())); }
private int RowNameToIndex(int rowName) { return(RowIndices.IndexOf(rowName)); }