org.mklab.nfc.matrix
クラス BooleanMatrixUtil

java.lang.Object
  上位を拡張 org.mklab.nfc.matrix.BooleanMatrixUtil

public final class BooleanMatrixUtil
extends Object

BooleanMatrixのユーティリティクラスです。

バージョン:
$Revision: 1.53 $
作成者:
koga

メソッドの概要
static boolean allTrue(boolean[][] matrix)
          全成分を調べ、全成分がtrueならtrue、そうでなければfalseを返します。
static boolean[] allTrueColumnWise(boolean[][] matrix)
          成分を列毎に調べ、列の全成分がtrueならtrue、そうでなければfalseを対応させ、行毎のbooleanからなる boolean行列を返します。
static boolean[][] allTrueRowWise(boolean[][] matrix)
          成分を行毎に調べ、行の全成分がtrueならtrue、そうでなければfalseを対応させ、 行毎のbooleanからなるboolean行列を返します。
static boolean[][] andElementWise(boolean[][] matrix, boolean scalar)
          行列の各成分とscalarの論理積を成分にもつboolean行列を返します。
static boolean[][] andElementWise(boolean[][] a1, boolean[][] a2)
          a1a2の各成分の論理積を成分にもつboolean行列を返します。
static boolean anyTrue(boolean[][] matrix)
          全成分を調べtrueが1個でもあればtrue、そうでなければfalseを返します。
static boolean[] anyTrueColumnWise(boolean[][] matrix)
          列毎の成分を調べ、行にtrueが1個でもあればtrue、そうでなければfalseを対応させ、 booleanを含むboolean行列を返します。
static boolean[][] anyTrueRowWise(boolean[][] matrix)
          行毎の成分を調べ、行にtrueが1個でもあればtrue、そうでなければfalseを対応させ、 booleanを含むboolean行列を返します。
static boolean[][] appendDown(boolean[][] a1, boolean[][] a2)
          2個の行列を縦に接続した行列を生成します。
static boolean[][] appendRight(boolean[][] a1, boolean[][] a2)
          ベクトルの右側に行列を接続した行列を生成します。
static boolean[][] clone(boolean[][] matrix)
          行列の複製を生成します。
static boolean[][] compareElements(boolean[][] a1, String operator, boolean[][] a2)
          2個の行列を成分毎にoperatorで指定された演算子で比較し, 計算結果を成分とする行列を生成します。
static void copy(boolean[][] source, boolean[][] destination)
          行列sourceの各成分を行列destinationの各成分にコピーします。
static boolean[] diagonalToVector(boolean[][] matrix)
          対角成分を取り出し縦ベクトルとして返します。
static boolean equals(boolean[][] a1, boolean[][] a2)
          2個の配列の成分が全て等しいか判定します。
static void exchangeColumn(boolean[][] matrix, int column1, int column2)
          column1列とcolumn2列を入れ替えます。
static void exchangeRow(boolean[][] matrix, int row1, int row2)
          row1行とrow2行を入れ替えます。
static boolean[][] exorElementWise(boolean[][] matrix, boolean scalar)
          行列の各成分とscalarの排他的論理和を成分にもつboolean行列を返します。
static boolean[][] exorElementWise(boolean[][] a1, boolean[][] a2)
          2個の行列の各成分の排他的論理和を成分にもつboolean行列を返します。
static int[] find(boolean[][] matrix)
          各成分を調べ、trueの位置を順にも整数ベクトルを返します。
static int getNumberOfTrue(boolean[][] matrix)
          成分のtrueの数を返します。
static boolean[][] getSubMatrix(boolean[][] matrix, int[] rowIndex, int column)
          部分行列を生成します。
static boolean[][] getSubMatrix(boolean[][] matrix, int[] rowIndex, int[] columnIndex)
          部分行列を生成します。
static boolean[][] getSubMatrix(boolean[][] matrix, int[] rowIndex, int columnMin, int columnMax)
          部分行列を生成します。
