| … Ctrl-o … | … 次のバッファに移動する … |
| … Ctrl-x o … | … 次のバッファに移動する … |
| \({\boldsymbol x}\) あるいは \({\boldsymbol \mu}\) | \({\boldsymbol x}-{\boldsymbol \mu}\) | \(\|{\boldsymbol x}-{\boldsymbol \mu}\|^2\) | |
|---|---|---|---|
| 札幌市 | \((0.0, 0.0)\) | \((-12.8, 7.3)\) | \(12.8^2+7.3^2\) |
| 千歳市 | \((23.8,-26.4)\) | \((11.0,-19.1)\) | \(11.0^2+19.1^2\) |
| 江別市 | \((14.6, 4.6)\) | \((1.8, 11.9)\) | \(1.8^2+11.9^2\) |
| 重心\({\boldsymbol \mu}\) | \((12.8,-7.3)\) |
readTrpreadTrpCrpを生成・・」は,
「実行ファイルreadTrp, readTrpCrsを生成・・」のタイポです.
は,第2項の負号が1つ余計で,正しくは,
\[ J\!S_W = \frac{1}{N}\sum_{k=1}^K N_k \sum_{m=1}^M -q_m^k \log q_m^k
-\left(\frac{1}{N}\sum_{i=1}^N \sum_{m=1}^M -p_m^i \log p_m^i \right),\]
です.
は,クラスタ毎に同時確率を計算すべきで,正しくは,
\[
\prod_{k=1}^K \prod_{{\boldsymbol x}^i \in C^k} A^i \prod_{m=1}^M (q_m^k)^{x^i_m},
\]
です.
`」を使います).
prac32.shの1行目について,
訂正前:「for seed in {0..999}」から,訂正後:「for seed in `seq 0 999`」へclustering100.shの2行目について,
訂正前:「for seed in {0..99}」から,訂正後:「for seed in `seq 0 99`」へwork1.shの1行目について,
訂正前:「for seed in {0..29}」から,訂正後:「for seed in `seq 0 29`」へ
例えば,空の文書を含む文書データ(3つ組)20ngNoS.datと
クラスラベル情報20ng.labelがある場合,下記
reallocateDocId.cppを
g++ -std=c++11 -O3 -I/usr/include/eigen3 reallocateDocId.cpp -o reallocateDocIdのようにしてコンパイルし,変更後の文書データの出力先を
20ngNoSid.dat,クラスラベル情報の出力先を
20ngNoSid.labelとする場合,
./reallocateDocId 20ngNoS.dat 20ng.label 20ngNoSid.label > 20ngNoSid.datのようにすれば,クラスラベル情報の修正も含めて空の文書 のidの除去ができます.
//reallocateDocId.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <sstream>
#include <Eigen/Dense>
#include <Eigen/Sparse>
using namespace Eigen;
using namespace std;
int main(int argc, char* argv[]){
string fname = argv[1]; // 文書疎行列(3つ組)ファイル
string fnameC = argv[2]; //(クラスラベル)ファイル入力
string fnameC2 = argv[3]; //(クラスラベル)ファイル出力
int nRows = 0, nCols = 0; // 行数(ndim)と列数(文書数)を表す変数の宣言
int row, col;
double val;
string buf;
set<int> validDocIds; // 0始まり.有効な文書idの集合
typedef Triplet<double> T;
vector<T> triplets;
ifstream ifile( fname );
while( getline(ifile,buf) ){
istringstream iss(buf);
iss >> row >> col >> val;
triplets.emplace_back(T(row-1,col-1,val));
if( row > nRows ) nRows = row;
if( col > nCols ) nCols = col;
validDocIds.insert(col-1); // 文書idを有効な文書id集合に追加
}
ifile.close();
int ndim = nRows; // 行数は,単語種類数(特徴の次元数ndim=M)を表す
int nvec = nCols; // 列数は,文書数nvec=Nを表す
SparseMatrix<double> spX(ndim,nvec);
spX.setFromTriplets(triplets.begin(), triplets.end());
ifstream ifileC( fnameC );
vector<int> vecC;
while( getline(ifileC,buf) ) vecC.emplace_back(stoi(buf)-1);
ifileC.close();
int Did = 0;
ofstream ofileClass( fnameC2 );
for( int i = 0 ; i < nvec ; i++ ){ // すべての文書idについて
if( validDocIds.find(i) != validDocIds.end() ){ // 空文書でない有効idなら
ofileClass << vecC[i]+1 << endl;
for(SparseMatrix<double>::InnerIterator it(spX,i);it; ++it)
cout << it.row()+1 << " " << Did+1 << " " << it.value() << endl;
Did++;
}
}
}