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
f5cab4c7
Commit
f5cab4c7
authored
Feb 27, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'linUCB' into 'master'
modify See merge request
alpha/physical!130
parents
19f84959
deac1811
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
linucb.py
linucb/views/linucb.py
+6
-5
No files found.
linucb/views/linucb.py
View file @
f5cab4c7
...
...
@@ -8,6 +8,7 @@ from trans2es.models.tag import Tag
import
logging
import
traceback
import
json
import
pickle
class
LinUCB
:
d
=
2
...
...
@@ -45,7 +46,7 @@ class LinUCB:
theta_list
=
list
()
for
tag_id
in
redis_linucb_tag_data_dict
:
tag_dict
=
json
.
loads
(
redis_linucb_tag_data_dict
[
tag_id
])
tag_dict
=
pickle
.
loads
(
redis_linucb_tag_data_dict
[
tag_id
])
Aa_list
.
append
(
tag_dict
[
"Aa"
])
theta_list
.
append
(
tag_dict
[
"theta"
])
...
...
@@ -78,8 +79,8 @@ class LinUCB:
"ba"
:
np
.
zeros
((
cls
.
d
,
1
)),
"AaI"
:
np
.
identity
(
cls
.
d
)
}
json_data
=
json
.
dumps
(
init_dict
)
user_tag_linucb_dict
[
tag_id
]
=
json
_data
pickle_data
=
pickle
.
dumps
(
init_dict
)
user_tag_linucb_dict
[
tag_id
]
=
pickle
_data
redis_cli
.
hmset
(
redis_key
,
user_tag_linucb_dict
)
...
...
@@ -108,7 +109,7 @@ class LinUCB:
if
not
ori_redis_tag_data
:
LinUCB
.
init_device_id_linucb_info
(
redis_client
,
redis_prefix
,
device_id
,[
tag_id
])
else
:
ori_redis_tag_dict
=
json
.
loads
(
ori_redis_tag_data
)
ori_redis_tag_dict
=
pickle
.
loads
(
ori_redis_tag_data
)
new_Aa_matrix
=
ori_redis_tag_dict
[
"Aa"
]
+
np
.
dot
(
xa
,
xaT
)
new_AaI_matrix
=
np
.
linalg
.
solve
(
new_Aa_matrix
,
np
.
identity
(
cls
.
d
))
new_ba_matrix
=
ori_redis_tag_dict
[
"ba"
]
+
r
*
xa
...
...
@@ -120,7 +121,7 @@ class LinUCB:
"theta"
:
np
.
dot
(
new_AaI_matrix
,
new_ba_matrix
)
}
redis_cli
.
hset
(
redis_key
,
tag_id
,
json
.
dumps
(
user_tag_dict
))
redis_cli
.
hset
(
redis_key
,
tag_id
,
pickle
.
dumps
(
user_tag_dict
))
return
True
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
...
...
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