当前位置:网站首页>[mmub] mobile phone user behavior modeling based on Hidden Markov Model -- hidden Markov model
[mmub] mobile phone user behavior modeling based on Hidden Markov Model -- hidden Markov model
2022-04-22 22:41:00 【fpga&matlab】
1. Software version
matlab2013b.
2. Theoretical knowledge of this algorithm


As you can see from the introduction above , The data format of the paper is as follows :
| Time1 |
Time2 |
Time3 |
Time4 |
Time5 |
Time6 |
...... |
|
| USER1 |
Pos1(1) |
Pos1(2) |
Pos1(3) |
Pos1(4) |
Pos1(5) |
Pos1(6) |
...... |
| USER2 |
Pos2(1) |
Pos2(2) |
Pos2(3) |
Pos2(4) |
Pos2(5) |
Pos2(6) |
...... |
| USER3 |
Pos3(1) |
Pos3(2) |
Pos3(3) |
Pos3(4) |
Pos3(5) |
Pos3(6) |
...... |
| ...... |
...... |
...... |
...... |
...... |
...... |
...... |
...... |
| USERn |
Posn(1) |
Posn (2) |
Posn (3) |
Posn (4) |
Posn (5) |
Posn (6) |
...... |
That is, by collecting the positions of multiple users at different times , By algorithm , To predict the position behind ( In this paper, we predict the following 6 Hours , here , We set the parameters to be configurable , Predict the position at any time )
In paper 1 , speak of :

In the same way , For services , The same type of data ( Services are not covered in this paper )
namely , The input data type of the model we use should be in the following format :
| Time1 |
Time2 |
Time3 |
Time4 |
...... |
|
| USER1 |
Pos1,Ser1(1) |
Pos1,Ser1 (2) |
Pos1,Ser1 (3) |
Pos1,Ser1 (4) |
...... |
| USER2 |
Pos2,Ser2 (1) |
Pos2,Ser2 (2) |
Pos2,Ser2 (3) |
Pos2,Ser2 (4) |
...... |
| USER3 |
Pos3,Ser3 (1) |
Pos3,Ser3 (2) |
Pos3,Ser3 (3) |
Pos3,Ser3 (4) |
...... |
| ...... |
...... |
...... |
...... |
...... |
...... |
| USERn |
Posn,Sern (1) |
Posn ,Sern (2) |
Posn,Sern (3) |
Posn,Sern (4) |
...... |
therefore , In demand , The model input you need , That is, data types similar to the above format .
The specific data is :


