Skip to content

Commit 2e1846c

Browse files
committed
maven deployed
1 parent c508a06 commit 2e1846c

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Add the following dependency to your POM file:
1818
<dependency>
1919
<groupId>com.github.chen0040</groupId>
2020
<artifactId>java-clustering</artifactId>
21-
<version>1.0.2</version>
21+
<version>1.0.3</version>
2222
</dependency>
2323
```
2424

@@ -65,6 +65,49 @@ for(int i = 0; i < learnedData.rowCount(); ++i){
6565
}
6666
```
6767

68+
### Spatial Segmentation using EM Clustering
69+
70+
The following sample code shows how to use EM clustering to separate two clusters:
71+
72+
```java
73+
DataQuery.DataFrameQueryBuilder schema = DataQuery.blank()
74+
.newInput("c1")
75+
.newInput("c2")
76+
.newOutput("designed")
77+
.end();
78+
79+
Sampler.DataSampleBuilder negativeSampler = new Sampler()
80+
.forColumn("c1").generate((name, index) -> randn() * 0.3 + (index % 2 == 0 ? 2 : 4))
81+
.forColumn("c2").generate((name, index) -> randn() * 0.3 + (index % 2 == 0 ? 2 : 4))
82+
.forColumn("designed").generate((name, index) -> 0.0)
83+
.end();
84+
85+
Sampler.DataSampleBuilder positiveSampler = new Sampler()
86+
.forColumn("c1").generate((name, index) -> rand(-4, -2))
87+
.forColumn("c2").generate((name, index) -> rand(-2, -4))
88+
.forColumn("designed").generate((name, index) -> 1.0)
89+
.end();
90+
91+
DataFrame data = schema.build();
92+
93+
data = negativeSampler.sample(data, 50);
94+
data = positiveSampler.sample(data, 50);
95+
96+
System.out.println(data.head(10));
97+
98+
EMClustering algorithm = new EMClustering();
99+
algorithm.setSigma0(1.5);
100+
algorithm.setClusterCount(2);
101+
102+
DataFrame learnedData = algorithm.fitAndTransform(data);
103+
104+
for(int i = 0; i < learnedData.rowCount(); ++i){
105+
DataRow tuple = learnedData.row(i);
106+
String clusterId = tuple.getCategoricalTargetCell("cluster");
107+
System.out.println("learned: " + clusterId +"\tknown: "+tuple.target());
108+
}
109+
```
110+
68111
### Spatial Segmentation using Single Linkage Clustering
69112

70113
The following sample code shows how to use single linkage clustering to separate two clusters:

pom.xml

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

77
<groupId>com.github.chen0040</groupId>
88
<artifactId>java-clustering</artifactId>
9-
<version>1.0.3</version>
9+
<version>1.0.4</version>
1010

1111

1212
<licenses>

0 commit comments

Comments
 (0)