質問編集履歴

4

誤字

2018/10/11 05:14

投稿

kohekoh
kohekoh

スコア140

test CHANGED
@@ -1 +1 @@
1
- f_min_lbfgs_bの実装について
1
+ sympyを用いて計算した後のデータ型の変換
test CHANGED
@@ -1,45 +1,17 @@
1
- pythonである式の更新のために
1
+ pythonを用いて演算をしています
2
-
3
- lbfgs法を用いることができる,scipyのf_min_lbfgs_bを実装しています
4
2
 
5
3
 
6
4
 
7
- その際に以下ようなエラー出ます
5
+ その際にsympyを用いて,計算をしているです,その解の型が
8
6
 
9
7
 
10
8
 
11
- ```python
12
-
13
- Traceback (most recent call last):
14
-
15
- File "lbfgs_calclog_tamesi.py", line 758, in <module>
16
-
17
- main()
18
-
19
- File "lbfgs_calclog_tamesi.py", line 741, in main
20
-
21
- mean, cov, region_all, region_user, topic_all, topic_user, word_all, word_topic, location_all, location_topic = m_step(sdata,np.delete(coor, test_num, 0),mean, cov, topic_all,topic_user,region_all,region_user,word_all,word_topic,location_all,location_topic,TOPIC,REGION,VOCABULARY,LOCATION2,USER2, voca3, voca)
22
-
23
- File "lbfgs_calclog_tamesi.py", line 196, in m_step
24
-
25
- xre_all = (sp.optimize.fmin_l_bfgs_b(rall_likelihood, x0 = r_al, args = (xs, cor, mean, cov, r_us, t_us, t_al, w_al, w_to, l_al, l_to, usr, voclist, voca, location, region,reg,user,b), fprime = beta_grad_rall))
26
-
27
- File "C:\Users\Anaconda3\envs\py3.5\lib\site-packages\scipy\optimize\lbfgsb.py", line 199, in fmin_l_bfgs_b
28
-
29
- **opts)
30
-
31
- File "C:\Users\Anaconda3\envs\py3.5\lib\site-packages\scipy\optimize\lbfgsb.py", line 328, in _minimize_lbfgsb
32
-
33
- isave, dsave, maxls)
34
-
35
- ValueError: failed to initialize intent(inout) array -- input 'O' not compatible to 'd'
36
-
37
- ```
9
+ <class 'sympy.core.numbers.Float'>
38
10
 
39
11
 
40
12
 
41
- これはどいうことでしょうか
13
+ のよになります
42
14
 
43
15
 
44
16
 
45
- 入力がおかいといことですね?
17
+ これをfloat64に変換するにはどうすればよいでうか

3

誤字

2018/10/11 05:14

投稿

kohekoh
kohekoh

スコア140

test CHANGED
File without changes
test CHANGED
@@ -7,6 +7,8 @@
7
7
  その際に以下のようなエラーが出ます
8
8
 
9
9
 
10
+
11
+ ```python
10
12
 
11
13
  Traceback (most recent call last):
12
14
 
@@ -32,6 +34,8 @@
32
34
 
33
35
  ValueError: failed to initialize intent(inout) array -- input 'O' not compatible to 'd'
34
36
 
37
+ ```
38
+
35
39
 
36
40
 
37
41
  これはどういうことでしょうか

2

誤字

2018/10/11 04:56

投稿

kohekoh
kohekoh

スコア140

test CHANGED
File without changes
test CHANGED
@@ -8,6 +8,28 @@
8
8
 
9
9
 
10
10
 
11
+ Traceback (most recent call last):
12
+
13
+ File "lbfgs_calclog_tamesi.py", line 758, in <module>
14
+
15
+ main()
16
+
17
+ File "lbfgs_calclog_tamesi.py", line 741, in main
18
+
19
+ mean, cov, region_all, region_user, topic_all, topic_user, word_all, word_topic, location_all, location_topic = m_step(sdata,np.delete(coor, test_num, 0),mean, cov, topic_all,topic_user,region_all,region_user,word_all,word_topic,location_all,location_topic,TOPIC,REGION,VOCABULARY,LOCATION2,USER2, voca3, voca)
20
+
21
+ File "lbfgs_calclog_tamesi.py", line 196, in m_step
22
+
23
+ xre_all = (sp.optimize.fmin_l_bfgs_b(rall_likelihood, x0 = r_al, args = (xs, cor, mean, cov, r_us, t_us, t_al, w_al, w_to, l_al, l_to, usr, voclist, voca, location, region,reg,user,b), fprime = beta_grad_rall))
24
+
25
+ File "C:\Users\Anaconda3\envs\py3.5\lib\site-packages\scipy\optimize\lbfgsb.py", line 199, in fmin_l_bfgs_b
26
+
27
+ **opts)
28
+
29
+ File "C:\Users\Anaconda3\envs\py3.5\lib\site-packages\scipy\optimize\lbfgsb.py", line 328, in _minimize_lbfgsb
30
+
31
+ isave, dsave, maxls)
32
+
11
33
  ValueError: failed to initialize intent(inout) array -- input 'O' not compatible to 'd'
12
34
 
13
35
 

1

誤字

2018/10/11 04:55

投稿

kohekoh
kohekoh

スコア140

test CHANGED
File without changes
test CHANGED
@@ -4,196 +4,16 @@
4
4
 
5
5
 
6
6
 
7
- 一応実装自体はできて,解が出てくるのですが
8
-
9
- 更新が一回しかされず,実行するたびに値がまったく異なるのですが
10
-
11
- 挙動はどうなのでしょうか
7
+ 際に以下のようなエラーが出ます
12
-
13
- なにかが間違っているという認識であっているでしょうか
14
8
 
15
9
 
16
10
 