3. Core code
clc;
clear;
close all;
warning off;
pack;
addpath 'func\'
load locs_realitymining2.mat
N1 = 100;% In order to prevent the continuous state from changing , here N1 Set it up bigger
N2 = 6;
N = N1 + N2; % front N1 For training , after N2 One for predicting
Times = 1000;
% Through multiple cycles , Calculate the accuracy
for Nu = 1:length(Locaiton_id3)
UNo = Nu;% User label
for tim = 1:Times
Dat = Locaiton_id3{1,UNo}(1+tim:N+tim);
State = unique(Dat);
%Counting the User Behavior Patterns
%Counting the User Behavior Patterns
Alpha = [];
maps = [];
MAP = [];
[Alpha,maps,MAP] = func_find_alpha_table(Dat,Locaiton_id3,State);
%Modeling the User Behaviors,the user’s behavior model can be built based on the resulting counting tables
% State transition probability % Release probability
% Calculate in the corresponding algorithm step STATE Steps for , Calculation moving or steady??
[seq,states] = func_cal_moving_steady(maps(1:N));% Here you need to map the address to a natural number
[TRANS_EST,EMIS_EST] = hmmestimate(seq,states);
[r,c] = size(TRANS_EST);
for p1 = 1:r
for p2 = 1:c
if TRANS_EST(p1,p2) == 0
TRANS_EST(p1,p2) = eps;
end
if TRANS_EST(p1,p2) == 1
TRANS_EST(p1,p2) = 1-eps;
end
end
end
% adopt vertiber The algorithm calculates the probability
likelystates = hmmviterbi(seq,TRANS_EST,EMIS_EST);
Ps = length(find(likelystates==1))/N;
Pm = length(find(likelystates==2))/N;
% Predict the position of the next time
likelihood_next_node = zeros(length(State),length(State));
for i = 1:length(State)
for j = 1:length(State)
if i == j
likelihood_next_node(i,j) = Ps*Alpha{i,j}(1);
else
likelihood_next_node(i,j) = Pm*Alpha{i,j}(1);
end
end
end
Plikelihood_next_node = zeros(length(State),N2);
for k = 1:N2
for i = 1:length(State)
Plikelihood_next_node(i,k) = likelihood_next_node(maps(N1+k-1),i)/(sum(likelihood_next_node(:,i))+eps);
end
[V,I] = max(Plikelihood_next_node(:,k));
for j = 1:size(MAP,1)
if I == MAP(j,2);
POS(k) = MAP(j,1);
end
end
end
NNN(:,tim) = (Dat(N1+1:N)==POS(1:N2)')';
end
for k = 1:N2
Precision1m(k,Nu) = sum(NNN(k,:))/Times;
end
end
save tmps2.mat Precision1m
clear all;
load locs_realitymining2.mat
N1 = 100;
N2 = 6;
N = N1 + N2;
Times = 200;
for i = 1:length(Locaiton_id3)
L(i) = length(Locaiton_id3{i});
end
Len = min(L);
% In what we delineated , Compare the time period when there is user behavior
Therehold = 20;
Flag = 0;
ASS = cell(length(Locaiton_id3),length(Locaiton_id3));
for k1 = 1:length(Locaiton_id3)
for k2 = k1+1:length(Locaiton_id3)
Flag = 0;
for i = 1:Len
if Locaiton3{k1}(i) == Locaiton3{k2}(i)% Suppose the duration is greater than 20 For the connection
Flag = Flag + 1;
else
Flag = 0;
end
if Flag > Therehold
ASS{k1,k2} = [ASS{k1,k2},i];
Flag = 0;
end
end
end
end
for Nu = 1:length(Locaiton_id3)
UNo = Nu;% User label
for tim = 1:Times
UNo
tim
% Calculate the number of States
Dat = Locaiton_id3{1,UNo}(1+tim:N+tim);
State = unique(Dat);
% Introduction to calculation status
P = func_trans_prob(Dat,State,N);
% Introduction to computing state transition
[P_tra,Map] = func_transition_matrix(Dat,State);
for j = 1:size(Map,1)
if Dat(N1) == Map(j,1);
Initial = Map(j,2);
end
end
% Start to predict
TT = zeros(1,length(State));
TT(Initial) = 1;
PState{1}= TT;
for i = 2:N2+1
PState{i} = PState{i-1}*P_tra;
[V,I] = max(PState{i});
for j = 1:size(Map,1)
if I == Map(j,2);
Pos(i-1) = Map(j,1);
end
end
end
NNN(:,tim) = (Dat(N1+1:N)==Pos(1:N2)')';
end
for k = 1:N2
Precision1(k,Nu) = sum(NNN(k,:))/Times;
end
end
save tmps1.mat Precision1
load tmps1.mat
load tmps2.mat
% combination CPB The final probability of the result
Precision2 = Precision1;
for Nu1 = 1:length(Locaiton_id3)
for Nu2 = 1:length(Locaiton_id3)
for tim = 1:Times
if isempty(ASS{Nu1,Nu2}) == 0
for k = 1:length(ASS{Nu1,Nu2})
if ASS{Nu1,Nu2}(k) == tim
for k2 = 1:N2
Precision2(k2,Nu1) = max(max(Precision1(k2,Nu1),Precision1(k2,Nu2)),max(Precision1m(k2,Nu1),Precision1m(k2,Nu2)));
end
end
end
end
end
end
end
save Result.mat Precision2
figure;
load Result1.mat
Views1 = [mean(Precision1(:,:),2)];
Views2 = [mean(Precision2(:,:),2)];
Views = [Views1,Views2];
bar(Views);
axis([0,N2+1,0.4,0.8]);
xlabel('Times');
ylabel('Precision');
legend('Markov','MMUB CPB Markov');
4. Operation steps and simulation conclusion




This algorithm , We will combine CBP+MMUB+MarkovChain Build the prediction algorithm .

From the simulation results, we can see , Compared with other algorithms, the improved algorithm has a certain performance improvement .
5. reference
A05-14
6. How to obtain the complete source code
The way 1: Wechat or QQ Contact bloggers
The way 2: subscribe
, Get the tutorial case code and any of this blog for free 2 Complete source code
版权声明
本文为[fpga&matlab]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222142054361.html
边栏推荐
猜你喜欢

41.0:GemBox.Spreadsheet|.Document|.Pdf|.Presentation

GORM 预加载和自引用

Listing on the Shanghai Stock Exchange of CNOOC: market value of 6.515 billion and annual profit of 70.3 billion

【4.1】flink窗口算子的trigger触发器和Evictor清理器

100 billion level im independent development guide! Global instant messaging full set of codes 4 hours quick (II)

io_uring技术在分布式云原生数据库中的应用

opcua协议如何在appinventor上使用?

【洛谷】P1162 填涂颜色(bfs)

MySql--库的操作

A simple and easy-to-use file upload scheme
随机推荐
Quickly calculate the number of divisors -- from basic to advanced
Transport layer - connectionless transport: UDP (2)
How to use lightly to teach programming classes gracefully?
Implementation of multi-layer perceptron from scratch (extracting function from D2L package)
Basic practice of C language (001-1)
High end beer is losing young people
Flex layout
Overview of working principle and main characteristics of ATOS proportional valve
Mathematics - Bezier curve
Sign up to open QKE container engine hosting version and container ecological Conference!
es6将二维、多维数组转化为一维数组
线性基(各种模板+例题)
用forEach和ES6实现tab切换
7. Comparable to JMeter Net pressure measurement tool - crank Summary - what does crank bring
Leetcode 04 Median of Two Sorted Arrays
Text processing mode out of bootrap box
Centos7安装mysql
Flutter hybrid development
接续符介绍及用法和++和--操作符分析介绍及用法
These two kinds of people can't do well in we media and can't make a lot of money all their life