-
Notifications
You must be signed in to change notification settings - Fork 1
/
LDADE.py
110 lines (89 loc) · 3.57 KB
/
LDADE.py
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
from __future__ import print_function, division
__author__ = 'amrit'
import sys
# import np as np
sys.dont_write_bytecode = True
from ldaScore import *
from DE import DE
from collections import OrderedDict
class BaseConfig:
"""
This is the basic version of user config class
Providing all the Basic Util inside this class
NO EXTRA DATA CONFIG INSIDE
"""
def __init__(self):
pass
def __getitem__(self, x):
return self.__dict__[x]
def __setitem__(self, key, value):
self.__dict__[key] = value
class UserNullConfig(BaseConfig):
"""
This is the inherited version of basic user config class
ALL THE DATA INSIDE THIS CLASS IS NULL
IT PROVIDES ALL THE INTERFACE VARIABLES
"""
def __init__(self):
BaseConfig.__init__(self)
self.__dict__.update(F=None,
CR=None,
NP=None,
GEN=None,
Goal=None,
data_samples=None,
terms=None,
fitness=None,
max_iter=None,
termination=None,
random_state=None,
learners_para=None,
learners_para_bounds=None,
learners_para_categories=None)
class UserTestConfig(BaseConfig):
"""
This is the inherited version of basic user config class
PRE-WRITTEN FOR THE USE OF TESTING CLASS
CONTAINING ALL THE NECESSARY CONFIG INSIDE
"""
def __init__(self):
BaseConfig.__init__(self)
self.__dict__.update(F=0.3,
CR=0.7,
NP=10,
GEN=2,
Goal="Max",
data_samples=None,
term=7,
fitness=ldascore,
max_iter=10,
termination="Early",
random_state=1,
learners_para=OrderedDict([("n_components", 10), # topics
("doc_topic_prior", 0.1), # alpha
("topic_word_prior", 0.01)]), # beta
learners_para_bounds=[(10, 100), # topics
(0.1, 1), # alpha
(0.01, 1)], # beta
learners_para_categories=["integer",
"continuous",
"categorical"])
def LDADE(config):
seed(config["random_state"])
np.random.seed(config["random_state"])
de = DE(F=config["F"],
CR=config["CR"],
GEN=config["GEN"],
Goal=config["Goal"],
termination=config["termination"],
random_state=config["random_state"])
v, _ = de.solve(config["fitness"],
config["learners_para"],
config["learners_para_bounds"],
config["learners_para_categories"],
term=config["term"],
data_samples=config["data_samples"],
random_state=config["random_state"],
max_iter=config["max_iter"],
ldaMultiWorkers=config["ldaMultiWorkers"])
return v.ind, v.fit