static boolean[][] getSubMatrix(boolean[][] matrix, int row, int[] columnIndex)
          部分行列を生成します。
static boolean[][] getSubMatrix(boolean[][] matrix, int rowMin, int rowMax, int[] columnIndex)
          部分行列を生成します。
static boolean[][] getSubMatrix(boolean[][] matrix, int rowMin, int rowMax, int columnMin, int columnMax)
          部分行列を生成します。
static boolean[] getSubVector(boolean[] matrix, int[] index)
          部分ベクトルを生成します。
static boolean isZero(boolean[][] matrix)
          零行列(全ての成分がfalse)であるか判定します。
static boolean[][] multiply(boolean[][] a1, boolean[][] a2)
          2個の行列の積(成分毎の論理積)を求めます。
static boolean[][] notElementWise(boolean[][] matrix)
          各成分の否定(trueならfalse、falseならtrue)を成分にもつboolean行列を返します。
static boolean[][] ones(int rowSize, int columnSize)
          rowSize*columnSizeの全成分trueの行列を生成します。
static boolean[][] orElementWise(boolean[][] matrix, boolean scalar)
          行列の各成分とscalarの論理和を成分にもつboolean行列を返します。
static boolean[][] orElementWise(boolean[][] a1, boolean[][] a2)
          2個の行列の各成分の論理和を成分にもつboolean行列を返します。
static boolean[][] power(boolean[][] matrix, int scalar)
          scalar乗(this scalar)を返します。
static void print(boolean[][] matrix, Writer output, String format, int maxColumnSize)
          ライターに出力します。
static boolean[][] readMxFormat(DataInputStream input, MxDataHead head)
          データ入力ストリームから行列データ(MXフォーマット)を読み込みます。
static boolean[][] removeColumnVectors(boolean[][] matrix, int[] index)
          指定された列を削除した行列を生成します。
static boolean[][] removeColumnVectors(boolean[][] matrix, int min, int max)
          指定された列を削除した行列を生成します。
static boolean[][] removeRowVectors(boolean[][] matrix, int[] index)
          指定された行を削除した行列を生成します。
static boolean[][] removeRowVectors(boolean[][] matrix, int min, int max)
          指定された行を削除した行列を生成します。
static boolean[][] reshape(boolean[][] matrix, int newRowSize, int newColumnSize)
          行列の成分を変えずに、行列の大きさ(行の数と列の数)を変形します。
static boolean[][] resize(boolean[][] matrix, int newRowSize, int newColumnSize)
          newRowSize*newColumnSizeにサイズ変更します。
static void setElements(boolean[][] destination, int[] index, boolean[][] source)
           
static void setSubMatrix(boolean[][] destination, int[] rowIndex, int[] columnIndex, boolean[][] source)
           
static void setSubMatrix(boolean[][] destination, int[] rowIndex, int columnMin, int columnMax, boolean[][] source)
           
static void setSubMatrix(boolean[][] destination, int rowTo, int columnTo, boolean[][] source, int rowMin, int rowMax, int columnMin, int columnMax)
          配列destinationrowTocolumnTo列を始点として、 配列sourcerowMincolumnMin列から rowMaxcolumnMax列までの値をコピーします。
static void setSubMatrix(boolean[][] destination, int rowMin, int rowMax, int[] columnIndex, boolean[][] source)
           
static void setZero(boolean[][] matrix)
          行列の全ての成分に零(false)を代入します。
static String toMmString(boolean[][] matrix)
          行列をMMフォーマットの文字列に変換します。
static boolean[][] transpose(boolean[][] matrix)
          転置行列を生成します。
static boolean[][] unit(int rowSize, int columnSize)
          単位行列を生成します。
static boolean[][] vectorToDiagonal(boolean[] diagonalElements)
          ベクトルの成分を対角成分とする対角行列を生成します。
static void writeMxFormat(boolean[][] matrix, OutputStream output, String name)
          行列を出力ストリームにMXフォーマットで出力します。
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

メソッドの詳細

clone

public static final boolean[][] clone(boolean[][] matrix)
行列の複製を生成します。

パラメータ:
matrix - 複製の元となる行列
戻り値:
複製された行列

exchangeColumn

public static final void exchangeColumn(boolean[][] matrix,
                                        int column1,
                                        int column2)
column1列とcolumn2列を入れ替えます。

パラメータ:
matrix - 対象の行列
column1 - 指定列1
column2 - 指定列2

exchangeRow

public static final void exchangeRow(boolean[][] matrix,
                                     int row1,
                                     int row2)
row1行とrow2行を入れ替えます。

パラメータ:
matrix - 対象の行列
row1 - 指定行1
row2 - 指定行2

resize

public static final boolean[][] resize(boolean[][] matrix,
                                       int newRowSize,
                                       int newColumnSize)
newRowSize*newColumnSizeにサイズ変更します。

reshape(boolean[][], int, int)とは異なり、成分位置の変更はせず、自身より大きなサイズに変更する時は、 0が埋められ、自身より小さなサイズに変更する時は余分な成分は切り取られます。

パラメータ:
matrix - 対象となる行列
newRowSize - 新しい行の数
newColumnSize - 新しいレスう
戻り値:
サイズ変更後の行列

removeColumnVectors

public static boolean[][] removeColumnVectors(boolean[][] matrix,
                                              int min,
                                              int max)
指定された列を削除した行列を生成します。

パラメータ:
matrix - 対象となる行列
min - 開始列
max - 終了列
戻り値:
列を削除された行列

removeColumnVectors

public static boolean[][] removeColumnVectors(boolean[][] matrix,
                                              int[] index)
指定された列を削除した行列を生成します。

パラメータ:
matrix - 元の行列
index - 削除する列の番号
戻り値:
列を削除された行列

removeRowVectors

public static boolean[][] removeRowVectors(boolean[][] matrix,
                                           int min,
                                           int max)
指定された行を削除した行列を生成します。

パラメータ:
matrix - 対象となる行列
min - 開始行
max - 終了行
戻り値:
行を削除された行列

removeRowVectors

public static boolean[][] removeRowVectors(boolean[][] matrix,
                                           int[] index)
指定された行を削除した行列を生成します。

パラメータ:
matrix - 元の行列
index - 削除する行の番号
戻り値:
行を削除された行列

getSubMatrix

public static final boolean[][] getSubMatrix(boolean[][] matrix,
                                             int rowMin,
                                             int rowMax,
                                             int[] columnIndex)
部分行列を生成します。

パラメータ:
matrix - 元の行列
rowMin - 始まりの行
rowMax - 終わりの行
columnIndex - 該当する列の番号
戻り値:
部分行列

getSubMatrix

public static final boolean[][] getSubMatrix(boolean[][] matrix,
                                             int[] rowIndex,
                                             int[] columnIndex)
部分行列を生成します。

パラメータ:
matrix - 元の行列
rowIndex - 該当する行の番号
columnIndex - 該当する列の番号
戻り値:
部分行列

getSubMatrix

public static final boolean[][] getSubMatrix(boolean[][] matrix,
                                             int[] rowIndex,
                                             int columnMin,
                                             int columnMax)
部分行列を生成します。

パラメータ:
matrix - 元の行列
rowIndex - 該当する行の番号
columnMin - 始まりの列
columnMax - 終わりの列
戻り値:
部分行列

getSubMatrix

public static final boolean[][] getSubMatrix(boolean[][] matrix,
                                             int[] rowIndex,
                                             int column)
部分行列を生成します。

パラメータ:
matrix - 元の行列
rowIndex - 該当する行の番号
column - 列番号
戻り値:
部分行列

getSubMatrix

public static final boolean[][] getSubMatrix(boolean[][] matrix,
                                             int row,
                                             int[] columnIndex)
部分行列を生成します。

パラメータ:
matrix - 元の行列
row - 行の番号
columnIndex - 該当する列の番号
戻り値:
部分行列

getSubVector

public static final boolean[] getSubVector(boolean[] matrix,
                                           int[] index)
