Skip to content

Commit

Permalink
Merge pull request #10 from shapelets/feature/clustering
Browse files Browse the repository at this point in the history
Adding clustering functions and tests
  • Loading branch information
avilchess committed Mar 8, 2019
2 parents 164ce10 + 436fdc7 commit f1d2f94
Show file tree
Hide file tree
Showing 40 changed files with 2,040 additions and 1,928 deletions.
4 changes: 2 additions & 2 deletions .CI/travis/build-and-test.sh
@@ -1,9 +1,9 @@
#!/bin/bash
# Copyright (c) 2018 Shapelets.io
# Copyright (c) 2019 Shapelets.io
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

mvn dokka:dokka
mvn test
mvn test
2 changes: 1 addition & 1 deletion .CI/travis/install-arrayfire.sh
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2018 Shapelets.io
# Copyright (c) 2019 Shapelets.io
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
2 changes: 1 addition & 1 deletion .CI/travis/install-java.sh
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2018 Shapelets.io
# Copyright (c) 2019 Shapelets.io
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
2 changes: 1 addition & 1 deletion .CI/travis/install-khiva.sh
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2018 Shapelets.io
# Copyright (c) 2019 Shapelets.io
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
2 changes: 1 addition & 1 deletion .appveyor.yml
@@ -1,4 +1,4 @@
# Copyright (c) 2018 Shapelets.io
# Copyright (c) 2019 Shapelets.io
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Expand Up @@ -90,4 +90,4 @@ If some members of staff were angered by the incident, it is best to apologise t

## Attribution

This Code of Conduct was adapted from both [Golang](https://golang.org/conduct) an the [Golang UK Conference](http://golanguk.com/conduct/).
This Code of Conduct was adapted from both [Golang](https://golang.org/conduct) an the [Golang UK Conference](http://golanguk.com/conduct/).
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,4 +1,4 @@
# Copyright (c) 2018 Shapelets.io
# Copyright (c) 2019 Shapelets.io
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -80,4 +80,4 @@ Start a new docker container.
```
# Start docker
docker run --rm -ti shapelets/khiva-java
```
```
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -51,4 +51,4 @@ Dokka does not support the writing of mathematical formulas, therefore functions
## Contributing
The rules to contribute to this project are described [here](CONTRIBUTING.md)

[![Powered by Shapelets](https://img.shields.io/badge/powered%20by-Shapelets-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://shapelets.io)
[![Powered by Shapelets](https://img.shields.io/badge/powered%20by-Shapelets-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://shapelets.io)
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -9,7 +9,7 @@
</properties>
<groupId>io.shapelets</groupId>
<artifactId>khiva-kotlin</artifactId>
<version>0.1.0</version>
<version>0.2.0</version>

<name>khiva-kotlin</name>
<url>https://github.com/shapelets/khiva-kotlin</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/shapelets/khiva/Array.kt
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Shapelets.io
* Copyright (c) 2019 Shapelets.io
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
59 changes: 59 additions & 0 deletions src/main/kotlin/io/shapelets/khiva/Clustering.kt
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2019 Shapelets.io
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/

package io.shapelets.khiva

/**
* Khiva Clustering class containing several clustering methods.
*/
object Clustering : Library() {
@JvmStatic
private external fun kMeans(tss: Long, k: Int, tolerance: Float, maxInterations: Int): LongArray

@JvmStatic
private external fun kShape(tss: Long, k: Int, tolerance: Float, maxInterations: Int): LongArray

/**
* Calculates the KMeans algorithm.
*
* [1] S. Lloyd. 1982. Least squares quantization in PCM. IEEE Transactions on Information Theory, 28, 2,
* Pages 129-137.
*
* @param tss The set of time series to be clusterized.
* @param k The number of centroids.
* @param tolerance The maximum error tolerance.
* @param maxIterations The maximum number of iterations.
*
* @return An Array of arrays with the resulting centroids and labels.
*/
fun kMeans(tss: Array, k: Int, tolerance: Float, maxInterations: Int): kotlin.Array<Array> {
val refs = Clustering.kMeans(tss.reference, k, tolerance, maxInterations)
tss.reference = refs[0]
return arrayOf(Array(refs[1]), Array(refs[2]))
}

/**
* Calculates the KShape algorithm.
*
* [1] John Paparrizos and Luis Gravano. 2016. k-Shape: Efficient and Accurate Clustering of Time Series.
* SIGMOD Rec. 45, 1 (June 2016), 69-76.
*
* @param tss The set of time series to be clusterized.
* @param k The number of centroids.
* @param tolerance The maximum error tolerance.
* @param maxIterations The maximum number of iterations.
*
* @return An Array of arrays with the resulting centroids and labels.
*/
fun kShape(tss: Array, k: Int, tolerance: Float, maxInterations: Int): kotlin.Array<Array>{
val refs = Clustering.kShape(tss.reference, k, tolerance, maxInterations)
tss.reference = refs[0]
return arrayOf(Array(refs[1]), Array(refs[2]))
}
}

0 comments on commit f1d2f94

Please sign in to comment.