Code Monkey home page Code Monkey logo

fyp_trajectory_clustering's Introduction

SCSE22-0161:Mining Big Spatial Data

Project Introduction:

This is my final year project. A large geospatial taxi trajectory dataset is used as dataset. The goal of project is to mine the patterns of trajectories and cluster trajectories into groups based on the pattern. To achieve this goal, two trajectory clustering models are presented, and a web-based front-end application is developed for visualization.
The first trajectory clustering model mainly contains a trajectory reduction layer and a trajectory clustering layer. The trajectory reduction layer utilizes Ramer–Douglas–Peucker Algorithm to reduce the size of trajectories, while preserving the geometric shape. The trajectory clustering layer adopts Hierarchical Density-Based Spatial Clustering of Applications with Noise (HDBSCAN) algorithm to produce clusters out of the reduced trajectories. This model is able to cluster long trajectories, but it cannot identify intertwined and dense trajectories.
The second model resolves the bottleneck by introducing Reccurent Neural Network (RNN) with a behavior extraction algorithm. The model consists of three layers: trajectory feature extraction, trajectory pattern mining and trajectory clustering. Trajectory feature extraction layer summarizes the trajectory moving pattern using sliding window. Trajectory pattern mining layer accepts the patterns and learns vector representation from them, using sequence-to-sequence encoder-decoder model with attention. The vectors are then clustered by K-means in trajectory clustering layer. This 3-layer model outperforms our first model as it is able to produce fairly distributed clusters, and group the trajectories with higher precision.
To facilitate the visualization, a web-based front-end application is developed using React.js. It displays the trajectory cluster on the map, and interacts with user to render details of the cluster.
Kindly refer to my final year paper for more details and technicals.  

Model 1: Trajectory Clustering with Polyline Reduction

Requirements

numpy==1.21.5
pandas==1.4.4
folium==0.14.0
hdbscan==0.8.29
utm==0.7.0
The package requirements has been consolidated at model_1/requirements.txt.  

Quick Demo

A demo with 1000 trajectories has been saved in model_1/Model Demo. The original jupyter notebook with interactive map visualization is also provided as model_1/Model 1 Demo.ipynb. This notebook experiments with 1000 trajectories, and produces cluster results. You can run it if necessary.

     

Model 2: Trajectory Clustering with Deep Learning

Requirements

numpy==1.21.5
pandas==1.4.4
tensorflow==2.11.0
tensorflow-addons==0.19.0
tensorflow-estimator==2.11.0
keras==2.11.0
folium==0.14.0
hdbscan==0.8.29
scikit-learn==1.0.2
utm==0.7.0
The package requirements has been consolidated at model_2/requirements.txt.  

Training and Clustering

Due to the file size limit imposed by Git, only partial checkpoint files are uploaded.
To run the model, first initiate an TrajPatternMiner object and supply the parameters:\

tpm = TrajPatternMiner(traj_to_try, learning_rate, training_epochs, \
                      display_step, units, batch_size, max_n_steps, frame_dim, window_size)

Start training by calling:

trajVec = tpm.runTheModel()

Perform clustering on the vectors:

tpm.cluster_by_kmeans(trajVec, number_of_clusters)

   

React.js Front-end Web Application

To run:

  1. cd to local directory and then cd to frontend directory.
cd frontend
  1. run npm start.    

fyp_trajectory_clustering's People

Contributors

agnesye1029 avatar

Stargazers

 avatar

Watchers

 avatar

fyp_trajectory_clustering's Issues

"mm = TrajPatternMiner(traj_list, learning_rate, training_epochs, \ display_step, units, batch_size, max_n_steps, frame_dim, window_size)"

When i run the code "mm = TrajPatternMiner(traj_list, learning_rate, training_epochs,
display_step, units, batch_size, max_n_steps, frame_dim, window_size)"

