Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
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
钟尚武
physical
Commits
015afbc3
Commit
015afbc3
authored
Mar 12, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'similar_sort' into 'master'
modifu See merge request
alpha/physical!158
parents
7d80a951
574107f8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
9 deletions
+30
-9
linucb.py
linucb/views/linucb.py
+30
-9
No files found.
linucb/views/linucb.py
View file @
015afbc3
...
...
@@ -45,7 +45,7 @@ class LinUCB:
Aa_list
=
list
()
theta_list
=
list
()
for
tag_id
in
redis_linucb_tag_data_dic
t
:
for
tag_id
in
tag_lis
t
:
tag_dict
=
pickle
.
loads
(
redis_linucb_tag_data_dict
[
tag_id
])
Aa_list
.
append
(
tag_dict
[
"Aa"
])
theta_list
.
append
(
tag_dict
[
"theta"
])
...
...
@@ -60,17 +60,38 @@ class LinUCB:
theta_tmp
=
np
.
array
(
theta_list
)
np_array
=
np
.
dot
(
xaT
,
theta_tmp
)
+
cls
.
alpha
*
np
.
sqrt
(
np
.
dot
(
np
.
dot
(
xaT
,
AaI_tmp
),
xa
))
top_tag_list_len
=
int
(
np_array
.
size
/
2
)
top_np_ind
=
np
.
argpartition
(
np_array
,
-
top_tag_list_len
)[
-
top_tag_list_len
:]
top_tag_list
=
list
()
top_np_list
=
top_np_ind
.
tolist
()
for
tag_id
in
top_np_list
:
top_tag_list
.
append
(
tag_id
)
#
top_tag_list_len = int(np_array.size/2)
#
top_np_ind = np.argpartition(np_array, -top_tag_list_len)[-top_tag_list_len:]
#
#
top_tag_list = list()
#
top_np_list = top_np_ind.tolist()
#
for tag_id in top_np_list:
#
top_tag_list.append(tag_id)
#art_max = tag_list[np.argmax(np.dot(xaT, theta_tmp) + cls.alpha * np.sqrt(np.dot(np.dot(xaT, AaI_tmp), xa)))]
return
top_tag_list
top_tag_set
=
set
()
np_score_list
=
list
()
np_score_dict
=
dict
()
for
score_index
in
range
(
0
,
np_array
.
size
):
score
=
np_array
.
take
(
score_index
)
np_score_list
.
append
(
score
)
if
score
not
in
np_score_dict
:
np_score_dict
[
score
]
=
[
score_index
]
else
:
np_score_dict
[
score
]
.
append
(
score_index
)
sorted_np_score_list
=
sorted
(
np_score_list
,
reverse
=
True
)
for
top_score
in
sorted_np_score_list
:
for
top_score_index
in
np_score_dict
[
top_score
]:
top_tag_set
.
add
(
tag_list
[
top_score_index
])
if
len
(
top_tag_set
)
>=
10
:
break
return
list
(
top_tag_set
)
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
...
...
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