class/0000755000176000001440000000000014167756466011435 5ustar ripleyusersclass/NAMESPACE0000644000176000001440000000043412544221020012617 0ustar ripleyusersuseDynLib(class, .registration = TRUE) export(batchSOM, condense, knn, knn.cv, knn1, lvq1, lvq2, lvq3, lvqinit, lvqtest, multiedit, olvq1, reduce.nn, SOM, somgrid) importFrom(graphics, plot, points, stars) importFrom(stats, dist) S3method(plot, SOM) S3method(plot, somgrid) class/LICENCE.note0000644000176000001440000000302114036521070013332 0ustar ripleyusersSoftware and datasets to support 'Modern Applied Statistics with S', fourth edition, by W. N. Venables and B. D. Ripley. Springer, 2002. From the text (pp. 464): These datasets and software are provided in good faith, but none of the authors, publishers nor distributors warrant their accuracy nor can be held responsible for the consequences of their use. This file is intended to clarify ownership and copyright: where possible individual files also carry brief copyright notices. Copyrights ========== All files except translations are copyright W. N. Venables and B. D. Ripley. Those parts which were distributed with the first edition are also copyright (C) 1994 Springer-Verlag New York Inc, with all rights assigned to W. N. Venables and B. D. Ripley. Licence ======= This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 or 3 of the License (at your option). This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Files share/licenses/GPL-2 and share/licenses/GPL-3 in the R (source or binary) distribution are copies of versions 2 and 3 of the 'GNU General Public License'. These can also be viewed at https://www.r-project.org/Licenses/ Bill.Venables@gmail.com ripley@stats.ox.ac.uk class/man/0000755000176000001440000000000012536607645012200 5ustar ripleyusersclass/man/lvq2.Rd0000644000176000001440000000333311754562034013346 0ustar ripleyusers% file class/man/lvq2.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{lvq2} \alias{lvq2} \title{ Learning Vector Quantization 2.1 } \description{ Moves examples in a codebook to better represent the training set. } \usage{ lvq2(x, cl, codebk, niter = 100 * nrow(codebk$x), alpha = 0.03, win = 0.3) } \arguments{ \item{x}{ a matrix or data frame of examples } \item{cl}{ a vector or factor of classifications for the examples } \item{codebk}{ a codebook } \item{niter}{ number of iterations } \item{alpha}{ constant for training } \item{win}{ a tolerance for the closeness of the two nearest vectors. }} \value{ A codebook, represented as a list with components \code{x} and \code{cl} giving the examples and classes. } \details{ Selects \code{niter} examples at random with replacement, and adjusts the nearest two examples in the codebook if one is correct and the other incorrect. } \references{ Kohonen, T. (1990) The self-organizing map. \emph{Proc. IEEE} \bold{78}, 1464--1480. Kohonen, T. (1995) \emph{Self-Organizing Maps.} Springer, Berlin. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{lvqinit}}, \code{\link{lvq1}}, \code{\link{olvq1}}, \code{\link{lvq3}}, \code{\link{lvqtest}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) cd <- lvqinit(train, cl, 10) lvqtest(cd, train) cd0 <- olvq1(train, cl, cd) lvqtest(cd0, train) cd2 <- lvq2(train, cl, cd0) lvqtest(cd2, train) } \keyword{classif} class/man/lvqtest.Rd0000644000176000001440000000162011754562034014161 0ustar ripleyusers% file class/man/lvqtest.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{lvqtest} \alias{lvqtest} \title{ Classify Test Set from LVQ Codebook } \description{ Classify a test set by 1-NN from a specified LVQ codebook. } \usage{ lvqtest(codebk, test) } \arguments{ \item{codebk}{ codebook object returned by other LVQ software } \item{test}{ matrix of test examples }} \value{ Factor of classification for each row of \code{x} } \details{ Uses 1-NN to classify each test example against the codebook. } \references{ Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{lvqinit}}, \code{\link{olvq1}} } \examples{ # The function is currently defined as function(codebk, test) knn1(codebk$x, test, codebk$cl) } \keyword{classif} class/man/multiedit.Rd0000644000176000001440000000300511754562034014456 0ustar ripleyusers% file class/man/multiedit.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{multiedit} \alias{multiedit} \title{ Multiedit for k-NN Classifier } \description{ Multiedit for k-NN classifier } \usage{ multiedit(x, class, k = 1, V = 3, I = 5, trace = TRUE) } \arguments{ \item{x}{ matrix of training set. } \item{class}{ vector of classification of training set. } \item{k}{ number of neighbours used in k-NN. } \item{V}{ divide training set into V parts. } \item{I}{ number of null passes before quitting. } \item{trace}{ logical for statistics at each pass. }} \value{ Index vector of cases to be retained. } \references{ P. A. Devijver and J. Kittler (1982) \emph{Pattern Recognition. A Statistical Approach.} Prentice-Hall, p. 115. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{condense}}, \code{\link{reduce.nn}} } \examples{ tr <- sample(1:50, 25) train <- rbind(iris3[tr,,1], iris3[tr,,2], iris3[tr,,3]) test <- rbind(iris3[-tr,,1], iris3[-tr,,2], iris3[-tr,,3]) cl <- factor(c(rep(1,25),rep(2,25), rep(3,25)), labels=c("s", "c", "v")) table(cl, knn(train, test, cl, 3)) ind1 <- multiedit(train, cl, 3) length(ind1) table(cl, knn(train[ind1, , drop=FALSE], test, cl[ind1], 1)) ntrain <- train[ind1,]; ncl <- cl[ind1] ind2 <- condense(ntrain, ncl) length(ind2) table(cl, knn(ntrain[ind2, , drop=FALSE], test, ncl[ind2], 1)) } \keyword{classif} class/man/knn1.Rd0000644000176000001440000000235412536607645013342 0ustar ripleyusers% file class/man/knn1.Rd % copyright (C) 1994-2015 W. N. Venables and B. D. Ripley % \name{knn1} \alias{knn1} \title{ 1-Nearest Neighbour Classification } \description{ Nearest neighbour classification for test set from training set. For each row of the test set, the nearest (by Euclidean distance) training set vector is found, and its classification used. If there is more than one nearest, a majority vote is used with ties broken at random. } \usage{ knn1(train, test, cl) } \arguments{ \item{train}{ matrix or data frame of training set cases. } \item{test}{ matrix or data frame of test set cases. A vector will be interpreted as a row vector for a single case. } \item{cl}{ factor of true classification of training set. }} \value{ Factor of classifications of test set. } \references{ Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{knn}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) knn1(train, test, cl) } \keyword{classif} class/man/lvqinit.Rd0000644000176000001440000000345411754562034014154 0ustar ripleyusers% file class/man/lvqinit.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{lvqinit} \alias{lvqinit} \title{ Initialize a LVQ Codebook } \description{ Construct an initial codebook for LVQ methods. } \usage{ lvqinit(x, cl, size, prior, k = 5) } \arguments{ \item{x}{ a matrix or data frame of training examples, \code{n} by \code{p}. } \item{cl}{ the classifications for the training examples. A vector or factor of length \code{n}. } \item{size}{ the size of the codebook. Defaults to \code{min(round(0.4*ng*(ng-1 + p/2),0), n)} where \code{ng} is the number of classes. } \item{prior}{ Probabilities to represent classes in the codebook. Default proportions in the training set. } \item{k}{ k used for k-NN test of correct classification. Default is 5. }} \value{ A codebook, represented as a list with components \code{x} and \code{cl} giving the examples and classes. } \details{ Selects \code{size} examples from the training set without replacement with proportions proportional to the prior or the original proportions. } \references{ Kohonen, T. (1990) The self-organizing map. \emph{Proc. IEEE } \bold{78}, 1464--1480. Kohonen, T. (1995) \emph{Self-Organizing Maps.} Springer, Berlin. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{lvq1}}, \code{\link{lvq2}}, \code{\link{lvq3}}, \code{\link{olvq1}}, \code{\link{lvqtest}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) cd <- lvqinit(train, cl, 10) lvqtest(cd, train) cd1 <- olvq1(train, cl, cd) lvqtest(cd1, train) } \keyword{classif} class/man/lvq3.Rd0000644000176000001440000000337411754562034013354 0ustar ripleyusers% file class/man/lvq3.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{lvq3} \alias{lvq3} \title{ Learning Vector Quantization 3 } \description{ Moves examples in a codebook to better represent the training set. } \usage{ lvq3(x, cl, codebk, niter = 100*nrow(codebk$x), alpha = 0.03, win = 0.3, epsilon = 0.1) } \arguments{ \item{x}{ a matrix or data frame of examples } \item{cl}{ a vector or factor of classifications for the examples } \item{codebk}{ a codebook } \item{niter}{ number of iterations } \item{alpha}{ constant for training } \item{win}{ a tolerance for the closeness of the two nearest vectors. } \item{epsilon}{ proportion of move for correct vectors }} \value{ A codebook, represented as a list with components \code{x} and \code{cl} giving the examples and classes. } \details{ Selects \code{niter} examples at random with replacement, and adjusts the nearest two examples in the codebook for each. } \references{ Kohonen, T. (1990) The self-organizing map. \emph{Proc. IEEE} \bold{78}, 1464--1480. Kohonen, T. (1995) \emph{Self-Organizing Maps.} Springer, Berlin. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{lvqinit}}, \code{\link{lvq1}}, \code{\link{olvq1}}, \code{\link{lvq2}}, \code{\link{lvqtest}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) cd <- lvqinit(train, cl, 10) lvqtest(cd, train) cd0 <- olvq1(train, cl, cd) lvqtest(cd0, train) cd3 <- lvq3(train, cl, cd0) lvqtest(cd3, train) } \keyword{classif} class/man/reduce.nn.Rd0000644000176000001440000000266312363133311014335 0ustar ripleyusers% file class/man/reduce.nn.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{reduce.nn} \alias{reduce.nn} \title{ Reduce Training Set for a k-NN Classifier } \description{ Reduce training set for a k-NN classifier. Used after \code{condense}. } \usage{ reduce.nn(train, ind, class) } \arguments{ \item{train}{ matrix for training set } \item{ind}{ Initial list of members of the training set (from \code{condense}). } \item{class}{ vector of classifications for test set }} \details{ All the members of the training set are tried in random order. Any which when dropped do not cause any members of the training set to be wrongly classified are dropped. } \value{ Index vector of cases to be retained. } \references{ Gates, G.W. (1972) The reduced nearest neighbor rule. \emph{IEEE Trans. Information Theory} \bold{IT-18}, 431--432. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{condense}}, \code{\link{multiedit}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) keep <- condense(train, cl) knn(train[keep,], test, cl[keep]) keep2 <- reduce.nn(train, keep, cl) knn(train[keep2,], test, cl[keep2]) } \keyword{classif} class/man/somgrid.Rd0000644000176000001440000000241611754562034014127 0ustar ripleyusers% file class/man/somgrid.Rd % copyright (C) 2002 W. N. Venables and B. D. Ripley % \name{somgrid} \alias{somgrid} \alias{plot.somgrid} \alias{plot.SOM} \title{ Plot SOM Fits } \description{ Plotting functions for SOM results. } \usage{ somgrid(xdim = 8, ydim = 6, topo = c("rectangular", "hexagonal")) \method{plot}{somgrid}(x, type = "p", ...) \method{plot}{SOM}(x, ...) } \arguments{ \item{xdim, ydim}{dimensions of the grid} \item{topo}{the topology of the grid.} \item{x}{an object inheriting from class \code{"somgrid"} or \code{"SOM"}.} \item{type, \dots}{graphical parameters.} } \value{ For \code{somgrid}, an object of class \code{"somgrid"}, a list with components \item{pts}{a two-column matrix giving locations for the grid points.} \item{xdim, ydim, topo}{as in the arguments to \code{somgrid}.} } \details{ The class \code{"somgrid"} records the coordinates of the grid to be used for (batch or on-line) SOM: this has a plot method. The plot method for class \code{"SOM"} plots a \code{\link{stars}} plot of the representative at each grid point. } \references{ Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{batchSOM}}, \code{\link{SOM}} } \keyword{classif} class/man/knn.Rd0000644000176000001440000000400011754562034013240 0ustar ripleyusers% file class/man/knn.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{knn} \alias{knn} \title{ k-Nearest Neighbour Classification } \description{ k-nearest neighbour classification for test set from training set. For each row of the test set, the \code{k} nearest (in Euclidean distance) training set vectors are found, and the classification is decided by majority vote, with ties broken at random. If there are ties for the \code{k}th nearest vector, all candidates are included in the vote. } \usage{ knn(train, test, cl, k = 1, l = 0, prob = FALSE, use.all = TRUE) } \arguments{ \item{train}{ matrix or data frame of training set cases. } \item{test}{ matrix or data frame of test set cases. A vector will be interpreted as a row vector for a single case. } \item{cl}{ factor of true classifications of training set } \item{k}{ number of neighbours considered. } \item{l}{ minimum vote for definite decision, otherwise \code{doubt}. (More precisely, less than \code{k-l} dissenting votes are allowed, even if \code{k} is increased by ties.) } \item{prob}{ If this is true, the proportion of the votes for the winning class are returned as attribute \code{prob}. } \item{use.all}{ controls handling of ties. If true, all distances equal to the \code{k}th largest are included. If false, a random selection of distances equal to the \code{k}th is chosen to use exactly \code{k} neighbours. }} \value{ Factor of classifications of test set. \code{doubt} will be returned as \code{NA}. } \references{ Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{knn1}}, \code{\link{knn.cv}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) knn(train, test, cl, k = 3, prob=TRUE) attributes(.Last.value) } \keyword{classif} class/man/knn.cv.Rd0000644000176000001440000000362011754562034013656 0ustar ripleyusers% file class/man/knn.cv.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{knn.cv} \alias{knn.cv} \title{ k-Nearest Neighbour Cross-Validatory Classification } \description{ k-nearest neighbour cross-validatory classification from training set. } \usage{ knn.cv(train, cl, k = 1, l = 0, prob = FALSE, use.all = TRUE) } \arguments{ \item{train}{ matrix or data frame of training set cases. } \item{cl}{ factor of true classifications of training set } \item{k}{ number of neighbours considered. } \item{l}{ minimum vote for definite decision, otherwise \code{doubt}. (More precisely, less than \code{k-l} dissenting votes are allowed, even if \code{k} is increased by ties.) } \item{prob}{ If this is true, the proportion of the votes for the winning class are returned as attribute \code{prob}. } \item{use.all}{ controls handling of ties. If true, all distances equal to the \code{k}th largest are included. If false, a random selection of distances equal to the \code{k}th is chosen to use exactly \code{k} neighbours. }} \details{ This uses leave-one-out cross validation. For each row of the training set \code{train}, the \code{k} nearest (in Euclidean distance) other training set vectors are found, and the classification is decided by majority vote, with ties broken at random. If there are ties for the \code{k}th nearest vector, all candidates are included in the vote. } \value{ Factor of classifications of training set. \code{doubt} will be returned as \code{NA}. } \references{ Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{knn}} } \examples{ train <- rbind(iris3[,,1], iris3[,,2], iris3[,,3]) cl <- factor(c(rep("s",50), rep("c",50), rep("v",50))) knn.cv(train, cl, k = 3, prob = TRUE) attributes(.Last.value) } \keyword{classif} class/man/SOM.Rd0000644000176000001440000000454211754562034013123 0ustar ripleyusers% file class/man/SOM.Rd % copyright (C) 2002 W. N. Venables and B. D. Ripley % \name{SOM} \alias{SOM} \title{ Self-Organizing Maps: Online Algorithm } \description{ Kohonen's Self-Organizing Maps are a crude form of multidimensional scaling. } \usage{ SOM(data, grid = somgrid(), rlen = 10000, alpha, radii, init) } \arguments{ \item{data}{ a matrix or data frame of observations, scaled so that Euclidean distance is appropriate. } \item{grid}{ A grid for the representatives: see \code{\link{somgrid}}. } \item{rlen}{ the number of updates: used only in the defaults for \code{alpha} and \code{radii}. } \item{alpha}{ the amount of change: one update is done for each element of \code{alpha}. Default is to decline linearly from 0.05 to 0 over \code{rlen} updates. } \item{radii}{ the radii of the neighbourhood to be used for each update: must be the same length as \code{alpha}. Default is to decline linearly from 4 to 1 over \code{rlen} updates. } \item{init}{ the initial representatives. If missing, chosen (without replacement) randomly from \code{data}. }} \value{ An object of class \code{"SOM"} with components \item{grid}{ the grid, an object of class \code{"somgrid"}. } \item{codes}{ a matrix of representatives. }} \details{ \code{alpha} and \code{radii} can also be lists, in which case each component is used in turn, allowing two- or more phase training. } \seealso{ \code{\link{somgrid}}, \code{\link{batchSOM}} } \references{ Kohonen, T. (1995) \emph{Self-Organizing Maps.} Springer-Verlag Kohonen, T., Hynninen, J., Kangas, J. and Laaksonen, J. (1996) \emph{SOM PAK: The self-organizing map program package.} Laboratory of Computer and Information Science, Helsinki University of Technology, Technical Report A31. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \examples{ require(graphics) data(crabs, package = "MASS") lcrabs <- log(crabs[, 4:8]) crabs.grp <- factor(c("B", "b", "O", "o")[rep(1:4, rep(50,4))]) gr <- somgrid(topo = "hexagonal") crabs.som <- SOM(lcrabs, gr) plot(crabs.som) ## 2-phase training crabs.som2 <- SOM(lcrabs, gr, alpha = list(seq(0.05, 0, len = 1e4), seq(0.02, 0, len = 1e5)), radii = list(seq(8, 1, len = 1e4), seq(4, 1, len = 1e5))) plot(crabs.som2) } \keyword{classif} class/man/olvq1.Rd0000644000176000001440000000306111754562034013522 0ustar ripleyusers% file class/man/olvq1.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{olvq1} \alias{olvq1} \title{ Optimized Learning Vector Quantization 1 } \description{ Moves examples in a codebook to better represent the training set. } \usage{ olvq1(x, cl, codebk, niter = 40 * nrow(codebk$x), alpha = 0.3) } \arguments{ \item{x}{ a matrix or data frame of examples } \item{cl}{ a vector or factor of classifications for the examples } \item{codebk}{ a codebook } \item{niter}{ number of iterations } \item{alpha}{ constant for training }} \value{ A codebook, represented as a list with components \code{x} and \code{cl} giving the examples and classes. } \details{ Selects \code{niter} examples at random with replacement, and adjusts the nearest example in the codebook for each. } \references{ Kohonen, T. (1990) The self-organizing map. \emph{Proc. IEEE} \bold{78}, 1464--1480. Kohonen, T. (1995) \emph{Self-Organizing Maps.} Springer, Berlin. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{lvqinit}}, \code{\link{lvqtest}}, \code{\link{lvq1}}, \code{\link{lvq2}}, \code{\link{lvq3}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) cd <- lvqinit(train, cl, 10) lvqtest(cd, train) cd1 <- olvq1(train, cl, cd) lvqtest(cd1, train) } \keyword{classif} class/man/batchSOM.Rd0000644000176000001440000000363111754562034014123 0ustar ripleyusers% file class/man/batchSOM.Rd % copyright (C) 2002 W. N. Venables and B. D. Ripley % \name{batchSOM} \alias{batchSOM} \title{ Self-Organizing Maps: Batch Algorithm } \description{ Kohonen's Self-Organizing Maps are a crude form of multidimensional scaling. } \usage{ batchSOM(data, grid = somgrid(), radii, init) } \arguments{ \item{data}{ a matrix or data frame of observations, scaled so that Euclidean distance is appropriate. } \item{grid}{ A grid for the representatives: see \code{\link{somgrid}}. } \item{radii}{ the radii of the neighbourhood to be used for each pass: one pass is run for each element of \code{radii}. } \item{init}{ the initial representatives. If missing, chosen (without replacement) randomly from \code{data}. } } \value{ An object of class \code{"SOM"} with components \item{grid}{the grid, an object of class \code{"somgrid"}.} \item{codes}{a matrix of representatives.} } \details{ The batch SOM algorithm of Kohonen(1995, section 3.14) is used. } \seealso{ \code{\link{somgrid}}, \code{\link{SOM}} } \references{ Kohonen, T. (1995) \emph{Self-Organizing Maps.} Springer-Verlag. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \examples{ require(graphics) data(crabs, package = "MASS") lcrabs <- log(crabs[, 4:8]) crabs.grp <- factor(c("B", "b", "O", "o")[rep(1:4, rep(50,4))]) gr <- somgrid(topo = "hexagonal") crabs.som <- batchSOM(lcrabs, gr, c(4, 4, 2, 2, 1, 1, 1, 0, 0)) plot(crabs.som) bins <- as.numeric(knn1(crabs.som$code, lcrabs, 0:47)) plot(crabs.som$grid, type = "n") symbols(crabs.som$grid$pts[, 1], crabs.som$grid$pts[, 2], circles = rep(0.4, 48), inches = FALSE, add = TRUE) text(crabs.som$grid$pts[bins, ] + rnorm(400, 0, 0.1), as.character(crabs.grp)) } \keyword{classif} class/man/condense.Rd0000644000176000001440000000276111754562034014264 0ustar ripleyusers% file class/man/condense.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{condense} \alias{condense} \title{ Condense training set for k-NN classifier } \description{ Condense training set for k-NN classifier } \usage{ condense(train, class, store, trace = TRUE) } \arguments{ \item{train}{ matrix for training set } \item{class}{ vector of classifications for test set } \item{store}{ initial store set. Default one randomly chosen element of the set. } \item{trace}{ logical. Trace iterations? }} \details{ The store set is used to 1-NN classify the rest, and misclassified patterns are added to the store set. The whole set is checked until no additions occur. } \value{ Index vector of cases to be retained (the final store set). } \references{ P. A. Devijver and J. Kittler (1982) \emph{Pattern Recognition. A Statistical Approach.} Prentice-Hall, pp. 119--121. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{reduce.nn}}, \code{\link{multiedit}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) keep <- condense(train, cl) knn(train[keep, , drop=FALSE], test, cl[keep]) keep2 <- reduce.nn(train, keep, cl) knn(train[keep2, , drop=FALSE], test, cl[keep2]) } \keyword{classif} class/man/lvq1.Rd0000644000176000001440000000313011754562034013340 0ustar ripleyusers% file class/man/lvq1.Rd % copyright (C) 1994-9 W. N. Venables and B. D. Ripley % \name{lvq1} \alias{lvq1} \title{ Learning Vector Quantization 1 } \description{ Moves examples in a codebook to better represent the training set. } \usage{ lvq1(x, cl, codebk, niter = 100 * nrow(codebk$x), alpha = 0.03) } \arguments{ \item{x}{ a matrix or data frame of examples } \item{cl}{ a vector or factor of classifications for the examples } \item{codebk}{ a codebook } \item{niter}{ number of iterations } \item{alpha}{ constant for training }} \value{ A codebook, represented as a list with components \code{x} and \code{cl} giving the examples and classes. } \details{ Selects \code{niter} examples at random with replacement, and adjusts the nearest example in the codebook for each. } \references{ Kohonen, T. (1990) The self-organizing map. \emph{Proc. IEEE } \bold{78}, 1464--1480. Kohonen, T. (1995) \emph{Self-Organizing Maps.} Springer, Berlin. Ripley, B. D. (1996) \emph{Pattern Recognition and Neural Networks.} Cambridge. Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{lvqinit}}, \code{\link{olvq1}}, \code{\link{lvq2}}, \code{\link{lvq3}}, \code{\link{lvqtest}} } \examples{ train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3]) test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3]) cl <- factor(c(rep("s",25), rep("c",25), rep("v",25))) cd <- lvqinit(train, cl, 10) lvqtest(cd, train) cd0 <- olvq1(train, cl, cd) lvqtest(cd0, train) cd1 <- lvq1(train, cl, cd0) lvqtest(cd1, train) } \keyword{classif} class/DESCRIPTION0000644000176000001440000000143214167756466013143 0ustar ripleyusersPackage: class Priority: recommended Version: 7.3-20 Date: 2022-01-12 Depends: R (>= 3.0.0), stats, utils Imports: MASS Authors@R: c(person("Brian", "Ripley", role = c("aut", "cre", "cph"), email = "ripley@stats.ox.ac.uk"), person("William", "Venables", role = "cph")) Description: Various functions for classification, including k-nearest neighbour, Learning Vector Quantization and Self-Organizing Maps. Title: Functions for Classification ByteCompile: yes License: GPL-2 | GPL-3 URL: http://www.stats.ox.ac.uk/pub/MASS4/ NeedsCompilation: yes Packaged: 2022-01-13 05:06:38 UTC; ripley Author: Brian Ripley [aut, cre, cph], William Venables [cph] Maintainer: Brian Ripley Repository: CRAN Date/Publication: 2022-01-13 08:05:10 UTC class/src/0000755000176000001440000000000014167623411012203 5ustar ripleyusersclass/src/class.c0000644000176000001440000002634114167623411013462 0ustar ripleyusers/* * class/src/class.c by W. N. Venables and B. D. Ripley Copyright (C) 1994-2022 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 or 3 of the License * (at your option). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * A copy of the GNU General Public License is available at * http://www.r-project.org/Licenses/ * */ #include // currently in R.h #include #include #include #define EPS 1e-4 /* relative test of equality of distances */ #define RANDIN GetRNGstate() #define RANDOUT PutRNGstate() #define UNIF unif_rand() void VR_knn1(Sint *pntr, Sint *pnte, Sint *p, double *train, Sint *class, double *test, Sint *res, Sint *votes, Sint *nc, double *dists) { int npat, index, i, j, k, ntr = *pntr, nte = *pnte, nind=0, ntie, *ind; double dm, dist, tmp; RANDIN; ind = R_Calloc(ntr, int); for (npat = 0; npat < nte; npat++) { dm = DBL_MAX; // was DOUBLE_XMAX; for (j = 0; j < ntr; j++) { dist = 0.0; for (k = 0; k < *p; k++) { tmp = test[npat + k * nte] - train[j + k * ntr]; dist += tmp * tmp; } if (dist <= dm * (1 + EPS)) { if (dist < dm * (1 - EPS)) nind = 0; else nind++; dm = dist; ind[nind] = j; } } for (i = 1; i <= *nc; i++) votes[i] = 0; /* nind is the number of tied minima, minus one */ if (nind == 0) index = class[ind[0]]; else { for (i = 0; i <= nind; i++) votes[class[ind[i]]]++; j = votes[1]; /* This uses 'reservoir sampling' to choose amongst ties at random on a single pass. */ index = 1; ntie = 1; for (i = 2; i <= *nc; i++) if (votes[i] > j) { ntie = 1; index = i; j = votes[i]; } else if (votes[i] == j) { if (++ntie * UNIF < 1.0) index = i; } } res[npat] = index; dists[npat] = dm; } RANDOUT; R_Free(ind); } #define MAX_TIES 1000 /* Not worth doing this dynamically -- limits k + # ties + fence, in fact */ void VR_knn(Sint *kin, Sint *lin, Sint *pntr, Sint *pnte, Sint *p, double *train, Sint *class, double *test, Sint *res, double *pr, Sint *votes, Sint *nc, Sint *cv, Sint *use_all) { int i, index, j, k, k1, kinit = *kin, kn, l = *lin, mm, npat, ntie, ntr = *pntr, nte = *pnte, extras; int pos[MAX_TIES], nclass[MAX_TIES]; int j1, j2, needed, t; double dist, tmp, nndist[MAX_TIES]; RANDIN; /* Use a 'fence' in the (k+1)st position to avoid special cases. Simple insertion sort will suffice since k will be small. */ for (npat = 0; npat < nte; npat++) { kn = kinit; for (k = 0; k < kn; k++) nndist[k] = 0.99 * DBL_MAX; for (j = 0; j < ntr; j++) { if ((*cv > 0) && (j == npat)) continue; dist = 0.0; for (k = 0; k < *p; k++) { tmp = test[npat + k * nte] - train[j + k * ntr]; dist += tmp * tmp; } /* Use 'fuzz' since distance computed could depend on order of coordinates */ if (dist <= nndist[kinit - 1] * (1 + EPS)) for (k = 0; k <= kn; k++) if (dist < nndist[k]) { for (k1 = kn; k1 > k; k1--) { nndist[k1] = nndist[k1 - 1]; pos[k1] = pos[k1 - 1]; } nndist[k] = dist; pos[k] = j; /* Keep an extra distance if the largest current one ties with current kth */ if (nndist[kn] <= nndist[kinit - 1]) if (++kn == MAX_TIES - 1) error("too many ties in knn"); break; } nndist[kn] = 0.99 * DBL_MAX; } for (j = 0; j <= *nc; j++) votes[j] = 0; if (*use_all) { for (j = 0; j < kinit; j++) votes[class[pos[j]]]++; extras = 0; for (j = kinit; j < kn; j++) { if (nndist[j] > nndist[kinit - 1] * (1 + EPS)) break; extras++; votes[class[pos[j]]]++; } } else { /* break ties at random */ extras = 0; for (j = 0; j < kinit; j++) { if (nndist[j] >= nndist[kinit - 1] * (1 - EPS)) break; votes[class[pos[j]]]++; } j1 = j; if (j1 == kinit - 1) { /* no ties for largest */ votes[class[pos[j1]]]++; } else { /* Use reservoir sampling to choose amongst the tied distances */ j1 = j; needed = kinit - j1; for (j = 0; j < needed; j++) nclass[j] = class[pos[j1 + j]]; t = needed; for (j = j1 + needed; j < kn; j++) { if (nndist[j] > nndist[kinit - 1] * (1 + EPS)) break; if (++t * UNIF < needed) { j2 = j1 + (int) (UNIF * needed); nclass[j2] = class[pos[j]]; } } for (j = 0; j < needed; j++) votes[nclass[j]]++; } } /* Use reservoir sampling to choose amongst the tied votes */ ntie = 1; if (l > 0) mm = l - 1 + extras; else mm = 0; index = 0; for (i = 1; i <= *nc; i++) if (votes[i] > mm) { ntie = 1; index = i; mm = votes[i]; } else if (votes[i] == mm && votes[i] >= l) { if (++ntie * UNIF < 1.0) index = i; } res[npat] = index; pr[npat] = (double) mm / (kinit + extras); } RANDOUT; } #define min9(a,b) ((a < b)?a:b) void VR_olvq(double *alpha, Sint *pn, Sint *p, double *x, Sint *cl, Sint *pncodes, double *xc, Sint *clc, Sint *niter, Sint *iters) { int index=0, iter, j, k, n = *pn, ncodes = *pncodes, npat, s; double *al; double dist, dm, tmp; al = R_Calloc(ncodes, double); for (j = 0; j < ncodes; j++) al[j] = *alpha; for (iter = 0; iter < *niter; iter++) { npat = iters[iter]; dm = DBL_MAX; for (j = 0; j < ncodes; j++) { dist = 0.0; for (k = 0; k < *p; k++) { tmp = x[npat + k * n] - xc[j + k * ncodes]; dist += tmp * tmp; } if (dist < dm) { dm = dist; index = j; } } s = 2 * (clc[index] == cl[npat]) - 1; for (k = 0; k < *p; k++) xc[index + k * ncodes] += s * al[index] * (x[npat + k * n] - xc[index + k * ncodes]); al[index] = min9(*alpha, al[index] / (1 + s * al[index])); } R_Free(al); } void VR_lvq1(double *alpha, Sint *pn, Sint *p, double *x, Sint *cl, Sint *pncodes, double *xc, Sint *clc, Sint *niter, Sint *iters) { int index = 0, iter, j, k, n = *pn, ncodes = *pncodes, npat, s; double alpha_t; double dist, dm, tmp; for (iter = 0; iter < *niter; iter++) { npat = iters[iter]; alpha_t = *alpha * (*niter - iter) / (double) *niter; dm = DBL_MAX; for (j = 0; j < ncodes; j++) { dist = 0.0; for (k = 0; k < *p; k++) { tmp = x[npat + k * n] - xc[j + k * ncodes]; dist += tmp * tmp; } if (dist < dm) { dm = dist; index = j; } } s = 2 * (clc[index] == cl[npat]) - 1; for (k = 0; k < *p; k++) xc[index + k * ncodes] += s * alpha_t * (x[npat + k * n] - xc[index + k * ncodes]); } } void VR_lvq2(double *alpha, double *win, Sint *pn, Sint *p, double *x, Sint *cl, Sint *pncodes, double *xc, Sint *clc, Sint *niter, Sint *iters) { int index = 0, iter, j, k, n = *pn, ncodes = *pncodes, nindex = 0, npat, ntmp; double alpha_t; double dist, dm, ndm, tmp; for (iter = 0; iter < *niter; iter++) { npat = iters[iter]; alpha_t = *alpha * (*niter - iter) / (double) *niter; ndm = dm = DBL_MAX; /* Find two nearest codebook vectors */ for (j = 0; j < ncodes; j++) { dist = 0.0; for (k = 0; k < *p; k++) { tmp = x[npat + k * n] - xc[j + k * ncodes]; dist += tmp * tmp; } if (dist < dm) { ndm = dm; nindex = index; dm = dist; index = j; } else if (dist < ndm) { ndm = dist; nindex = j; } } if (clc[index] != clc[nindex]) { if (((clc[index] == cl[npat]) || (clc[nindex] == cl[npat])) && dm / ndm > (1 - *win) / (1 + *win)) { if (clc[nindex] == cl[npat]) { ntmp = index; index = nindex; nindex = ntmp; } for (k = 0; k < *p; k++) { xc[index + k * ncodes] += alpha_t * (x[npat + k * n] - xc[index + k * ncodes]); xc[nindex + k * ncodes] -= alpha_t * (x[npat + k * n] - xc[nindex + k * ncodes]); } } } } } void VR_lvq3(double *alpha, double *win, double *epsilon, Sint *pn, Sint *p, double *x, Sint *cl, Sint *pncodes, double *xc, Sint *clc, Sint *niter, Sint *iters) { int index = 0, iter, j, k, n = *pn, ncodes = *pncodes, nindex = 0, npat, ntmp; double alpha_t; double dist, dm, ndm, tmp; for (iter = 0; iter < *niter; iter++) { npat = iters[iter]; alpha_t = *alpha * (*niter - iter) / (double) *niter; ndm = dm = DBL_MAX; /* Find two nearest codebook vectors */ for (j = 0; j < ncodes; j++) { dist = 0.0; for (k = 0; k < *p; k++) { tmp = x[npat + k * n] - xc[j + k * ncodes]; dist += tmp * tmp; } if (dist < dm) { ndm = dm; nindex = index; dm = dist; index = j; } else if (dist < ndm) { ndm = dist; nindex = j; } } if (clc[index] != clc[nindex]) { if (((clc[index] == cl[npat]) || (clc[nindex] == cl[npat])) && dm / ndm > (1 - *win) / (1 + *win)) { if (clc[nindex] == cl[npat]) { ntmp = index; index = nindex; nindex = ntmp; } for (k = 0; k < *p; k++) { xc[index + k * ncodes] += alpha_t * (x[npat + k * n] - xc[index + k * ncodes]); xc[nindex + k * ncodes] -= alpha_t * (x[npat + k * n] - xc[nindex + k * ncodes]); } } } else if (clc[index] == cl[npat]) { for (k = 0; k < *p; k++) { xc[index + k * ncodes] += *epsilon * alpha_t * (x[npat + k * n] - xc[index + k * ncodes]); xc[nindex + k * ncodes] += *epsilon * alpha_t * (x[npat + k * n] - xc[nindex + k * ncodes]); } } } } void VR_onlineSOM(double *data, double *codes, double *nhbrdist, double *alpha, double *radii, Sint *pn, Sint *pp, Sint *pncodes, Sint *rlen) { int n = *pn, p = *pp, ncodes = *pncodes; int i, j, k, nearest = 0 /* -Wall */, nind; double dm, dist, tmp; unsigned int cd; /* avoid spurious warning from gcc pre-4.3.0 */ RANDIN; for (k = 0; k < *rlen; k++) { /* pick a random data point */ i = (int)(n * UNIF); /* find the nearest code 'near' */ /* nind is the number of tied minima, unlike VR_knn1 */ nind = 1; // for compilers: set to 1 when first min found. dm = DBL_MAX; for (cd = 0; cd < ncodes; cd++) { dist = 0.0; for (j = 0; j < p; j++) { tmp = data[i + j*n] - codes[cd + j*ncodes]; dist += tmp * tmp; } if (dist <= dm * (1 + EPS)) { if (dist < dm * (1 - EPS)) { nind = 1; nearest = cd; } else { if(++nind * UNIF < 1.0) nearest = cd; } dm = dist; } /* update all codes within radii[k] of 'nearest' */ for (cd = 0; cd < ncodes; cd++) { if(nhbrdist[cd + ncodes*nearest] > radii[k]) continue; for(j = 0; j < p; j++) codes[cd + j*ncodes] += alpha[k] * (data[i + j*n] - codes[cd + j*ncodes]); } } } RANDOUT; } #include "R_ext/Rdynload.h" static const R_CMethodDef CEntries[] = { {"VR_knn", (DL_FUNC) &VR_knn, 14}, {"VR_knn1", (DL_FUNC) &VR_knn1, 10}, {"VR_lvq1", (DL_FUNC) &VR_lvq1, 10}, {"VR_lvq2", (DL_FUNC) &VR_lvq2, 11}, {"VR_lvq3", (DL_FUNC) &VR_lvq3, 12}, {"VR_olvq", (DL_FUNC) &VR_olvq, 10}, {"VR_onlineSOM", (DL_FUNC) &VR_onlineSOM, 9}, {NULL, NULL, 0} }; void R_init_class(DllInfo *dll) { R_registerRoutines(dll, CEntries, NULL, NULL, NULL); R_useDynamicSymbols(dll, FALSE); R_forceSymbols(dll, TRUE); } class/R/0000755000176000001440000000000012131311464011604 5ustar ripleyusersclass/R/knn.R0000644000176000001440000000706211754562034012535 0ustar ripleyusers# file nnet/R/knn.R # copyright (C) 1994-9 W. N. Venables and B. D. Ripley # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 or 3 of the License # (at your option). # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # A copy of the GNU General Public License is available at # http://www.r-project.org/Licenses/ # # knn1 <- function(train, test, cl) { train <- as.matrix(train) if(is.null(dim(test))) dim(test) <- c(1, length(test)) test <- as.matrix(test) if(any(is.na(train)) || any(is.na(test)) || any(is.na(cl))) stop("no missing values are allowed") p <- ncol(train) ntr <- nrow(train) if(length(cl) != ntr) stop("'train' and 'class' have different lengths") nte <- nrow(test) if(ncol(test) != p) stop("dims of 'test' and 'train' differ") clf <- as.factor(cl) nc <- max(unclass(clf)) res <- .C(VR_knn1, as.integer(ntr), as.integer(nte), as.integer(p), as.double(train), as.integer(unclass(clf)), as.double(test), res = integer(nte), integer(nc+1), as.integer(nc), d = double(nte) )$res factor(res, levels=seq_along(levels(clf)), labels=levels(clf)) } knn <- function(train, test, cl, k=1, l=0, prob=FALSE, use.all=TRUE) { train <- as.matrix(train) if(is.null(dim(test))) dim(test) <- c(1, length(test)) test <- as.matrix(test) if(any(is.na(train)) || any(is.na(test)) || any(is.na(cl))) stop("no missing values are allowed") p <- ncol(train) ntr <- nrow(train) if(length(cl) != ntr) stop("'train' and 'class' have different lengths") if(ntr < k) { warning(gettextf("k = %d exceeds number %d of patterns", k, ntr), domain = NA) k <- ntr } if (k < 1) stop(gettextf("k = %d must be at least 1", k), domain = NA) nte <- nrow(test) if(ncol(test) != p) stop("dims of 'test' and 'train' differ") clf <- as.factor(cl) nc <- max(unclass(clf)) Z <- .C(VR_knn, as.integer(k), as.integer(l), as.integer(ntr), as.integer(nte), as.integer(p), as.double(train), as.integer(unclass(clf)), as.double(test), res = integer(nte), pr = double(nte), integer(nc+1), as.integer(nc), as.integer(FALSE), as.integer(use.all) ) res <- factor(Z$res, levels=seq_along(levels(clf)),labels=levels(clf)) if(prob) attr(res, "prob") <- Z$pr res } knn.cv <- function(train, cl, k=1, l=0, prob=FALSE, use.all=TRUE) { train <- as.matrix(train) if(any(is.na(train)) || any(is.na(cl))) stop("no missing values are allowed") p <- ncol(train) ntr <- nrow(train) if(length(cl) != ntr) stop("'train' and 'class' have different lengths") if(ntr-1 < k) { warning(gettextf("k = %d exceeds number %d of patterns", k, ntr-1), domain = NA) k <- ntr - 1 } if (k < 1) stop(gettextf("k = %d must be at least 1", k), domain = NA) clf <- as.factor(cl) nc <- max(unclass(clf)) Z <- .C(VR_knn, as.integer(k), as.integer(l), as.integer(ntr), as.integer(ntr), as.integer(p), as.double(train), as.integer(unclass(clf)), as.double(train), res = integer(ntr), pr = double(ntr), integer(nc+1), as.integer(nc), as.integer(TRUE), as.integer(use.all) ) res <- factor(Z$res, levels=seq_along(levels(clf)),labels=levels(clf)) if(prob) attr(res, "prob") <- Z$pr res } class/R/zzz.R0000644000176000001440000000013711754562034012600 0ustar ripleyusers.noGenerics <- TRUE .onUnload <- function(libpath) library.dynam.unload("class", libpath) class/R/multiedit.R0000644000176000001440000000456312030071124013731 0ustar ripleyusers# file nnet/R/multiedit.R # copyright (C) 1994-9 W. N. Venables and B. D. Ripley # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 or 3 of the License # (at your option). # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # A copy of the GNU General Public License is available at # http://www.r-project.org/Licenses/ # # multiedit <- function(x, class, k=1, V=3, I=5, trace=TRUE) { n1 <- length(class) class <- unclass(class) index <- seq_len(n1) pass <- lpass <- 0L repeat{ if(n1 < 5*V) { warning("retained set is now too small to proceed") break } pass <- pass + 1L sub <- sample(V, length(class), replace=TRUE) keep <- logical(length(class)) for (i in 1L:V){ train <- sub==i test <- sub==(1 + i%%V) keep[test] <- (knn(x[train, , drop=FALSE], x[test, , drop=FALSE], class[train],k) == class[test]) } x <- x[keep, , drop=FALSE]; class <- class[keep]; index <- index[keep] n2 <- length(class) if(n2 < n1) lpass <- pass if(lpass <= pass - I) break n1 <- n2 if(trace) message(gettextf("pass %s size %d", pass, n2), domain = NA) } index } condense <- function(train, class, store=sample(seq(n), 1), trace=TRUE) { n <- length(class) bag <- rep(TRUE, n) bag[store] <- FALSE repeat { if(trace) print(seq(n)[!bag]) if(sum(bag) == 0) break res <- knn1(train[!bag,,drop = FALSE], train[bag,,drop = FALSE], class[!bag]) add <- res != class[bag] if(sum(add) == 0) break cand <- (seq(n)[bag])[add] if(length(cand) > 1L) cand <- sample(cand, 1L) bag[cand] <- FALSE } seq(n)[!bag] } reduce.nn <- function(train, ind, class) { n <- length(class) rest <- seq(n)[-ind] # this must be done iteratively, not simultaneously for(i in sample(ind)) { res <- knn1(train[-c(rest,i),,drop=FALSE], train[c(rest,i),,drop=FALSE], class[-c(rest,i)]) if(all(res == class[c(rest,i)])) rest <- c(rest,i) } seq(n)[-rest] } class/R/SOM.R0000644000176000001440000001064012030071124012360 0ustar ripleyusers# file nnet/R/SOM.R # copyright (C) W. N. Venables and B. D. Ripley # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 or 3 of the License # (at your option). # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # A copy of the GNU General Public License is available at # http://www.r-project.org/Licenses/ # batchSOM <- function(data, grid = somgrid(), radii, init) { data <- as.matrix(data) nd <- nrow(data) ng <- nrow(grid$pts) if(missing(init)) init <- data[sample(1L:nd, ng, replace = FALSE), , drop = FALSE] nhbrdist <- as.matrix(dist(grid$pts)) for(r in radii) { cl <- as.numeric(knn1(init, data, 1L:ng)) A <- (nhbrdist <= r)[, cl] ind <- rowSums(A) > 0 init[ind, ] <- A[ind, ] %*% data / rowSums(A)[ind] } structure(list(grid = grid, codes = init), class = "SOM") } somgrid <- function(xdim = 8, ydim = 6, topo = c("rectangular", "hexagonal")) { topo <- match.arg(topo) x <- 1L:xdim y <- 1L:ydim pts <- as.matrix(expand.grid(x = x, y = y)) if(topo == "hexagonal") { pts[, 1L] <- pts[, 1L] + 0.5 * (pts[, 2L] %% 2) pts[, 2L] <- sqrt(3)/2 * pts[, 2L] } res <- list(pts = pts, xdim = xdim, ydim = ydim, topo = topo) class(res) <- "somgrid" res } plot.somgrid <- function(x, type = "p", ...) { if(!inherits(x, "somgrid")) stop("wrong plot method used") MASS::eqscplot(c(0, x$xdim+(x$topo == "hexagonal") + 1), c(x$ydim + 1, 0), axes = FALSE, type = "n", xlab = "", ylab = "", ...) if(type == "p") points(x$pts, cex = 2, ...) invisible() } plot.SOM <- function(x, ...) { if(!inherits(x, "SOM")) stop("wrong plot method used") MASS::eqscplot(c(0, x$grid$xdim+(x$grid$topo == "hexagonal") + 1), c(x$grid$ydim + 1, 0), axes = FALSE, type = "n", xlab = "", ylab = "", ...) stars(x$codes, locations = x$grid$pts, labels = NULL, len = 0.5) invisible() } SOM <- function(data, grid = somgrid(), rlen = 10000, alpha = seq(0.05, 0, len = rlen), radii = seq(4, 1, len = rlen), init) { data <- as.matrix(data) nd <- nrow(data) if(!nd) stop("'SOM' called with no data") ng <- nrow(grid$pts) nphases <- 1L if(is.list(alpha)) { nphases <- length(alpha) if(!is.list(radii) || length(radii) != nphases) stop("'radii' must be a list of the same length as 'alpha'") } if(missing(init)) init <- data[sample(1L:nd, ng, replace = FALSE), , drop = FALSE] codes <- init nhbrdist <- as.matrix(dist(grid$pts)) if(nphases == 1L) { rlen <- length(alpha) if(length(radii) != rlen) stop("'alpha' and 'radii' do not have the same lengths") codes <- .C(VR_onlineSOM, data = as.double(data), codes = as.double(codes), nhbrdist = as.double(nhbrdist), alpha = as.double(alpha), radii = as.double(radii), n = as.integer(nrow(data)), p = as.integer(ncol(data)), ncodes = as.integer(nrow(init)), rlen = as.integer(rlen) )$codes } else { for(k in 1L:nphases) { rlen <- length(alpha[[k]]) if(length(radii[[k]]) != rlen) stop("'alpha' and 'radii' do not match") codes <- .C(VR_onlineSOM, data = as.double(data), codes = as.double(codes), nhbrdist = as.double(nhbrdist), alpha = as.double(alpha[[k]]), radii = as.double(radii[[k]]), n = as.integer(nrow(data)), p = as.integer(ncol(data)), ncodes = as.integer(nrow(init)), rlen = as.integer(rlen) )$codes } } dim(codes) <- dim(init) colnames(codes) <- colnames(init) structure(list(grid = grid, codes = codes), class = "SOM") } class/R/lvq.R0000644000176000001440000001174312030071124012531 0ustar ripleyusers# file nnet/R/lvq.R # copyright (C) 1994-9 W. N. Venables and B. D. Ripley # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 or 3 of the License # (at your option). # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # A copy of the GNU General Public License is available at # http://www.r-project.org/Licenses/ # # lvqinit <- function(x, cl, size, prior, k=5) { x <- as.matrix(x) n <- nrow(x) p <- ncol(x) if(length(cl) != n) stop("'x' and 'cl' have different lengths") g <- as.factor(cl) if(any(is.na(x)) || any(is.na(g))) stop("no missing values are allowed") counts <- tapply(rep(1, length(g)), g, sum) prop <- counts/n np <- length(prop) # allow for supplied prior if(missing(prior)) prior <- prop else if(any(prior <0)||round(sum(prior), 5) != 1) stop("invalid 'prior'") if(length(prior) != np) stop("'prior' is of incorrect length") if(missing(size)) size <- min(round(0.4 * np * (np-1+p/2),0), n) inside <- knn.cv(x, cl, k) == cl selected <- numeric(0) for(i in 1L:np){ set <- seq_along(g)[unclass(g)==i & inside] if(length(set) > 1L) set <- sample(set, min(length(set), round(size*prior[i]))) selected <- c(selected, set) } list(x = x[selected, , drop=FALSE], cl = cl[selected]) } olvq1 <- function(x, cl, codebk, niter = 40*nrow(codebk$x), alpha = 0.3) { x <- as.matrix(x) if(any(is.na(x)) || any(is.na(cl))) stop("no missing values are allowed") n <- nrow(x) p <- ncol(x) nc <- dim(codebk$x)[1L] if(length(cl) != n) stop("'x' and 'cl' have different lengths") iters <- sample(n, niter, TRUE) z <- .C(VR_olvq, as.double(alpha), as.integer(n), as.integer(p), as.double(x), as.integer(unclass(cl)), as.integer(nc), xc = as.double(codebk$x), as.integer(codebk$cl), as.integer(niter), as.integer(iters-1L) ) xc <- matrix(z$xc,nc,p) dimnames(xc) <- dimnames(codebk$x) list(x = xc, cl = codebk$cl) } lvq1 <- function(x, cl, codebk, niter = 100*nrow(codebk$x), alpha = 0.03) { x <- as.matrix(x) if(any(is.na(x)) || any(is.na(cl))) stop("no missing values are allowed") n <- nrow(x) p <- ncol(x) nc <- dim(codebk$x)[1L] if(length(cl) != n) stop("'x' and 'cl' have different lengths") iters <- sample(n, niter, TRUE) z <- .C(VR_lvq1, as.double(alpha), as.integer(n), as.integer(p), as.double(x), as.integer(unclass(cl)), as.integer(nc), xc = as.double(codebk$x), as.integer(codebk$cl), as.integer(niter), as.integer(iters-1L) ) xc <- matrix(z$xc,nc,p) dimnames(xc) <- dimnames(codebk$x) list(x = xc, cl = codebk$cl) } lvq2 <- function(x, cl, codebk, niter = 100*nrow(codebk$x), alpha = 0.03, win = 0.3) { x <- as.matrix(x) if(any(is.na(x)) || any(is.na(cl))) stop("no missing values are allowed") n <- nrow(x) p <- ncol(x) nc <- dim(codebk$x)[1L] if(length(cl) != n) stop("'x' and 'cl' have different lengths") iters <- sample(n, niter, TRUE) z <- .C(VR_lvq2, as.double(alpha), as.double(win), as.integer(n), as.integer(p), as.double(x), as.integer(unclass(cl)), as.integer(nc), xc = as.double(codebk$x), as.integer(codebk$cl), as.integer(niter), as.integer(iters-1L) ) xc <- matrix(z$xc,nc,p) dimnames(xc) <- dimnames(codebk$x) list(x = xc, cl = codebk$cl) } lvq3 <- function(x, cl, codebk, niter = 100*nrow(codebk$x), alpha = 0.03, win = 0.3, epsilon = 0.1) { x <- as.matrix(x) if(any(is.na(x)) || any(is.na(cl))) stop("no missing values are allowed") n <- nrow(x) p <- ncol(x) nc <- dim(codebk$x)[1L] if(length(cl) != n) stop("'x' and 'cl' have different lengths") iters <- sample(n, niter, TRUE) z <- .C(VR_lvq3, as.double(alpha), as.double(win), as.double(epsilon), as.integer(n), as.integer(p), as.double(x), as.integer(unclass(cl)), as.integer(nc), xc = as.double(codebk$x), as.integer(codebk$cl), as.integer(niter), as.integer(iters-1L) ) xc <- matrix(z$xc,nc,p) dimnames(xc) <- dimnames(codebk$x) list(x = xc, cl = codebk$cl) } lvqtest <- function(codebk, test) knn1(codebk$x, test, codebk$cl) class/MD50000644000176000001440000000355014167756466011750 0ustar ripleyusersc85caea72c963aee6dfa23c3c0309fc0 *DESCRIPTION a0e96c11b4d12e246a178ca1e77f7f7e *LICENCE.note a92febb02a17971969afc1e4e4067279 *NAMESPACE 44e5755ae2d5d1f1b8509879577c17a5 *R/SOM.R 6985c529cd8fc96dc6c91af6cc9cc964 *R/knn.R 50be3231f5443f347952d0ee4918395d *R/lvq.R acd705e760928c76dc5507dc598872e1 *R/multiedit.R 6eeaac5a4afe30bedaff5567311dc342 *R/zzz.R 4ab3c6052e2eb9bf3a52dcad7f8c805e *inst/CITATION e042788d6870b70eb8ea0bc5f01391ff *inst/NEWS ac6f3dc952201ade180517b2722076ee *inst/po/de/LC_MESSAGES/R-class.mo 8c21e08d116783358604da994fb02b75 *inst/po/en@quot/LC_MESSAGES/R-class.mo 8fb3d21d5de93757623c30023b5deec4 *inst/po/fr/LC_MESSAGES/R-class.mo f7eec3d17d381a2ade078b89ba652c14 *inst/po/it/LC_MESSAGES/R-class.mo aad7b8496526e0f154b3514e4fbb21e7 *inst/po/ko/LC_MESSAGES/R-class.mo 8d26254987ed65ce560e62c63623c82d *inst/po/pl/LC_MESSAGES/R-class.mo 4088862ce7d73759a8a754d490575c55 *man/SOM.Rd 4a2e92b20c3ae11d503519eda00a7ed7 *man/batchSOM.Rd 69d25fc468f9fd914106f8f1fb49c101 *man/condense.Rd e00177dbfe979c7296188143e8f79474 *man/knn.Rd 76475b80960431c6da3f2bb8a04c15c6 *man/knn.cv.Rd 5c80ca4e6c4cd95356edf642d43eb4bf *man/knn1.Rd d62613e784171295bf11703d708cd2b8 *man/lvq1.Rd fdfb3a7e3ed8116278a8f4fd067a8045 *man/lvq2.Rd 396eec671f1bddd185fa79831dd47ee3 *man/lvq3.Rd e70f2c5c23ddf839b5e3b1457fc6fdbd *man/lvqinit.Rd e8e077536af8608b6d5d366410bae87a *man/lvqtest.Rd 4c659dd015ed95b15223d1a62c39a745 *man/multiedit.Rd 11a66b273c6dc182cc05bb2bc53fdb54 *man/olvq1.Rd 401fc2d0327911732fd84ccd817e41e5 *man/reduce.nn.Rd 04d8b8fb49626fa41093f3b19ce5edbf *man/somgrid.Rd c696aa9a43bc8dd8daed5f2249647210 *po/R-class.pot 98593b35ec7a47e8442acbbe9feb6846 *po/R-de.po b7821605b00f996cac959aaa0e3bbe72 *po/R-fr.po 492fd736f45313a71f7ab3b491fda0a0 *po/R-it.po 161dc97e9c24260b24b9304c3f69d642 *po/R-ko.po 4fcc24f341019a4f3101815fd34f960c *po/R-pl.po afdbd484afd8f6d78a9ac578c465ed5a *src/class.c class/inst/0000755000176000001440000000000014011452563012365 5ustar ripleyusersclass/inst/CITATION0000644000176000001440000000126414011452563013525 0ustar ripleyuserscitHeader("To cite the class package in publications use:") citEntry(entry="Book", title = "Modern Applied Statistics with S", author = personList(as.person("W. N. Venables"), as.person("B. D. Ripley")), publisher = "Springer", edition = "Fourth", address = "New York", year = 2002, note = "ISBN 0-387-95457-0", url = "https://www.stats.ox.ac.uk/pub/MASS4/", textVersion = paste("Venables, W. N. & Ripley, B. D. (2002)", "Modern Applied Statistics with S.", "Fourth Edition. Springer, New York. ISBN 0-387-95457-0") ) class/inst/NEWS0000644000176000001440000000104411754562034013071 0ustar ripleyusersSoftware and datasets to support 'Modern Applied Statistics with S', fourth edition, by W. N. Venables and B. D. Ripley. Springer, 2002, ISBN 0-387-95457-0. This file documents software changes since the third edition. - fixed a bug in knn(use.all = FALSE) - added SOM, batchSOM and ancillary functions. - Bugfix in SOM (7.0-5) - knn* and lvq* explicitly check for missing values in the inputs. - knn1 was not handling ties correctly in some cases (but knn was). - added check for user error in inputs in knn.cv. - SOM segfaulted for 1D inputs. class/inst/po/0000755000176000001440000000000013636604711013011 5ustar ripleyusersclass/inst/po/ko/0000755000176000001440000000000012171733033013413 5ustar ripleyusersclass/inst/po/ko/LC_MESSAGES/0000755000176000001440000000000014036517426015210 5ustar ripleyusersclass/inst/po/ko/LC_MESSAGES/R-class.mo0000644000176000001440000000401414036517426017050 0ustar ripleyusersxy0 4*9#d!$('P<g077 5E^{>0=J6?:*:eTuA   'SOM' called with no data'alpha' and 'radii' do not have the same lengths'alpha' and 'radii' do not match'prior' is of incorrect length'radii' must be a list of the same length as 'alpha''train' and 'class' have different lengths'x' and 'cl' have different lengthsdims of 'test' and 'train' differinvalid 'prior'k = %d exceeds number %d of patternsk = %d must be at least 1no missing values are allowedpass %s size %dretained set is now too small to proceedwrong plot method usedProject-Id-Version: class 7.3-5 PO-Revision-Date: 2015-02-06 21:56-0600 Last-Translator:Chel Hee Lee Language-Team: Chel Hee Lee Language: ko MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=1; plural=0; 데이터 없이 'SOM'이 호출되었습니다.'alpha'의 길이가 'radii'의 길이가 다릅니다.'alpha'와 'radii'가 서로 일치하지 않습니다.입력된 'prior'의 길이가 잘못되었습니다.'radii'는 반드시 'alpha'와 같은 길이를 가지는 리스트(list)이어야 합니다.'train'의 길이와 'class'의 길이가 서로 다릅니다.'x'의 길이와 'cl'의 길이가 다릅니다.'test'의 차원과 'train'의 차원이 서로 다릅니다.입력된 'prior'의 값이 올바르지 않습니다.입력된 k = %1$d는 패턴의 개수 %2$d를 초과합니다.k = %d는 반드시 적어도 1 이상이어야 합니다.결측값들이 있어서는 안됩니다.pass %s size %d얻어진 세트(set)가 현재 너무 작아 더 이상 진행할 수 없습니다.사용된 플랏 메소드(plot method)가 잘못되었습니다.class/inst/po/fr/0000755000176000001440000000000012131311463013404 5ustar ripleyusersclass/inst/po/fr/LC_MESSAGES/0000755000176000001440000000000014036517426015206 5ustar ripleyusersclass/inst/po/fr/LC_MESSAGES/R-class.mo0000644000176000001440000000350514036517426017052 0ustar ripleyusersxy0 4*9#d!$('Pg. ':"b:1*1O,`$:%   'SOM' called with no data'alpha' and 'radii' do not have the same lengths'alpha' and 'radii' do not match'prior' is of incorrect length'radii' must be a list of the same length as 'alpha''train' and 'class' have different lengths'x' and 'cl' have different lengthsdims of 'test' and 'train' differinvalid 'prior'k = %d exceeds number %d of patternsk = %d must be at least 1no missing values are allowedpass %s size %dretained set is now too small to proceedwrong plot method usedProject-Id-Version: class 7.2-20 Report-Msgid-Bugs-To: bugs@r-project.org PO-Revision-Date: 2021-04-12 18:48+0200 Last-Translator: Philippe Grosjean Language-Team: French Language: fr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n > 1); X-Generator: Poedit 2.4.2 'SOM' appelé sans données'alpha' et 'radii' n'ont pas la même longueur'alpha' et 'radii' ne correspondent pas'prior' est de longueur incorrecte'radii' doit être une liste de même longueur que 'alpha''train' et 'class' ont des longueurs différentes'x' et 'cl' ont des longueurs différentesles dimensions de 'test' et de 'train' diffèrent'prior' invalidek = %d est supérieur au nombre %d de motifsk = %d doit être au moins 1aucune valeur manquante n'est admisepassage %s taille %dl'ensemble retenu est maintenant trop petit pour continuertype de méthode graphique incorrecteclass/inst/po/it/0000755000176000001440000000000013636604711013425 5ustar ripleyusersclass/inst/po/it/LC_MESSAGES/0000755000176000001440000000000014036517426015213 5ustar ripleyusersclass/inst/po/it/LC_MESSAGES/R-class.mo0000644000176000001440000000344514036517426017062 0ustar ripleyusersxy0 4*9#d!$('P{g1#/"S@v,%. 9&Ls"5&   'SOM' called with no data'alpha' and 'radii' do not have the same lengths'alpha' and 'radii' do not match'prior' is of incorrect length'radii' must be a list of the same length as 'alpha''train' and 'class' have different lengths'x' and 'cl' have different lengthsdims of 'test' and 'train' differinvalid 'prior'k = %d exceeds number %d of patternsk = %d must be at least 1no missing values are allowedpass %s size %dretained set is now too small to proceedwrong plot method usedProject-Id-Version: class 7.3-14 Report-Msgid-Bugs-To: bugs.r-project.org PO-Revision-Date: Last-Translator: Daniele Medri Language-Team: Italian https://github.com/dmedri/R-italian-lang Language: it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n != 1); X-Generator: Poedit 2.2.1 'SOM' chiamato senza dati'alpha' e 'radii' non hanno la medesima lunghezza'alpha' e 'radii' non corrispondono'prior' è di lunghezza incorretta'radii' dev'essere una lista della medesima lunghezza di 'alpha''train' e 'class' hanno lunghezze differenti'x' e 'cl' hanno lunghezze differentile dimensioni di 'test' e 'train' differiscono'prior' non validok = %d eccede il numero %d dei patternk = %d dev'essere almeno 1i valori mancanti non sono ammessipassa %s dimensione %dil set conservato è ora troppo piccolo per procederemetodo di plot utilizzato è sbagliatoclass/inst/po/de/0000755000176000001440000000000012131311464013366 5ustar ripleyusersclass/inst/po/de/LC_MESSAGES/0000755000176000001440000000000014036517426015167 5ustar ripleyusersclass/inst/po/de/LC_MESSAGES/R-class.mo0000644000176000001440000000353414036517426017035 0ustar ripleyusersxy0 4*9#d!$('P|g6-9gD6/;0l,!3 =   'SOM' called with no data'alpha' and 'radii' do not have the same lengths'alpha' and 'radii' do not match'prior' is of incorrect length'radii' must be a list of the same length as 'alpha''train' and 'class' have different lengths'x' and 'cl' have different lengthsdims of 'test' and 'train' differinvalid 'prior'k = %d exceeds number %d of patternsk = %d must be at least 1no missing values are allowedpass %s size %dretained set is now too small to proceedwrong plot method usedProject-Id-Version: R 2.15.2 / class 7.3-1 Report-Msgid-Bugs-To: bugs@r-project.org PO-Revision-Date: 2012-09-30 12:25+0100 Last-Translator: Chris Leick Language-Team: German Language: de MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n != 1); »SOM« ohne Daten aufgerufen»alpha« und »radii« haben nicht die gleiche Länge»alpha« und »radii« passen nicht zusammen»prior« hat falsche Länge»radii« muss eine Liste mit der gleichen Länge wie »alpha« sein»train« und »class« haben unterschiedliche Längen»x« und »cl« haben unterschiedliche LängenAbmessungen von »test« und »train« sind unterschiedlichungültiges »prior«k = %d überschreitet die Zahl %d der Musterk = %d muss mindestens 1 seinfehlende Werte sind nicht erlaubt%s übergeben, Größe %dverbliebene Menge ist nun zu klein, um fortzufahrenfalsche Ausgabemethode benutztclass/inst/po/pl/0000755000176000001440000000000012131311464013411 5ustar ripleyusersclass/inst/po/pl/LC_MESSAGES/0000755000176000001440000000000014036517426015212 5ustar ripleyusersclass/inst/po/pl/LC_MESSAGES/R-class.mo0000644000176000001440000000406414036517426017057 0ustar ripleyusersxy0 4*9#d!$('Pg#jD10J6776(&El-7)    'SOM' called with no data'alpha' and 'radii' do not have the same lengths'alpha' and 'radii' do not match'prior' is of incorrect length'radii' must be a list of the same length as 'alpha''train' and 'class' have different lengths'x' and 'cl' have different lengthsdims of 'test' and 'train' differinvalid 'prior'k = %d exceeds number %d of patternsk = %d must be at least 1no missing values are allowedpass %s size %dretained set is now too small to proceedwrong plot method usedProject-Id-Version: class 7.3-9 Report-Msgid-Bugs-To: bugs@r-project.org PO-Revision-Date: Last-Translator: Łukasz Daniel Language-Team: Łukasz Daniel Language: pl_PL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit na-Revision-Date: 2012-05-29 07:55+0100 Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); X-Poedit-SourceCharset: iso-8859-1 X-Generator: Poedit 1.5.4 'SOM' zostało wywołane bez danychargumenty 'alpha' oraz 'radii' nie posiadają tych samych długościargumenty 'alpha' oraz 'radii' nie zgadzają sięargument 'prior' posiada niepoprawną długośćargument 'radii' musi być listą tej samej długości co argument 'alpha'argumenty 'train' oraz 'class' mają różne długościargumenty 'train' oraz 'class' mają różne długościwymiary argumentów 'test' oraz 'train' różnią sięniepoprawny argument 'prior'k = %d przekracza liczbę %d ścieżekk = %d musi być co najmniej 1żadne brakujące wartości nie są dozwoloneprzekazano %s rozmiar %dzachowany zbiór jest teraz zbyt mały aby kontynuowaćbłędnie użyta metoda rysowania wykresuclass/inst/po/en@quot/0000755000176000001440000000000012131311464014411 5ustar ripleyusersclass/inst/po/en@quot/LC_MESSAGES/0000755000176000001440000000000014036517426016212 5ustar ripleyusersclass/inst/po/en@quot/LC_MESSAGES/R-class.mo0000644000176000001440000000324514036517426020057 0ustar ripleyusersxy0 4*9#d!$('Pg{8("<2[+)$7U(e   'SOM' called with no data'alpha' and 'radii' do not have the same lengths'alpha' and 'radii' do not match'prior' is of incorrect length'radii' must be a list of the same length as 'alpha''train' and 'class' have different lengths'x' and 'cl' have different lengthsdims of 'test' and 'train' differinvalid 'prior'k = %d exceeds number %d of patternsk = %d must be at least 1no missing values are allowedpass %s size %dretained set is now too small to proceedwrong plot method usedProject-Id-Version: class 7.3-19 PO-Revision-Date: 2021-04-17 09:40 Last-Translator: Automatically generated Language-Team: none MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Language: en Plural-Forms: nplurals=2; plural=(n != 1); ‘SOM’ called with no data‘alpha’ and ‘radii’ do not have the same lengths‘alpha’ and ‘radii’ do not match‘prior’ is of incorrect length‘radii’ must be a list of the same length as ‘alpha’‘train’ and ‘class’ have different lengths‘x’ and ‘cl’ have different lengthsdims of ‘test’ and ‘train’ differinvalid ‘prior’k = %d exceeds number %d of patternsk = %d must be at least 1no missing values are allowedpass %s size %dretained set is now too small to proceedwrong plot method usedclass/po/0000755000176000001440000000000014167731536012042 5ustar ripleyusersclass/po/R-ko.po0000644000176000001440000000462112466606573013217 0ustar ripleyusers# Korean translation for R class package # Recommended/class/po/R-ko.po # Maintainer: Brian Ripley # # This file is distributed under the same license as the R class package. # Chel Hee Lee , 2013-2015. # # Reviewing process is completed (26-JAN-2015) # The original source code is reviewed (26-JAN-2015) # QC: PASS # Freezing on 06-FEB-2015 for R-3.1.3 # msgid "" msgstr "" "Project-Id-Version: class 7.3-5\n" "POT-Creation-Date: 2012-10-08 10:54\n" "PO-Revision-Date: 2015-02-06 21:56-0600\n" "Last-Translator:Chel Hee Lee \n" "Language-Team: Chel Hee Lee \n" "Language: ko\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" msgid "wrong plot method used" msgstr "사용된 플랏 메소드(plot method)가 잘못되었습니다." msgid "'SOM' called with no data" msgstr "데이터 없이 'SOM'이 호출되었습니다." msgid "'radii' must be a list of the same length as 'alpha'" msgstr "'radii'는 반드시 'alpha'와 같은 길이를 가지는 리스트(list)이어야 합니다." msgid "'alpha' and 'radii' do not have the same lengths" msgstr "'alpha'의 길이가 'radii'의 길이가 다릅니다." msgid "'alpha' and 'radii' do not match" msgstr "'alpha'와 'radii'가 서로 일치하지 않습니다." msgid "no missing values are allowed" msgstr "결측값들이 있어서는 안됩니다." msgid "'train' and 'class' have different lengths" msgstr "'train'의 길이와 'class'의 길이가 서로 다릅니다." msgid "dims of 'test' and 'train' differ" msgstr "'test'의 차원과 'train'의 차원이 서로 다릅니다." msgid "k = %d exceeds number %d of patterns" msgstr "입력된 k = %1$d는 패턴의 개수 %2$d를 초과합니다." msgid "k = %d must be at least 1" msgstr "k = %d는 반드시 적어도 1 이상이어야 합니다." msgid "'x' and 'cl' have different lengths" msgstr "'x'의 길이와 'cl'의 길이가 다릅니다." msgid "invalid 'prior'" msgstr "입력된 'prior'의 값이 올바르지 않습니다." msgid "'prior' is of incorrect length" msgstr "입력된 'prior'의 길이가 잘못되었습니다." msgid "retained set is now too small to proceed" msgstr "얻어진 세트(set)가 현재 너무 작아 더 이상 진행할 수 없습니다." msgid "pass %s size %d" msgstr "pass %s size %d" class/po/R-class.pot0000644000176000001440000000212714036517426014067 0ustar ripleyusersmsgid "" msgstr "" "Project-Id-Version: class 7.3-19\n" "POT-Creation-Date: 2021-04-17 09:40\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" msgid "wrong plot method used" msgstr "" msgid "'SOM' called with no data" msgstr "" msgid "'radii' must be a list of the same length as 'alpha'" msgstr "" msgid "'alpha' and 'radii' do not have the same lengths" msgstr "" msgid "'alpha' and 'radii' do not match" msgstr "" msgid "no missing values are allowed" msgstr "" msgid "'train' and 'class' have different lengths" msgstr "" msgid "dims of 'test' and 'train' differ" msgstr "" msgid "k = %d exceeds number %d of patterns" msgstr "" msgid "k = %d must be at least 1" msgstr "" msgid "'x' and 'cl' have different lengths" msgstr "" msgid "invalid 'prior'" msgstr "" msgid "'prior' is of incorrect length" msgstr "" msgid "retained set is now too small to proceed" msgstr "" msgid "pass %s size %d" msgstr "" class/po/R-pl.po0000644000176000001440000001017512315120517013200 0ustar ripleyusersmsgid "" msgstr "" "Project-Id-Version: class 7.3-9\n" "Report-Msgid-Bugs-To: bugs@r-project.org\n" "POT-Creation-Date: 2013-03-18 09:49\n" "PO-Revision-Date: \n" "Last-Translator: Łukasz Daniel \n" "Language-Team: Łukasz Daniel \n" "Language: pl_PL\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "na-Revision-Date: 2012-05-29 07:55+0100\n" "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " "|| n%100>=20) ? 1 : 2);\n" "X-Poedit-SourceCharset: iso-8859-1\n" "X-Generator: Poedit 1.5.4\n" # class/R/SOM.R: 52 # stop("wrong plot method used") # class/R/SOM.R: 62 # stop("wrong plot method used") msgid "wrong plot method used" msgstr "błędnie użyta metoda rysowania wykresu" # class/R/SOM.R: 77 # stop("'SOM' called with no data") msgid "'SOM' called with no data" msgstr "'SOM' zostało wywołane bez danych" # class/R/SOM.R: 83 # stop("'radii' must be a list of the same length as 'alpha'") msgid "'radii' must be a list of the same length as 'alpha'" msgstr "argument 'radii' musi być listą tej samej długości co argument 'alpha'" # class/R/SOM.R: 92 # stop("'alpha' and 'radii' do not have the same lengths") msgid "'alpha' and 'radii' do not have the same lengths" msgstr "argumenty 'alpha' oraz 'radii' nie posiadają tych samych długości" # class/R/SOM.R: 108 # stop("'alpha' and 'radii' do not match") msgid "'alpha' and 'radii' do not match" msgstr "argumenty 'alpha' oraz 'radii' nie zgadzają się" # class/R/lvq.R: 26 # stop("no missing values are allowed") # class/R/lvq.R: 51 # stop("no missing values are allowed") # class/R/lvq.R: 78 # stop("no missing values are allowed") # class/R/lvq.R: 106 # stop("no missing values are allowed") # class/R/lvq.R: 135 # stop("no missing values are allowed") # class/R/knn.R: 24 # stop("no missing values are allowed") # class/R/knn.R: 53 # stop("no missing values are allowed") # class/R/knn.R: 92 # stop("no missing values are allowed") msgid "no missing values are allowed" msgstr "żadne brakujące wartości nie są dozwolone" # class/R/knn.R: 27 # stop("'train' and 'class' have different lengths") # class/R/knn.R: 56 # stop("'train' and 'class' have different lengths") # class/R/knn.R: 95 # stop("'train' and 'class' have different lengths") msgid "'train' and 'class' have different lengths" msgstr "argumenty 'train' oraz 'class' mają różne długości" # class/R/knn.R: 29 # stop("dims of 'test' and 'train' differ") # class/R/knn.R: 64 # stop("dims of 'test' and 'train' differ") msgid "dims of 'test' and 'train' differ" msgstr "wymiary argumentów 'test' oraz 'train' różnią się" # class/R/knn.R: 58 # warning(gettextf("k = %d exceeds number %d of patterns", k, ntr), domain = "R-class") # class/R/knn.R: 97 # warning(gettextf("k = %d exceeds number %d of patterns", k, ntr-1), domain = "R-class") msgid "k = %d exceeds number %d of patterns" msgstr "k = %d przekracza liczbę %d ścieżek" # class/R/knn.R: 62 # stop(gettextf("k = %d must be at least 1", k), domain = "R-class") # class/R/knn.R: 101 # stop(gettextf("k = %d must be at least 1", k), domain = "R-class") msgid "k = %d must be at least 1" msgstr "k = %d musi być co najmniej 1" # class/R/knn.R: 27 # stop("'train' and 'class' have different lengths") # class/R/knn.R: 56 # stop("'train' and 'class' have different lengths") # class/R/knn.R: 95 # stop("'train' and 'class' have different lengths") msgid "'x' and 'cl' have different lengths" msgstr "argumenty 'train' oraz 'class' mają różne długości" # class/R/lvq.R: 33 # stop("invalid 'prior'") msgid "invalid 'prior'" msgstr "niepoprawny argument 'prior'" # class/R/lvq.R: 34 # stop("'prior' is of incorrect length") msgid "'prior' is of incorrect length" msgstr "argument 'prior' posiada niepoprawną długość" # class/R/multiedit.R: 26 # warning("retained set is now too small to proceed") msgid "retained set is now too small to proceed" msgstr "zachowany zbiór jest teraz zbyt mały aby kontynuować" # class/R/multiedit.R: 43 # message(gettextf("pass %s size %d", pass, n2), domain = "R-class") msgid "pass %s size %d" msgstr "przekazano %s rozmiar %d" class/po/R-de.po0000644000176000001440000000426012032030344013145 0ustar ripleyusers# Translation of src/library/Recommended/class/R-class.pot to German # Copyright (C) 2007-2009 The R Foundation # This file is distributed under the same license as the lattice R package. # Chris Leick , 2009. # msgid "" msgstr "" "Project-Id-Version: R 2.15.2 / class 7.3-1\n" "Report-Msgid-Bugs-To: bugs@r-project.org\n" "POT-Creation-Date: 2012-09-23 17:22\n" "PO-Revision-Date: 2012-09-30 12:25+0100\n" "Last-Translator: Chris Leick \n" "Language-Team: German \n" "Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" msgid "wrong plot method used" msgstr "falsche Ausgabemethode benutzt" msgid "'SOM' called with no data" msgstr "»SOM« ohne Daten aufgerufen" msgid "'radii' must be a list of the same length as 'alpha'" msgstr "»radii« muss eine Liste mit der gleichen Länge wie »alpha« sein" msgid "'alpha' and 'radii' do not have the same lengths" msgstr "»alpha« und »radii« haben nicht die gleiche Länge" msgid "'alpha' and 'radii' do not match" msgstr "»alpha« und »radii« passen nicht zusammen" msgid "no missing values are allowed" msgstr "fehlende Werte sind nicht erlaubt" msgid "'train' and 'class' have different lengths" msgstr "»train« und »class« haben unterschiedliche Längen" msgid "dims of 'test' and 'train' differ" msgstr "Abmessungen von »test« und »train« sind unterschiedlich" msgid "k = %d exceeds number %d of patterns" msgstr "k = %d überschreitet die Zahl %d der Muster" msgid "k = %d must be at least 1" msgstr "k = %d muss mindestens 1 sein" msgid "'x' and 'cl' have different lengths" msgstr "»x« und »cl« haben unterschiedliche Längen" msgid "invalid 'prior'" msgstr "ungültiges »prior«" msgid "'prior' is of incorrect length" msgstr "»prior« hat falsche Länge" msgid "retained set is now too small to proceed" msgstr "verbliebene Menge ist nun zu klein, um fortzufahren" msgid "pass %s size %d" msgstr "%s übergeben, Größe %d" #~ msgid "dims of 'test' and 'train differ" #~ msgstr "Abmessungen von »test« und »train« sind unterschiedlich" class/po/R-it.po0000644000176000001440000000412713651251727013215 0ustar ripleyusers# R Italian translation # This file is distributed under the same license as the R package. # Copyright (C) The R Foundation. # Daniele Medri , 2005-2020. # msgid "" msgstr "" "Project-Id-Version: class 7.3-14\n" "Report-Msgid-Bugs-To: bugs.r-project.org\n" "POT-Creation-Date: 2020-03-25 07:35\n" "PO-Revision-Date: \n" "Last-Translator: Daniele Medri \n" "Language-Team: Italian https://github.com/dmedri/R-italian-lang\n" "Language: it\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 2.2.1\n" msgid "wrong plot method used" msgstr "metodo di plot utilizzato è sbagliato" msgid "'SOM' called with no data" msgstr "'SOM' chiamato senza dati" msgid "'radii' must be a list of the same length as 'alpha'" msgstr "'radii' dev'essere una lista della medesima lunghezza di 'alpha'" msgid "'alpha' and 'radii' do not have the same lengths" msgstr "'alpha' e 'radii' non hanno la medesima lunghezza" msgid "'alpha' and 'radii' do not match" msgstr "'alpha' e 'radii' non corrispondono" msgid "no missing values are allowed" msgstr "i valori mancanti non sono ammessi" msgid "'train' and 'class' have different lengths" msgstr "'train' e 'class' hanno lunghezze differenti" msgid "dims of 'test' and 'train' differ" msgstr "le dimensioni di 'test' e 'train' differiscono" msgid "k = %d exceeds number %d of patterns" msgstr "k = %d eccede il numero %d dei pattern" msgid "k = %d must be at least 1" msgstr "k = %d dev'essere almeno 1" msgid "'x' and 'cl' have different lengths" msgstr "'x' e 'cl' hanno lunghezze differenti" msgid "invalid 'prior'" msgstr "'prior' non valido" msgid "'prior' is of incorrect length" msgstr "'prior' è di lunghezza incorretta" msgid "retained set is now too small to proceed" msgstr "il set conservato è ora troppo piccolo per procedere" msgid "pass %s size %d" msgstr "passa %s dimensione %d" class/po/R-fr.po0000644000176000001440000000401614036517370013202 0ustar ripleyusers# Translation of R-class.pot to French # Copyright (C) 2005 The R Foundation # This file is distributed under the same license as the class R package. # Philippe Grosjean , 2005. # msgid "" msgstr "" "Project-Id-Version: class 7.2-20\n" "Report-Msgid-Bugs-To: bugs@r-project.org\n" "POT-Creation-Date: 2020-03-25 07:35\n" "PO-Revision-Date: 2021-04-12 18:48+0200\n" "Last-Translator: Philippe Grosjean \n" "Language-Team: French \n" "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "X-Generator: Poedit 2.4.2\n" msgid "wrong plot method used" msgstr "type de méthode graphique incorrecte" msgid "'SOM' called with no data" msgstr "'SOM' appelé sans données" msgid "'radii' must be a list of the same length as 'alpha'" msgstr "'radii' doit être une liste de même longueur que 'alpha'" msgid "'alpha' and 'radii' do not have the same lengths" msgstr "'alpha' et 'radii' n'ont pas la même longueur" msgid "'alpha' and 'radii' do not match" msgstr "'alpha' et 'radii' ne correspondent pas" msgid "no missing values are allowed" msgstr "aucune valeur manquante n'est admise" msgid "'train' and 'class' have different lengths" msgstr "'train' et 'class' ont des longueurs différentes" msgid "dims of 'test' and 'train' differ" msgstr "les dimensions de 'test' et de 'train' diffèrent" msgid "k = %d exceeds number %d of patterns" msgstr "k = %d est supérieur au nombre %d de motifs" msgid "k = %d must be at least 1" msgstr "k = %d doit être au moins 1" msgid "'x' and 'cl' have different lengths" msgstr "'x' et 'cl' ont des longueurs différentes" msgid "invalid 'prior'" msgstr "'prior' invalide" msgid "'prior' is of incorrect length" msgstr "'prior' est de longueur incorrecte" msgid "retained set is now too small to proceed" msgstr "l'ensemble retenu est maintenant trop petit pour continuer" msgid "pass %s size %d" msgstr "passage %s taille %d"