Skip to content

Commit

Permalink
Register C fucntion
Browse files Browse the repository at this point in the history
  • Loading branch information
Neplex committed Sep 25, 2017
1 parent b0dff2b commit edc67e4
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 43 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: COveR
Title: Clustering with Overlaps in R
Version: 0.10.6
Version: 1.0.0
Authors@R: c(
person("Guillaume", "Cleuziou", email = "guillaume.cleuziou@univ-orleans.fr", role = "cre"),
person("Nicolas", "Hiot", email = "nicolas.hiot@etu.univ-orleans.fr", role = "aut"))
Expand Down
17 changes: 9 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ export(r1okm)
export(r2okm)
export(read.interval)
export(write.interval)
useDynLib(COveR,R_icmeans)
useDynLib(COveR,R_ikmeans)
useDynLib(COveR,R_ineokm)
useDynLib(COveR,R_iokm)
useDynLib(COveR,R_neokm)
useDynLib(COveR,R_okm)
useDynLib(COveR,R_r1okm)
useDynLib(COveR,R_r2okm)
importFrom(grDevices,col2rgb)
importFrom(grDevices,rainbow)
importFrom(grDevices,rgb)
importFrom(graphics,plot)
importFrom(graphics,rect)
importFrom(stats,model.matrix)
importFrom(utils,read.csv)
importFrom(utils,write.csv)
useDynLib(COveR, .registration = TRUE)
6 changes: 3 additions & 3 deletions R/fuzzy_icmeans.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Interval fuzzy cmeans clustering.
#'
#' Culster interval data with fuzzy cmeans algorithm.
#' @useDynLib COveR R_icmeans
#' @useDynLib COveR, .registration = TRUE
#'
#' @param x An 3D interval array.
#' @param centers A number or interval, number of cluster for clustering or pre init centers.
Expand Down Expand Up @@ -71,11 +71,11 @@ fuzzy_icmeans <- function(x, centers, m = 2, nstart = 2, distance = "euclid", tr
stop(paste("Unknow distance:", distance, ". Try 'euclid' or 'hausdorff'"))
}

