Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
Njust.Pdf.Analysis.V4.5
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陶然
Njust.Pdf.Analysis.V4.5
Commits
9993a834
Commit
9993a834
authored
Jun 18, 2021
by
陶然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
91845da6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
42 deletions
+44
-42
LDA.cs
LDA/LdaModel/LDA.cs
+1
-0
LDAGibbsSampling.cs
LDA/LdaModel/LDAGibbsSampling.cs
+14
-13
TopicSimilarityCos.cs
LDA/LdaModel/TopicSimilarityCos.cs
+25
-26
DisTopicEvolution.cs
Src/Entities/DisTopicEvolution.cs
+2
-2
RestfulAnalyse.cs
Src/Tranforms/RestfulAnalyse.cs
+2
-1
RestfulDisAnalyse.cs
Src/Tranforms/RestfulDisAnalyse.cs
+0
-0
No files found.
LDA/LdaModel/LDA.cs
View file @
9993a834
...
@@ -9,6 +9,7 @@ namespace LDA.LdaModel
...
@@ -9,6 +9,7 @@ namespace LDA.LdaModel
public
int
K
;
//#Topics
public
int
K
;
//#Topics
public
double
alpha
;
// Dirichlet Prior Parameter for Document->Topic
public
double
alpha
;
// Dirichlet Prior Parameter for Document->Topic
public
double
beta
;
// Dirichlet Prior Parameter for Topic->Word
public
double
beta
;
// Dirichlet Prior Parameter for Topic->Word
public
double
logLikelihood
;
public
double
LogLikelihood
public
double
LogLikelihood
{
{
get
get
...
...
LDA/LdaModel/LDAGibbsSampling.cs
View file @
9993a834
...
@@ -130,26 +130,27 @@ namespace LDA.LdaModel
...
@@ -130,26 +130,27 @@ namespace LDA.LdaModel
getLda
.
M
=
M
;
getLda
.
M
=
M
;
getLda
.
phi
=
phi
;
getLda
.
phi
=
phi
;
getLda
.
theta
=
theta
;
getLda
.
theta
=
theta
;
getLda
.
logLikelihood
=
LogLikelihood
;
return
getLda
;
return
getLda
;
}
}
public
void
PrintModelInfo
()
public
void
PrintModelInfo
()
{
{
Console
.
WriteLine
(
"Aplha: "
+
alpha
.
ToString
());
//
Console.WriteLine("Aplha: " + alpha.ToString());
Console
.
WriteLine
(
"Beta: "
+
beta
.
ToString
());
//
Console.WriteLine("Beta: " + beta.ToString());
Console
.
WriteLine
(
"M: "
+
M
);
//
Console.WriteLine("M: " + M);
Console
.
WriteLine
(
"K: "
+
K
);
//
Console.WriteLine("K: " + K);
Console
.
WriteLine
(
"V: "
+
V
);
//
Console.WriteLine("V: " + V);
Console
.
WriteLine
(
"Total iterations:"
+
niters
);
//
Console.WriteLine("Total iterations:" + niters);
Console
.
WriteLine
(
"Save at: "
+
savestep
);
//
Console.WriteLine("Save at: " + savestep);
Console
.
WriteLine
();
//
Console.WriteLine();
}
}
private
void
GibbsSampling
(
int
totalIter
)
private
void
GibbsSampling
(
int
totalIter
)
{
{
for
(
int
iter
=
1
;
iter
<=
totalIter
;
iter
++)
for
(
int
iter
=
1
;
iter
<=
totalIter
;
iter
++)
{
{
Console
.
Write
(
"Iteration "
+
iter
+
":"
);
//
Console.Write("Iteration " + iter + ":");
var
stopWatch
=
new
Stopwatch
();
var
stopWatch
=
new
Stopwatch
();
stopWatch
.
Start
();
stopWatch
.
Start
();
for
(
int
i
=
0
;
i
<
wn
;
i
++)
for
(
int
i
=
0
;
i
<
wn
;
i
++)
...
@@ -159,7 +160,7 @@ namespace LDA.LdaModel
...
@@ -159,7 +160,7 @@ namespace LDA.LdaModel
}
}
stopWatch
.
Stop
();
stopWatch
.
Stop
();
Console
.
WriteLine
(
stopWatch
.
ElapsedMilliseconds
/
1000.0
+
" seconds"
);
//
Console.WriteLine(stopWatch.ElapsedMilliseconds / 1000.0 + " seconds");
if
(
iter
%
savestep
==
0
)
if
(
iter
%
savestep
==
0
)
{
{
//保存参数、文档分布等
//保存参数、文档分布等
...
@@ -195,7 +196,7 @@ namespace LDA.LdaModel
...
@@ -195,7 +196,7 @@ namespace LDA.LdaModel
}
}
//主题编号
//主题编号
//sw.Write("Topic " + k + "th:\n");
//sw.Write("Topic " + k + "th:\n");
Console
.
WriteLine
(
"Topic "
+
k
+
"th:\n"
);
//
Console.WriteLine("Topic " + k + "th:\n");
//主题词
//主题词
var
wordsProbsListOrdered
=
wordsProbsList
.
OrderBy
(
e
=>
-
e
.
Value
).
ToList
();
var
wordsProbsListOrdered
=
wordsProbsList
.
OrderBy
(
e
=>
-
e
.
Value
).
ToList
();
...
@@ -203,11 +204,11 @@ namespace LDA.LdaModel
...
@@ -203,11 +204,11 @@ namespace LDA.LdaModel
{
{
string
word
=
cor
.
GetStringByID
(
wordsProbsListOrdered
[
i
].
Key
);
string
word
=
cor
.
GetStringByID
(
wordsProbsListOrdered
[
i
].
Key
);
// sw.WriteLine("\t" + word + " " + wordsProbsListOrdered[i].Value);
// sw.WriteLine("\t" + word + " " + wordsProbsListOrdered[i].Value);
Console
.
WriteLine
(
"\t"
+
word
+
" "
+
wordsProbsListOrdered
[
i
].
Value
);
//
Console.WriteLine("\t" + word + " " + wordsProbsListOrdered[i].Value);
}
}
}
}
Console
.
WriteLine
(
"LogLikelihood= "
+
LogLikelihood
);
//
Console.WriteLine("LogLikelihood= " + LogLikelihood);
}
}
}
}
}
}
...
...
LDA/LdaModel/TopicSimilarityCos.cs
View file @
9993a834
...
@@ -6,32 +6,32 @@ using System.Threading.Tasks;
...
@@ -6,32 +6,32 @@ using System.Threading.Tasks;
namespace
LDA.LdaModel
namespace
LDA.LdaModel
{
{
class
TopicSimilarityCos
public
static
class
TopicSimilarityCos
{
{
public
double
SimilarityCos
(
)
public
static
double
SimilarityCos
(
List
<
string
>
lstr1
,
List
<
string
>
lstr2
)
{
{
List
<
string
>
lstr1
=
new
List
<
string
>();
//
List<string> lstr1 = new List<string>();
lstr1
.
Add
(
"稀疏"
);
//
lstr1.Add("稀疏");
lstr1
.
Add
(
"信号"
);
//
lstr1.Add("信号");
lstr1
.
Add
(
"算法"
);
//
lstr1.Add("算法");
lstr1
.
Add
(
"方法"
);
//
lstr1.Add("方法");
lstr1
.
Add
(
"轴承"
);
//
lstr1.Add("轴承");
lstr1
.
Add
(
"故障"
);
//
lstr1.Add("故障");
lstr1
.
Add
(
"贝叶斯"
);
//
lstr1.Add("贝叶斯");
lstr1
.
Add
(
"模型"
);
//
lstr1.Add("模型");
lstr1
.
Add
(
"发动机"
);
//
lstr1.Add("发动机");
lstr1
.
Add
(
"降低"
);
//
lstr1.Add("降低");
List
<
string
>
lstr2
=
new
List
<
string
>();
//
List<string> lstr2 = new List<string>();
lstr2
.
Add
(
"测量"
);
//
lstr2.Add("测量");
lstr2
.
Add
(
"发动机"
);
//
lstr2.Add("发动机");
lstr2
.
Add
(
"叶尖"
);
//
lstr2.Add("叶尖");
lstr2
.
Add
(
"间隙"
);
//
lstr2.Add("间隙");
lstr2
.
Add
(
"性能"
);
//
lstr2.Add("性能");
lstr2
.
Add
(
"控制"
);
//
lstr2.Add("控制");
lstr2
.
Add
(
"微波"
);
//
lstr2.Add("微波");
lstr2
.
Add
(
"叶片"
);
//
lstr2.Add("叶片");
lstr2
.
Add
(
"降低"
);
//
lstr2.Add("降低");
lstr2
.
Add
(
"自主"
);
//
lstr2.Add("自主");
//求并集
//求并集
var
strUnion
=
lstr1
.
Union
(
lstr2
);
var
strUnion
=
lstr1
.
Union
(
lstr2
);
...
@@ -58,8 +58,7 @@ namespace LDA.LdaModel
...
@@ -58,8 +58,7 @@ namespace LDA.LdaModel
//求分母(2)
//求分母(2)
den2
+=
Math
.
Pow
(
int2
[
i
],
2
);
den2
+=
Math
.
Pow
(
int2
[
i
],
2
);
}
}
double
cos
=
s
/
(
Math
.
Sqrt
(
den1
)
*
Math
.
Sqrt
(
den2
));
//Console.WriteLine(cos);
Console
.
WriteLine
(
cos
);
return
s
/
(
Math
.
Sqrt
(
den1
)
*
Math
.
Sqrt
(
den2
));
return
s
/
(
Math
.
Sqrt
(
den1
)
*
Math
.
Sqrt
(
den2
));
}
}
}
}
...
...
Src/Entities/DisTopicEvolution.cs
View file @
9993a834
...
@@ -28,7 +28,7 @@ namespace Njust.Pdf.Analysis.Entities
...
@@ -28,7 +28,7 @@ namespace Njust.Pdf.Analysis.Entities
public
string
SourceTopic
{
get
;
set
;
}
public
string
SourceTopic
{
get
;
set
;
}
[
ApiMember
(
Description
=
"目标主题编号"
)]
[
ApiMember
(
Description
=
"目标主题编号"
)]
public
string
TargeTopic
{
get
;
set
;
}
public
string
Targe
t
Topic
{
get
;
set
;
}
[
ApiMember
(
Description
=
"源主题词"
)]
[
ApiMember
(
Description
=
"源主题词"
)]
public
string
SourceTopicWord
{
get
;
set
;
}
public
string
SourceTopicWord
{
get
;
set
;
}
...
@@ -37,6 +37,6 @@ namespace Njust.Pdf.Analysis.Entities
...
@@ -37,6 +37,6 @@ namespace Njust.Pdf.Analysis.Entities
public
string
TargetTopicWord
{
get
;
set
;
}
public
string
TargetTopicWord
{
get
;
set
;
}
[
ApiMember
(
Description
=
"余弦相似度"
)]
[
ApiMember
(
Description
=
"余弦相似度"
)]
public
string
CosSim
{
get
;
set
;
}
public
double
CosSim
{
get
;
set
;
}
}
}
}
}
Src/Tranforms/RestfulAnalyse.cs
View file @
9993a834
...
@@ -116,9 +116,11 @@ namespace Njust.Pdf.Analysis.Tranforms
...
@@ -116,9 +116,11 @@ namespace Njust.Pdf.Analysis.Tranforms
foreach
(
var
item
in
preInserts
)
foreach
(
var
item
in
preInserts
)
{
{
var
stream
=
files
[
item
.
HashCode
];
var
exist
=
exists
.
FirstOrDefault
(
o
=>
o
.
HashCode
==
item
.
HashCode
);
var
exist
=
exists
.
FirstOrDefault
(
o
=>
o
.
HashCode
==
item
.
HashCode
);
if
(
exist
!=
null
)
if
(
exist
!=
null
)
{
{
KiviiContext
.
VirtualFiles
.
WriteFile
(
exist
.
ImportPath
,
stream
);
rtns
.
Results
.
Add
(
exist
);
rtns
.
Results
.
Add
(
exist
);
continue
;
continue
;
}
}
...
@@ -126,7 +128,6 @@ namespace Njust.Pdf.Analysis.Tranforms
...
@@ -126,7 +128,6 @@ namespace Njust.Pdf.Analysis.Tranforms
conn
.
Insert
(
item
);
conn
.
Insert
(
item
);
item
.
RemoveAllOnlyProperties
();
item
.
RemoveAllOnlyProperties
();
rtns
.
Results
.
Add
(
item
);
rtns
.
Results
.
Add
(
item
);
var
stream
=
files
[
item
.
HashCode
];
stream
.
Position
=
0
;
stream
.
Position
=
0
;
KiviiContext
.
VirtualFiles
.
WriteFile
(
item
.
ImportPath
,
stream
);
KiviiContext
.
VirtualFiles
.
WriteFile
(
item
.
ImportPath
,
stream
);
...
...
Src/Tranforms/RestfulDisAnalyse.cs
View file @
9993a834
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment