-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSVD.cpp
More file actions
132 lines (115 loc) · 3.19 KB
/
SVD.cpp
File metadata and controls
132 lines (115 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// SVD.cpp: implementation of the CSVD class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ARS.h"
#include "SVD.h"
#include "IR.h"
#include "KeyWord.h"
#include "ARSDocument.h"
#include "IndexTermsInDoc.h"
#include "FilePrepare.h"
#include "DBManpulation.h"
#include "Indexer.h"
#include "fstream.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
mwArray CSVD::m_V;
mwArray CSVD::m_U;
mwArray CSVD::m_S;
//////////////////////////////////////////////////////////////////////
extern CARSDocument ArabicDocs;
extern CIndexer ARSIndexer;
//////////////////////////////////////////////////////////////////////
CSVD::CSVD()
{
}
CSVD::CSVD(int MaxVal)
{
nMaxFactors = MaxVal;
}
CSVD::~CSVD()
{
}
BOOL CSVD::DoIndexing(CStringList *DocPathList)
{
BOOL bState = TRUE;
ConstructDocBase(DocPathList);
// ArabicDocs.PrepareDocument( DocPathList );
mwArray A = ARSIndexer.GetTermDocMat();
A = sparse(A);
save("C:\\My Documents\\my corpus\\economic\\A.mat", "A", A);
/**/ //save("C:\\My Documents\\test10\\A10.mat", "A10", A);
CalculateSVD(A);
WriteSVD();
return bState;
}
int CSVD::GetMaxFactors()
{
return nMaxFactors;
}
void CSVD::SetMaxFactors(int MaxVal)
{
nMaxFactors = MaxVal;
}
BOOL CSVD::CalculateSVD(mwArray &A)
{
m_U = svds(&m_S, &m_V, A, nMaxFactors);
return TRUE;
}
BOOL CSVD::WriteSVD()
{
/**/ try
{ // Save (and name) the SVD components U,V,S.
save("C:\\My Documents\\my corpus\\economic\\U.mat", "U", m_U);
save("C:\\My Documents\\my corpus\\economic\\V.mat", "V", m_V);
save("C:\\My Documents\\my corpus\\economic\\S.mat", "S", m_S);
// save("C:\\My Documents\\test10\\U10.mat", "U10", m_U);
// save("C:\\My Documents\\test10\\V10.mat", "V10", m_V);
// save("C:\\My Documents\\test10\\S10.mat", "S10", m_S);
}
catch ( mwException &ex )
{ ////////out file for exploring the write error ...///
AfxMessageBox("FAIL WITH saving U, V, S");
ofstream out_file("_writerr.txt", ios::out);
out_file << ex << ends;
out_file.close();
/////////////////////////////////////////////// .............///
AfxMessageBox("FAIL WITH writing U file,V file, S file ");
return FALSE;
}
////////////out file for exploring the U ...///
/* ofstream out_file("_U.txt", ios::out);
out_file << m_U << ends;
out_file.close();
/////////////////////////////////////////////////// .............///*/
return TRUE;
}
mwArray& CSVD::GetV()
{
load("C:\\My Documents\\my corpus\\economic\\V.mat", "V", &m_V);
return m_V;
}
mwArray& CSVD::GetU()
{
load("C:\\My Documents\\my corpus\\economic\\U.mat", "U", &m_U);
return m_U;
}
mwArray& CSVD::GetS()
{
load("C:\\My Documents\\my corpus\\economic\\S.mat", "S", &m_S);
return m_S;
}
BOOL CSVD::ConstructDocBase(CStringList *DocPathList)
{
BOOL bState = TRUE;
CARSDocument DocBase;
DocBase.PrepareDocument( DocPathList );
return bState;
}