#  Call
# Call
d <- dim(x$inter)
n <- dimnames(x$inter)
v <- as.numeric(as.vector(x$inter))
c <- .Call(R_icmeans, v, d[1], d[2], d[3], nc, m, nstart, dist, trace, iter.max,
c <- .Call("_icmeans", v, d[1], d[2], d[3], nc, m, nstart, dist, trace, iter.max,
c)

# Naming
Expand Down
6 changes: 3 additions & 3 deletions R/ikmeans.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Interval kmeans clustering.
#'
#' Culster interval data with kmeans algorithm.
#' @useDynLib COveR R_ikmeans
#' @useDynLib COveR, .registration = TRUE
#'
#' @param x An 3D interval array.
#' @param centers A number or interval, number of cluster for clustering or pre init centers.
Expand Down Expand Up @@ -65,11 +65,11 @@ ikmeans <- function(x, centers, nstart = 10, distance = "euclid", trace = FALSE,
stop(paste("Unknow distance:", distance, ". Try 'euclid' or 'hausdorff'"))
}

#  Call
# Call
d <- dim(x$inter)
n <- dimnames(x$inter)
v <- as.numeric(as.vector(x$inter))
c <- .Call(R_ikmeans, v, d[1], d[2], d[3], nc, nstart, dist, trace, iter.max,
c <- .Call("_ikmeans", v, d[1], d[2], d[3], nc, nstart, dist, trace, iter.max,
c)

# Naming
Expand Down
6 changes: 3 additions & 3 deletions R/ineokm.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Interval neokm clustering.
#'
#' Culster interval data with neokm algorithm.
#' @useDynLib COveR R_ineokm
#' @useDynLib COveR, .registration = TRUE
#'
#' @param x An 3D interval array.
#' @param centers A number or interval, number of cluster for clustering or pre init centers.
Expand Down Expand Up @@ -61,11 +61,11 @@ ineokm <- function(x, centers, alpha = 0.3, beta = 0.05, nstart = 10, trace = FA
if (iter.max <= 0)
stop("iter.max must be positive")

#  Call
# Call
d <- dim(x$inter)
n <- dimnames(x$inter)
v <- as.numeric(as.vector(x$inter))
c <- .Call(R_ineokm, v, d[1], d[2], d[3], nc, alpha, beta, nstart, trace, iter.max,
c <- .Call("_ineokm", v, d[1], d[2], d[3], nc, alpha, beta, nstart, trace, iter.max,
c)

# Naming
Expand Down
8 changes: 8 additions & 0 deletions R/interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ print.interval <- function(x, ...) {
#' @param class The column of class (empty if not).
#' @param ... Other options from read.
#'
#' @importFrom utils read.csv
#'
#' @export
read.interval <- function(..., row.names = FALSE, class = NULL) {
args <- list(...)
Expand Down Expand Up @@ -86,6 +88,8 @@ read.interval <- function(..., row.names = FALSE, class = NULL) {
#' @param class Write the class column at the end ?.
#' @param ... Other options from write.
#'
#' @importFrom utils write.csv
#'
#' @export
write.interval <- function(x, ..., class = FALSE) {
if (!is.interval(x))
Expand Down Expand Up @@ -117,6 +121,8 @@ write.interval <- function(x, ..., class = FALSE) {
#' - 'add' Add to exsiting plot or not.
#' - Other options from plot.
#'
#' @importFrom graphics plot rect
#'
#' @export
#'
#' @examples
Expand Down Expand Up @@ -271,6 +277,8 @@ igenerate <- function(n, ...) {
#' @param max The maximum value of degree.
#' @param step The step of degree.
#'
#' @importFrom graphics plot
#'
#' @export
measure <- function(x, min = 0, max = 1, step = 0.1) {
if (!is.matrix(x))
Expand Down
6 changes: 3 additions & 3 deletions R/iokm.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Interval okm clustering.
#'
#' Culster interval data with okm algorithm.
#' @useDynLib COveR R_iokm
#' @useDynLib COveR, .registration = TRUE
#'
#' @param x An 3D interval array.
#' @param centers A number or interval, number of cluster for clustering or pre init centers.
Expand Down Expand Up @@ -77,11 +77,11 @@ iokm <- function(x, centers, nstart = 10, distance = "euclid", algorithm = "std"
# Update
up <- match(update, c("mean", "sum", "join", "meet")) - 1


# Call
d <- dim(x$inter)
n <- dimnames(x$inter)
v <- as.numeric(as.vector(x$inter))
c <- .Call(R_iokm, v, d[1], d[2], d[3], nc, nstart, dist, algo, up, trace, iter.max,
c <- .Call("_iokm", v, d[1], d[2], d[3], nc, nstart, dist, algo, up, trace, iter.max,
secure, c)


Expand Down
6 changes: 3 additions & 3 deletions R/neokm.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' neokm clustering.
#'
#' Culster data with neokm algorithm.
#' @useDynLib COveR R_neokm
#' @useDynLib COveR, .registration = TRUE
#'
#' @param x An data matrix.
#' @param centers A number, number of cluster for clustering or pre init centers.
Expand Down Expand Up @@ -62,9 +62,9 @@ neokm <- function(x, centers, alpha = 0.3, beta = 0.05, nstart = 10, trace = FAL
if (iter.max <= 0)
stop("iter.max must be positive")


# Call
v <- as.numeric(as.vector(data.matrix(x)))
c <- .Call(R_neokm, v, nrow(x), ncol(x), nc, alpha, beta, nstart, trace, iter.max,
c <- .Call("_neokm", v, nrow(x), ncol(x), nc, alpha, beta, nstart, trace, iter.max,
c)


Expand Down
7 changes: 3 additions & 4 deletions R/okm.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' OKM clustering.
#'
#' Overlapping Kmeans algorithm.
#' @useDynLib COveR R_okm
#' @useDynLib COveR, .registration = TRUE
#'
#' @param X A data.
#' @param centers A number or matrix, number of cluster for clustering or pre init centers.
Expand Down Expand Up @@ -54,18 +54,17 @@ okm <- function(X, centers, iter.max = 10, nstart = 1, trace = FALSE, method = "
if (nrow(X) < k)
stop("More cluster than datas in X.")


if (method == "euclid")
method <- 1 else if (method == "manhattan")
method <- 2 else stop("Unknown distance computation method.")
U <- .C(R_okm, as.double(t(X)), centers = as.double(t(cen)), as.integer(iter.max),
U <- .C("_okm", as.double(t(X)), centers = as.double(t(cen)), as.integer(iter.max),
as.integer(k), as.integer(ncol(X)), as.integer(nrow(X)), clusters = integer(nrow(X) *
k), wss = as.double(k), over = as.double(k), as.integer(trace), 0, 0,
0, 0, 0, as.integer(method))
if (use.nstart && nstart > 1) {
for (i in 2:nstart) {
cen <- X[sample(1:nrow(X), k), ]
UU <- .C(R_okm, as.double(t(X)), centers = as.double(t(cen)), as.integer(iter.max),
UU <- .C("_okm", as.double(t(X)), centers = as.double(t(cen)), as.integer(iter.max),
as.integer(k), as.integer(ncol(X)), as.integer(nrow(X)), clusters = integer(nrow(X) *
k), wss = as.double(k), over = as.double(k), as.integer(trace),
0, 0, 0, 0, 0, as.integer(method))
Expand Down
5 changes: 3 additions & 2 deletions R/r1okm.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' r1okm clustering.
#'
#' Culster data with r1okm algorithm.
#' @useDynLib COveR R_r1okm
#' @useDynLib COveR, .registration = TRUE
#'
#' @param x An data matrix.
#' @param centers A number, number of cluster for clustering or pre init centers.
Expand Down Expand Up @@ -60,8 +60,9 @@ r1okm <- function(x, centers, alpha = 0, nstart = 10, trace = FALSE, iter.max =
stop("iter.max must be positive")


# Call
v <- as.numeric(as.vector(data.matrix(x)))
c <- .Call(R_r1okm, v, nrow(x), ncol(x), nc, alpha, nstart, trace, iter.max,
c <- .Call("_r1okm", v, nrow(x), ncol(x), nc, alpha, nstart, trace, iter.max,
c)


Expand Down
5 changes: 3 additions & 2 deletions R/r2okm.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' r2okm clustering.
#'
#' Culster data with r2okm algorithm.
#' @useDynLib COveR R_r2okm
#' @useDynLib COveR, .registration = TRUE
#'
#' @param x An data matrix.
#' @param centers A number, number of cluster for clustering or pre init centers.
Expand Down Expand Up @@ -62,8 +62,9 @@ r2okm <- function(x, centers, lambda = 0, nstart = 10, trace = FALSE, iter.max =
stop("iter.max must be positive")


# Call
v <- as.numeric(as.vector(data.matrix(x)))
c <- .Call(R_r2okm, v, nrow(x), ncol(x), nc, lambda, nstart, trace, iter.max,
c <- .Call("_r2okm", v, nrow(x), ncol(x), nc, lambda, nstart, trace, iter.max,
c)


Expand Down
3 changes: 3 additions & 0 deletions R/tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#'
#' @param x A cluster.
#'
#' @importFrom grDevices col2rgb rainbow rgb
#' @importFrom stats model.matrix
#'
#' @export
#'
#' @examples
Expand Down
31 changes: 31 additions & 0 deletions src/COveR-init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Interval clustering
#include "icmeans/R_icmeans.h"
#include "ikmeans/R_ikmeans.h"
#include "ineokm/R_ineokm.h"
#include "iokm/R_iokm.h"

// Classic clustering
#include "neokm/R_neokm.h"
#include "okm/okm.h"
#include "r1okm/R_r1okm.h"
#include "r2okm/R_r2okm.h"

#include <R.h>
#include <R_ext/Rdynload.h>
#include <Rinternals.h>

static const R_CallMethodDef callMethods[] = {
{"_icmeans", (DL_FUNC)&R_icmeans, 11}, {"_ikmeans", (DL_FUNC)&R_ikmeans, 10},
{"_ineokm", (DL_FUNC)&R_ineokm, 11}, {"_iokm", (DL_FUNC)&R_iokm, 13},
{"_neokm", (DL_FUNC)&R_neokm, 10}, {"_r1okm", (DL_FUNC)&R_r1okm, 9},
{"_r2okm", (DL_FUNC)&R_r2okm, 9}, {NULL, NULL, 0}};

static R_NativePrimitiveArgType okm_t[] = {
REALSXP, REALSXP, INTSXP, INTSXP, INTSXP, INTSXP, INTSXP, REALSXP,
REALSXP, INTSXP, REALSXP, REALSXP, REALSXP, REALSXP, REALSXP, INTSXP};
static const R_CMethodDef cMethods[] = {{"_okm", (DL_FUNC)&R_okm, 16, okm_t},
{NULL, NULL, 0}};

void R_init_COveR(DllInfo *info) {
R_registerRoutines(info, cMethods, callMethods, NULL, NULL);
}
11 changes: 0 additions & 11 deletions src/clustering.c

This file was deleted.

0 comments on commit edc67e4

Please sign in to comment.