部分ベクトルを生成します。

パラメータ:
matrix - 元のベクトル
index - 該当する行の番号
戻り値:
部分ベクトル

toMmString

public static final String toMmString(boolean[][] matrix)
行列をMMフォーマットの文字列に変換します。

パラメータ:
matrix - 対象となる行列
戻り値:
MMフォーマットの文字列

copy

public static void copy(boolean[][] source,
                        boolean[][] destination)
行列sourceの各成分を行列destinationの各成分にコピーします。

パラメータ:
source - コピー元行列
destination - コピー先行列

anyTrue

public static boolean anyTrue(boolean[][] matrix)
全成分を調べtrueが1個でもあればtrue、そうでなければfalseを返します。

パラメータ:
matrix - 対象となる行列
戻り値:
全成分を調べtrueが1個でもあればtrue、そうでなければfalse

anyTrueRowWise

public static boolean[][] anyTrueRowWise(boolean[][] matrix)
行毎の成分を調べ、行にtrueが1個でもあればtrue、そうでなければfalseを対応させ、 booleanを含むboolean行列を返します。

パラメータ:
matrix - 対象となる行列
戻り値:
調査の結果を成分とするboolean行列

anyTrueColumnWise

public static boolean[] anyTrueColumnWise(boolean[][] matrix)
列毎の成分を調べ、行にtrueが1個でもあればtrue、そうでなければfalseを対応させ、 booleanを含むboolean行列を返します。

パラメータ:
matrix - 対象となる行列
戻り値:
調査の結果を成分とするboolean行列

allTrue

public static boolean allTrue(boolean[][] matrix)
全成分を調べ、全成分がtrueならtrue、そうでなければfalseを返します。

パラメータ:
matrix - 対象となる行列
戻り値:
調査の結果

allTrueRowWise

public static boolean[][] allTrueRowWise(boolean[][] matrix)
成分を行毎に調べ、行の全成分がtrueならtrue、そうでなければfalseを対応させ、 行毎のbooleanからなるboolean行列を返します。

パラメータ:
matrix - 対象となる行列
戻り値:
調査の結果を成分とするboolean行列

allTrueColumnWise

public static boolean[] allTrueColumnWise(boolean[][] matrix)
成分を列毎に調べ、列の全成分がtrueならtrue、そうでなければfalseを対応させ、行毎のbooleanからなる boolean行列を返します。

パラメータ:
matrix - 対象となる行列
戻り値:
調査の結果を成分とするboolean行列

notElementWise

public static boolean[][] notElementWise(boolean[][] matrix)
各成分の否定(trueならfalse、falseならtrue)を成分にもつboolean行列を返します。

パラメータ:
matrix - 対象となる行列
戻り値:
調査の結果を成分とするboolean行列

andElementWise

public static boolean[][] andElementWise(boolean[][] a1,
                                         boolean[][] a2)
a1a2の各成分の論理積を成分にもつboolean行列を返します。

パラメータ:
a1 - 演算の対象
a2 - 演算の対象
戻り値:
演算の結果を成分とするboolean行列

multiply

public static boolean[][] multiply(boolean[][] a1,
                                   boolean[][] a2)
2個の行列の積(成分毎の論理積)を求めます。

パラメータ:
a1 - 掛けられる行列
a2 - 掛ける行列
戻り値:
積(成分毎の論理積)

andElementWise

public static boolean[][] andElementWise(boolean[][] matrix,
                                         boolean scalar)
行列の各成分とscalarの論理積を成分にもつboolean行列を返します。

パラメータ:
matrix - 対象となる行列
scalar - 対象となるboolean値
戻り値:
演算の結果を成分とするboolean行列

orElementWise

public static boolean[][] orElementWise(boolean[][] a1,
                                        boolean[][] a2)
2個の行列の各成分の論理和を成分にもつboolean行列を返します。

パラメータ:
a1 - 対象となる行列
a2 - 対象となる行列
戻り値:
演算の結果を成分とするboolean行列