17
- 一応コードを載せておきます
18
-
19
- ```python
20
-
21
- xre_all2 = (sp.optimize.fmin_l_bfgs_b(bfgs_likelihood, x0 = r_al, args = (xs, cor, mean, cov, r_us, t_us, t_al, w_al, w_to, l_al, l_to, usr, voclist, voca, location, region,reg,user,b,xre_all), fprime = beta_grad_rall))
11
+ ValueError: failed to initialize intent(inout) array -- input 'O' not compatible to 'd'
22
12
 
23
13
 
24
14
 
25
- def bfgs_likelihood(params,*args):
26
-
27
- r_all = params
15
+ これはどういうことでしょうか
28
-
29
- xs = args[0]
30
-
31
- cor = args[1]
32
-
33
- mean = args[2]
34
-
35
- cov = args[3]
36
-
37
- r_user = args[4]
38
-
39
- t_user = args[5]
40
-
41
- t_all = args[6]
42
-
43
- w_all = args[7]
44
-
45
- w_topic = args[8]
46
-
47
- l_all = args[9]
48
-
49
- l_topic = args[10]
50
-
51
- User = args[11]
52
-
53
- word = args[12]
54
-
55
- zisyo = args[13]
56
-
57
- LOCATION = args[14]
58
-
59
- sda = 0
60
-
61
- #for i in range(len(l_topic)):
62
-
63
- # print (len(l_all), len(l_topic[i]))
64
-
65
- for w,ccc,vo in zip(xs,cor, word):
66
-
67
- key_topic = (w.split(":|:")[6])
68
-
69
- key_region = (w.split(":|:")[5])
70
-
71
- key_user = (w.split(":|:")[0])
72
-
73
- key_location = (w.split(":|:")[1])
74
-
75
- inde_loc = LOCATION.index(key_location)
76
-
77
- #coordinate = np.array([float(w.split("::")[2]),float(w.split("::")[3])])
78
-
79
- sb = beta(r_all, r_user[User.index((w.split(":|:")[0]))], r_user[User.index((w.split(":|:")[0]))][int(key_region)], r_all[int(key_region)])
80
-
81
- sa = alpha(t_all,t_user[User.index((w.split(":|:")[0]))], float(t_user[User.index((w.split(":|:")[0]))][int(key_topic)]), t_all[int(key_topic)])
82
-
83
- #print "flag"
84
-
85
- if len(vo) != 0:
86
-
87
- #print vo
88
-
89
- #print len(w_topic[int(key_topic)]), len(w_all), len(zisyo)
90
-
91
- sc = np.prod([gamma(w_all, w_topic[int(key_topic)], w_all[zisyo.index(wrd)], w_topic[int(key_topic)][zisyo.index(wrd)]) for wrd in vo])
92
-
93
- else:
94
-
95
- sc = 0
96
-
97
- #print "flag-after"
98
-
99
- #print len(l_all), len(l_topic[int(key_topic)]), key_topic, key_location
100
-
101
- sd = delta(l_all, l_topic[int(key_topic)], l_all[inde_loc], l_topic[int(key_topic)][inde_loc])
102
-
103
- if sa <= 0 or math.isinf(sa):
104
-
105
- sa = 1
106
-
107
- if sb <= 0 or math.isinf(sb):
108
-
109
- sb = 1
110
-
111
- if sc <= 0 or math.isinf(sc):
112
-
113
- sc =1
114
-
115
- if sd <= 0 or math.isinf(sd):
116
-
117
- sd = 1
118
-
119
- if gaussian(ccc,mean[int(key_region)], cov[int(key_region)]) <= 0:
120
-
121
- sda += math.log(sa) + math.log(sb) + math.log(sc) + math.log(sd)
122
-
123
- else:
124
-
125
- try:
126
-
127
- sda += math.log(sa) + math.log(sb) + math.log(sc) + math.log(sd) + math.log(gaussian(ccc,mean[int(key_region)], cov[int(key_region)]))
128
-
129
- except:
130
-
131
- #print (sa,sb,sc,sd,gaussian(ccc,mean[int(key_region)], cov[int(key_region)]))
132
-
133
- sda += math.log(sa) + math.log(sb) + math.log(sd) + math.log(gaussian(ccc,mean[int(key_region)], cov[int(key_region)]))
134
16
 
135
17
 
136
18
 
137
- return sda
138
-
139
-
140
-
141
-
142
-
143
- def beta_grad_rall(params, *args):
144
-
145
- r_al = params
146
-
147
- r_us = args[4]
148
-
149
- usr = args[11]
150
-
151
- region = args[15]
19
+ 入力がおかしいということですかね?
152
-
153
- reg = args[16]
154
-
155
- user = args[17]
156
-
157
- b = args[18]
158
-
159
- xre_all = np.zeros(region)
160
-
161
- count = 0
162
-
163
- for r in range(region):
164
-
165
- region_count = reg.count(str(r))
166
-
167
- for m in usr:
168
-
169
- user_count = user.count(str(m))
170
-
171
- x = Symbol('x')
172
-
173
- b += user_count * (exp(x + r_us[usr.index(m)][r]) / (sum([exp(ra+ru) for ra, ru in zip(r_al, r_us[usr.index(m)])])))
174
-
175
- count+=1
176
-
177
- if region_count == 0:
178
-
179
- xre_all[r] = 0
180
-
181
- else:
182
-
183
- if len(solve(Eq(region_count-b),x)) == 0:
184
-
185
- xre_all[r] = 0
186
-
187
- else:
188
-
189
- np.append(xre_all,solve(Eq(region_count-b),x))
190
-
191
- count = 0
192
-
193
- region_count = 0
194
-
195
- print(xre_all)
196
-
197
- return xre_all
198
-
199
- ```