Skip to content

Commit e3424fc

Browse files
committed
change the file path
1 parent 74f343f commit e3424fc

15 files changed

Lines changed: 14062 additions & 37 deletions

File tree

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ We present Joint t-Stochastic Neighbor Embedding (Joint t-SNE), a technique to g
1010
+ It requires [Qt](https://www.qt.io/), [Python 3.6](https://www.python.org/), [numpy](https://numpy.org/) and [scikit-learn](https://scikit-learn.org/).
1111

1212
## How to use:
13-
1. Put the directory of your data sequence, e.g. "YOUR_DATA" in **Joint_tsne/data**. There are several requirements on the format and organization of your data:
13+
1. Put the directory of your data sequence, e.g. "YOUR_DATA" in **./data**. There are several requirements on the format and organization of your data:
1414
+ Each data frame is named as *f_i.txt*, where *i* is the time step/index of this data frame in the sequence.
1515
+ The *j* th row of the data frame contains both the feature vector and label of the *j* th item, which is seperated by \tab. The label is at the last position.
1616
+ All data frames must have the same number of rows, and the the same item is at the same row in different data frames to compute the node similarities one by one.
1717

1818

19-
2. Create a configuration file, e.g. "YOUR_DATA.json" in **Joint_tsne/config**, which is organized as a json structure.
19+
2. Create a configuration file, e.g. "YOUR_DATA.json" in **./config**, which is organized as a json structure.
2020

2121
<code>
2222

@@ -53,22 +53,22 @@ We present Joint t-Stochastic Neighbor Embedding (Joint t-SNE), a technique to g
5353

5454
In this file, *algo* represents the hyperparamters of our algorithm except for *bfs_level*, which always equals to 1. *thesne* contains the information of the input data. Please remember that *data_name* must be consistent with the directory name in the previous step.
5555

56-
3. Create a shell script, e.g. "YOUR_DATA.sh" in **Joint_tsne/scripts** as below:
56+
3. Create a shell script, e.g. "YOUR_DATA.sh" in **./scripts** as below:
5757

5858
<code>
5959

6060
```shell
6161
# !/bin/bash
62-
# 1. specify the configuration file with absolute file path
63-
config_path="xxx/Joint_tsne/config/YOUR_DATA.json"
62+
# 1. specify the path of the configuration file
63+
config_path="config/YOUR_DATA.json"
6464

65-
workdir=$(cd $(dirname $0); pwd)
65+
workdir=$(pwd)
6666

6767
# 2. build knn graph for each data frame
68-
python3 ../codes/graphBuild/run.py $config_path
68+
python3 codes/graphBuild/run.py $config_path
6969

7070
# 3. compute edge similarities between each two adjacent data frames
71-
buildDir="../codes/graphSim/build"
71+
buildDir="codes/graphSim/build"
7272
if [ ! -d $buildDir ]; then
7373
mkdir $buildDir
7474
echo "create directory ${buildDir}"
@@ -79,33 +79,37 @@ cd $buildDir
7979
qmake ../
8080
make
8181

82+
cd $workdir
83+
8284
# bin is dependent on your operating system
83-
bin=./graphSim.app/Contents/MacOS/graphSim
85+
bin=$buildDir/graphSim.app/Contents/MacOS/graphSim
8486
$bin $config_path
8587

86-
cd $workdir
8788

8889
# 4. run t-sne optimization
89-
python3 ../codes/thesne/run.py $config_path
90+
python3 codes/thesne/run.py $config_path
9091
```
9192
</code>
9293

9394
There are several places you should pay attention to.
94-
+ Again, *config_path* must be consitent with the name of configuration file in previous step
95-
+ *bin* is dependent on your operating system. If you use linux, you should change it to
95+
+ Again, *config_path* must be consitent with the name of configuration file in the previous step
96+
+ *bin* is dependent on your operating system. If you use linux, you probably should change it to
9697

97-
bin=./graphSim
98+
bin=$buildDir/graphSim
9899

99-
4. change your directory to **Joint_tsne/scripts** and type
100+
4. In **root** directory, type
100101

101102
<code>
102103

103-
sh YOUR_DATA.sh
104+
sh scripts/YOUR_DATA.sh
104105

105106
</code>
106107

107-
The final embeddings will be generated in **Joint_tsne/results/YOUR_DATA**.
108+
The final embeddings will be generated in **./results/YOUR_DATA**.
109+
110+
111+
5. Optionally, you can use codes/draw/run.py to plot the embeddings.
108112

109113

110114
## Example:
111-
You can find an example in **Joint_tsne/scripts/10_cluster_contract.sh**.
115+
You can find an example in **./scripts/10_cluster_contract.sh**.

codes/draw/run.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
import pylab
3+
from matplotlib.colors import ListedColormap
4+
5+
6+
if __name__ == "__main__":
7+
data_name = "10_cluster_contract"
8+
frame_index = 9
9+
10+
input_path = "../../results/{}/dr_{}.txt".format(
11+
data_name, frame_index)
12+
13+
Y = np.loadtxt(input_path, usecols=range(0, 2), encoding='utf-8')
14+
labels = np.loadtxt(input_path, usecols=(2, ))
15+
16+
17+
colormap = [
18+
"#aecde1", "#3b77af", "#bbdd93", "#559d3f", "#ee9f9c", "#d1352b",
19+
"#c6b3d4", "#644195", "#ffffa6", "#a65e34"
20+
]
21+
my_cmap = ListedColormap(colormap)
22+
23+
pylab.scatter(Y[:, 0], Y[:, 1], 30, labels, cmap=my_cmap)
24+
pylab.show()

codes/graphSim/graph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "math_utils.h"
1111

12-
struct Node //
12+
struct Node
1313
{
1414
float x,y;
1515
QVector<int> childs;

codes/graphSim/main.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111

1212
int main(int argc, char *argv[])
1313
{
14-
QString config_path = argv[1];
15-
// QString config_path = "/Users/joe/Codes/PythonProjects/joint_tsne_experiments/config/5_cluster_trans_split_overlap_contract.json";
16-
17-
QString rootDir = "/Users/joe/Codes/PythonProjects/joint_tsne_experiments/";
14+
QString config_path = argv[1];
1815

1916
QFile configFile(config_path);
2017
configFile.open(QIODevice::ReadOnly | QIODevice::Text);
@@ -46,11 +43,11 @@ int main(int argc, char *argv[])
4643

4744
GraphSimilarity gs(bfs_level);
4845

49-
QString graphDirStr = rootDir + "knn graph/" + data_name;
46+
QString graphDirStr = "knn graph/" + data_name;
5047
QDir graphDir(graphDirStr);
5148

5249

53-
QString simDirStr = rootDir + "graphSim/" + data_name;
50+
QString simDirStr = "graphSim/" + data_name;
5451
QDir simDir(simDirStr);
5552
if (!simDir.exists())
5653
{

codes/graphSim/math_utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ float cosine(const QVector<float> &vec1, const QVector<float> &vec2)
2828
// dot product bewteen v2 and v2
2929
sum2 += vec2[k]*vec2[k];
3030
}
31-
int len1 = static_cast<int>(sqrtf(sum1));
32-
int len2 = static_cast<int>(sqrtf(sum2));
31+
float len1 = sqrtf(sum1);
32+
float len2 = sqrtf(sum2);
3333

3434
float s = 0;
35-
if (len1 != 0 && len2 != 0)
35+
if (len1 > 0 && len2 > 0)
3636
{
3737
s = sum / (len1 * len2);
3838
}
-1 Bytes
Binary file not shown.

config/10_cluster_contract.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"k_closest_count": 3,
44
"perplexity": 70,
55
"bfs_level": 1,
6-
"gamma": 0.1
6+
"gamma": 0.01
77
},
88
"thesne": {
99
"data_name": "10_cluster_contract",

0 commit comments

Comments
 (0)