orElementWise

public static boolean[][] orElementWise(boolean[][] matrix,
                                        boolean scalar)
行列の各成分とscalarの論理和を成分にもつboolean行列を返します。

パラメータ:
matrix - 対象となる行列
scalar - 全ての演算に用いるboolean
戻り値:
演算の結果を成分とするboolean行列

exorElementWise

public static boolean[][] exorElementWise(boolean[][] a1,
                                          boolean[][] a2)
2個の行列の各成分の排他的論理和を成分にもつboolean行列を返します。

パラメータ:
a1 - 対象となる行列
a2 - 対象となる行列
戻り値:
演算の結果を成分とするboolean行列

exorElementWise

public static boolean[][] exorElementWise(boolean[][] matrix,
                                          boolean scalar)
行列の各成分とscalarの排他的論理和を成分にもつboolean行列を返します。

パラメータ:
matrix - 対象となる行列
scalar - 全ての演算に用いるboolean
戻り値:
演算の結果を成分とするboolean行列

print

public static void print(boolean[][] matrix,
                         Writer output,
                         String format,
                         int maxColumnSize)
ライターに出力します。

パラメータ:
matrix - 対象となる行列
output - ライター
format - 成分の出力フォーマット
maxColumnSize - 最大列の数

reshape

public static boolean[][] reshape(boolean[][] matrix,
                                  int newRowSize,
                                  int newColumnSize)
行列の成分を変えずに、行列の大きさ(行の数と列の数)を変形します。

パラメータ:
matrix - 対象となる行列
newRowSize - 変更後の行の数
newColumnSize - 変更後の列の数
戻り値:
変形した行列

getNumberOfTrue

public static int getNumberOfTrue(boolean[][] matrix)
成分のtrueの数を返します。

パラメータ:
matrix - booleanをもつ配列
戻り値:
trueの数

find

public static int[] find(boolean[][] matrix)
各成分を調べ、trueの位置を順にも整数ベクトルを返します。

パラメータ:
matrix - booleanをもつ配列
戻り値:
trueの位置を順にもつ整数ベクトル

power

public static boolean[][] power(boolean[][] matrix,
                                int scalar)
scalar乗(this scalar)を返します。

パラメータ:
matrix - 対象となる行列
scalar - 指数
戻り値:
num乗

unit

public static boolean[][] unit(int rowSize,
                               int columnSize)
単位行列を生成します。

パラメータ:
rowSize - 行の数
columnSize - 列の数
戻り値:
単位行列

ones

public static boolean[][] ones(int rowSize,
                               int columnSize)
rowSize*columnSizeの全成分trueの行列を生成します。

パラメータ:
rowSize - 行の数
columnSize - 列の数
戻り値:
全ての成分が1である行列

vectorToDiagonal

public static boolean[][] vectorToDiagonal(boolean[] diagonalElements)
ベクトルの成分を対角成分とする対角行列を生成します。

パラメータ:
diagonalElements - 対象となるベクトル
戻り値:
対角行列

writeMxFormat

public static void writeMxFormat(boolean[][] matrix,
                                 OutputStream output,
                                 String name)
                          throws IOException
行列を出力ストリームにMXフォーマットで出力します。

パラメータ:
matrix - 対象となる行列
output - 出力ストリーム
name - 行列の名前
例外:
IOException - ストリームに出力できない場合

readMxFormat

public static boolean[][] readMxFormat(DataInputStream input,
                                       MxDataHead head)
                                throws IOException
データ入力ストリームから行列データ(MXフォーマット)を読み込みます。

パラメータ:
input - データ入力ストリーム
head - MXフォーマットのヘッダ情報
戻り値:
読み込んだ行列
例外:
IOException - ストリームに出力できない場合

equals

public static boolean equals(boolean[][] a1,
                             boolean[][] a2)
2個の配列の成分が全て等しいか判定します。

パラメータ:
a1 - 第一行列
a2 - 第二行列
戻り値:
配列の成分が等しければtrue、そうでなければfalse