There's an error:
TypeCheckError Traceback (most recent call last)
Cell In[10], line 1
----> 1 mm = TrajPatternMiner(traj_list, learning_rate, training_epochs,
2 display_step, units, batch_size, max_n_steps, frame_dim, window_size)

File D:\Users\duhit\Desktop\323\FYP_trajectory_clustering-main\FYP_trajectory_clustering-main\model_2\traj_pattern_miner.py:20, in TrajPatternMiner.init(self, traj, learning_rate, training_epochs, display_step, units, batch_size, max_n_steps, frame_dim, window_size)
18 self.window_size = window_size
19 self.txc = TrajectoryBehaviorExtraction()
---> 20 self.t2v = Traj2Vec(self.learning_rate, self.training_epochs, self.display_step, self.units, self.batch_size, self.frame_dim)

File D:\Users\duhit\Desktop\323\FYP_trajectory_clustering-main\FYP_trajectory_clustering-main\model_2\traj2vec.py:27, in Traj2Vec.init(self, learning_rate, training_epochs, display_step, units, batch_size, frame_dim)
25 self.frame_dim = frame_dim
26 self.encoder = Encoder(self.units, self.batch_size)
---> 27 self.decoder = Decoder(self.units, self.batch_size, self.max_n_steps)
28 self.optimizer = tf.keras.optimizers.experimental.RMSprop(self.learning_rate)
29 self.checkpoint_dir = './training_checkpoints'

File D:\Users\duhit\Desktop\323\FYP_trajectory_clustering-main\FYP_trajectory_clustering-main\model_2\decoder.py:21, in Decoder.init(self, dec_units, batch_sz, max_length_input, attention_type)
18 self.sampler = tfa.seq2seq.sampler.TrainingSampler()
20 # Create attention mechanism with memory = None
---> 21 self.attention_mechanism = self.build_attention_mechanism(self.dec_units,
22 None, self.batch_sz*[self.max_length_input], self.attention_type)
24 # Wrap attention mechanism with the fundamental rnn cell of decoder
25 self.rnn_cell = self.build_rnn_cell(batch_sz)

File D:\Users\duhit\Desktop\323\FYP_trajectory_clustering-main\FYP_trajectory_clustering-main\model_2\decoder.py:46, in Decoder.build_attention_mechanism(self, dec_units, memory, memory_sequence_length, attention_type)
44 return tfa.seq2seq.BahdanauAttention(units=dec_units, memory=memory, memory_sequence_length=memory_sequence_length)
45 else:
---> 46 return tfa.seq2seq.LuongAttention(units=dec_units, memory=memory, memory_sequence_length=memory_sequence_length)

File D:\duhit\anaconda\envs\FYP\lib\site-packages\tensorflow_addons\seq2seq\attention_wrapper.py:543, in init(self, units, memory, memory_sequence_length, scale, probability_fn, dtype, name, **kwargs)
540 # For LuongAttention, we only transform the memory layer; thus
541 # num_units must match expected the query depth.
542 self.probability_fn_name = probability_fn
--> 543 probability_fn = self._process_probability_fn(self.probability_fn_name)
545 def wrapped_probability_fn(score, _):
546 return probability_fn(score)

File D:\duhit\anaconda\envs\FYP\lib\site-packages\typeguard_functions.py:264, in check_variable_assignment(value, expected_annotations, memo)
262 iterated_values.append(obj)
263 try:
--> 264 check_type_internal(obj, expected_type, memo)
265 except TypeCheckError as exc:
266 exc.append_path_element(argname)

File D:\duhit\anaconda\envs\FYP\lib\site-packages\typeguard_checkers.py:671, in check_type_internal(value, annotation, memo)
668 return
670 if not isinstance(value, origin_type):
--> 671 raise TypeCheckError(f"is not an instance of {qualified_name(origin_type)}")

TypeCheckError: probability_fn is not an instance of str

Who knows the solving methods? Emergency!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.