transpose

public static boolean[][] transpose(boolean[][] matrix)
転置行列を生成します。

パラメータ:
matrix - 元の行列
戻り値:
転置行列

getSubMatrix

public static boolean[][] getSubMatrix(boolean[][] matrix,
                                       int rowMin,
                                       int rowMax,
                                       int columnMin,
                                       int columnMax)
部分行列を生成します。

パラメータ:
matrix - 元の行列
rowMin - 始まり行
rowMax - 終わり行
columnMin - 始まり列
columnMax - 終わり列
戻り値:
部分行列

diagonalToVector

public static boolean[] diagonalToVector(boolean[][] matrix)
対角成分を取り出し縦ベクトルとして返します。

パラメータ:
matrix - 対象となる行列
戻り値:
対角成分からなる縦ベクトル

setSubMatrix

public static void setSubMatrix(boolean[][] destination,
                                int rowTo,
                                int columnTo,
                                boolean[][] source,
                                int rowMin,
                                int rowMax,
                                int columnMin,
                                int columnMax)
配列destinationrowTocolumnTo列を始点として、 配列sourcerowMincolumnMin列から rowMaxcolumnMax列までの値をコピーします。

パラメータ:
destination - コピー先
rowTo - 変更開始行
columnTo - 変更開始列
source - コピー元
rowMin - コピー開始行
rowMax - コピー開始列
columnMin - コピー終了行
columnMax - コピー終了列

setSubMatrix

public static void setSubMatrix(boolean[][] destination,
                                int[] rowIndex,
                                int columnMin,
                                int columnMax,
                                boolean[][] source)
パラメータ:
destination - 値を設定する行列
rowIndex - 指定する行を含む指数
columnMin - 列の始まり
columnMax - 列の終り
source - 代入する行列

setSubMatrix

public static void setSubMatrix(boolean[][] destination,
                                int rowMin,
                                int rowMax,
                                int[] columnIndex,
                                boolean[][] source)
パラメータ:
destination - 値を設定する行列
rowMin - 行の始まり
rowMax - 行の終り
columnIndex - 指定する列を含む指数
source - 代入する行列

setSubMatrix

public static void setSubMatrix(boolean[][] destination,
                                int[] rowIndex,
                                int[] columnIndex,
                                boolean[][] source)
パラメータ:
destination - 値を設定する行列
rowIndex - 指定する行を含む指数
columnIndex - 指定する列を含む指数
source - 代入する行列

setElements

public static void setElements(boolean[][] destination,
                               int[] index,
                               boolean[][] source)
パラメータ:
destination - 成分を代入する行列
index - 成分の番号を指定する指数
source - 代入するベクトル

appendDown

public static boolean[][] appendDown(boolean[][] a1,
                                     boolean[][] a2)
2個の行列を縦に接続した行列を生成します。

パラメータ:
a1 - 上側の行列
a2 - 下側の行列
戻り値:
接続された行列

appendRight

public static boolean[][] appendRight(boolean[][] a1,
                                      boolean[][] a2)
ベクトルの右側に行列を接続した行列を生成します。

パラメータ:
a1 - 左側のベクトル
a2 - 右側の行列
戻り値:
接続された行列

compareElements

public static final boolean[][] compareElements(boolean[][] a1,
                                                String operator,
                                                boolean[][] a2)
2個の行列を成分毎にoperatorで指定された演算子で比較し, 計算結果を成分とする行列を生成します。

パラメータ:
a1 - 第一行列
operator - 比較演算子(".==", ".!=")
a2 - 第二行列
戻り値:
計算結果を成分とする行列

isZero

public static final boolean isZero(boolean[][] matrix)
零行列(全ての成分がfalse)であるか判定します。

パラメータ:
matrix - 調べる行列
戻り値:
零行列(全ての成分がfalse)ならtrue、そうでなければfalse

setZero

public static final void setZero(boolean[][] matrix)
行列の全ての成分に零(false)を代入します。

パラメータ:
matrix - 零(false)を代入する行列