class/0000755000176000001440000000000012205127043011403 5ustar ripleyusersclass/po/0000755000176000001440000000000012204750330012021 5ustar ripleyusersclass/po/R-fr.po0000644000176000001440000000401012033036353013164 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: 2012-09-23 17:22\n" "PO-Revision-Date: 2012-10-03 15:26+0100\n" "Last-Translator: Philippe Grosjean \n" "Language-Team: French \n" "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=ISO-8859-1\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "X-Generator: Poedit 1.5.3\n" msgid "wrong plot method used" msgstr "type de mthode graphique incorrecte" msgid "'SOM' called with no data" msgstr "'SOM' appel sans donnes" msgid "'radii' must be a list of the same length as 'alpha'" msgstr "'radii' doit tre une liste de mme longueur que 'alpha'" msgid "'alpha' and 'radii' do not have the same lengths" msgstr "'alpha' et 'radii' n'ont pas la mme 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 diffrentes" msgid "dims of 'test' and 'train' differ" msgstr "les dimensions de 'test' et de 'train' diffrent" msgid "k = %d exceeds number %d of patterns" msgstr "k = %d est suprieur 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 diffrentes" 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" class/po/R-de.po0000644000176000001440000000426012032026057013153 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-class.pot0000644000176000001440000000212612121561432014053 0ustar ripleyusersmsgid "" msgstr "" "Project-Id-Version: class 7.3-6\n" "POT-Creation-Date: 2013-03-18 09:49\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.po0000644000176000001440000001026412034044542013200 0ustar ripleyusersmsgid "" msgstr "" "Project-Id-Version: class 7.3-3\n" "Report-Msgid-Bugs-To: bugs@r-project.org\n" "POT-Creation-Date: 2012-09-23 17:22\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.3\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 "'radii' musi być listą tej samej długości co '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 "'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 "'alpha' oraz 'radii' nie zgadzają się" # 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: 93 # stop("no missing values are allowed") # 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") 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: 96 # stop("'train' and 'class' have different lengths") msgid "'train' and 'class' have different lengths" msgstr "'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: 65 # stop("dims of 'test' and 'train' differ") msgid "dims of 'test' and 'train' differ" msgstr "wymiary 'test' oraz 'train' różnią się" # class/R/knn.R: 58 # warning(gettextf("k = %d exceeds number %d of patterns", k, ntr), # domain = NA) # class/R/knn.R: 98 # warning(gettextf("k = %d exceeds number %d of patterns", k, ntr-1), # domain = NA) msgid "k = %d exceeds number %d of patterns" msgstr "k = %d przekracza liczbę %d ścieżek" # class/R/knn.R: 63 # stop(gettextf("k = %d must be at least 1", k), domain = NA) # class/R/knn.R: 103 # stop(gettextf("k = %d must be at least 1", k), domain = NA) msgid "k = %d must be at least 1" msgstr "k = %d musi być co najmniej 1" # class/R/lvq.R: 23 # stop("'x' and 'cl' have different lengths") # class/R/lvq.R: 55 # stop("'x' and 'cl' have different lengths") # class/R/lvq.R: 82 # stop("'x' and 'cl' have different lengths") # class/R/lvq.R: 110 # stop("'x' and 'cl' have different lengths") # class/R/lvq.R: 139 # stop("'x' and 'cl' have different lengths") msgid "'x' and 'cl' have different lengths" msgstr "'x' oraz 'cl'mają różne długości" # class/R/lvq.R: 33 # stop("invalid 'prior'") msgid "invalid 'prior'" msgstr "niepoprawny 'prior'" # class/R/lvq.R: 34 # stop("'prior' is of incorrect length") msgid "'prior' is of incorrect length" msgstr "'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 = NA) msgid "pass %s size %d" msgstr "przekazano %s rozmiar %d" class/po/R-ko.po0000644000176000001440000000442612117457373013215 0ustar ripleyusers# Korean translation for R class package # Recommended/class/po/R-ko.po # Maintainer: Brian Ripley # Copyright (C) 1995-2013 The R Core Team # This file is distributed under the same license as the R class package. # R Development Translation Team - Korean # Chel Hee Lee , 2013. # Chel Hee Lee , 2013. # msgid "" msgstr "" "Project-Id-Version: class 7.3-5\n" "POT-Creation-Date: 2012-10-08 10:54\n" "PO-Revision-Date: 2013-03-11 13:42-0600\n" "Last-Translator: Chel Hee Lee \n" "Language-Team: R Development Translation Teams (Korean) \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" "X-Poedit-Language: Korean\n" "X-Poedit-Country: KOREA, REPUBLIC OF\n" "X-Poedit-SourceCharset: utf-8\n" msgid "wrong plot method used" msgstr "사용된 플랏 메소드가 잘못되었습니다" msgid "'SOM' called with no data" msgstr "아무런 데이터가 없이 호출된 'SOM'입니다" msgid "'radii' must be a list of the same length as 'alpha'" msgstr "'radii'는 반드시 'alpha'와 같은 길이의 리스트이어야 합니다" 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'의 dims가 서로 다릅니다" msgid "k = %d exceeds number %d of patterns" msgstr "" 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 "" msgid "pass %s size %d" msgstr "" class/inst/0000755000176000001440000000000012204750330012360 5ustar ripleyusersclass/inst/po/0000755000176000001440000000000012121561432012777 5ustar ripleyusersclass/inst/po/pl/0000755000176000001440000000000011772553043013424 5ustar ripleyusersclass/inst/po/pl/LC_MESSAGES/0000755000176000001440000000000012204750330015176 5ustar ripleyusersclass/inst/po/pl/LC_MESSAGES/R-class.mo0000644000176000001440000000377012121561432017047 0ustar ripleyusersxy0 4*9#d!$('P&g#:''8=-v%*& 0-O}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-3 Report-Msgid-Bugs-To: bugs@r-project.org POT-Creation-Date: 2012-09-23 17:22 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.3 'SOM' zostało wywołane bez danych'alpha' oraz 'radii' nie posiadają tych samych długości'alpha' oraz 'radii' nie zgadzają się'prior' posiada niepoprawną długość'radii' musi być listą tej samej długości co 'alpha''train' oraz 'class' mają różne długości'x' oraz 'cl'mają różne długościwymiary 'test' oraz 'train' różnią sięniepoprawny '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/0000755000176000001440000000000011754561331014423 5ustar ripleyusersclass/inst/po/en@quot/LC_MESSAGES/0000755000176000001440000000000012204750330016176 5ustar ripleyusersclass/inst/po/en@quot/LC_MESSAGES/R-class.mo0000644000176000001440000000331012121561432020035 0ustar ripleyusersxy0 4*9#d!$('P6g8("<A2~+)$@Zx(   '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-6 POT-Creation-Date: 2013-03-18 09:49 PO-Revision-Date: 2013-03-18 09:49 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/inst/po/ko/0000755000176000001440000000000012121561432013410 5ustar ripleyusersclass/inst/po/ko/LC_MESSAGES/0000755000176000001440000000000012204750330015174 5ustar ripleyusersclass/inst/po/ko/LC_MESSAGES/R-class.mo0000644000176000001440000000343212121561432017040 0ustar ripleyusers 010K |4*#!@br6D6*MMx330.$_7)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 must be at least 1no missing values are allowedwrong plot method usedProject-Id-Version: class 7.3-5 POT-Creation-Date: 2012-10-08 10:54 PO-Revision-Date: 2013-03-11 13:42-0600 Last-Translator: Chel Hee Lee Language-Team: R Development Translation Teams (Korean) Language: ko MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=1; plural=0; X-Poedit-Language: Korean X-Poedit-Country: KOREA, REPUBLIC OF X-Poedit-SourceCharset: utf-8 아무런 데이터가 없이 호출된 'SOM'입니다'alpha'와 'radii'는 같은 길이를 가지고 있지 않습니다'alpha'와 'radii'가 서로 일치하지 않습니다'prior'의 길이가 잘못되었습니다'radii'는 반드시 'alpha'와 같은 길이의 리스트이어야 합니다'train'과 'class'는 다른 길이를 가집니다'x'와 'cl'은 서로 다른 길이를 가집니다'test'와 'train'의 dims가 서로 다릅니다유효하지 않은 'prior'입니다k의 값 %d는 반드시 적어도 1이어야 합니다결측치들은 허용되지 않습니다사용된 플랏 메소드가 잘못되었습니다class/inst/po/fr/0000755000176000001440000000000011754561331013417 5ustar ripleyusersclass/inst/po/fr/LC_MESSAGES/0000755000176000001440000000000012204750330015172 5ustar ripleyusersclass/inst/po/fr/LC_MESSAGES/R-class.mo0000644000176000001440000000354312121561432017041 0ustar ripleyusersxy0 4*9#d!$('Pg-2'`"80)0?p+$:$>   '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 POT-Creation-Date: 2012-09-23 17:22 PO-Revision-Date: 2012-10-03 15:26+0100 Last-Translator: Philippe Grosjean Language-Team: French Language: fr MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n > 1); X-Generator: Poedit 1.5.3 'SOM' appel sans donnes'alpha' et 'radii' n'ont pas la mme longueur'alpha' et 'radii' ne correspondent pas'prior' est de longueur incorrecte'radii' doit tre une liste de mme longueur que 'alpha''train' et 'class' ont des longueurs diffrentes'x' et 'cl' ont des longueurs diffrentesles dimensions de 'test' et de 'train' diffrent'prior' invalidek = %d est suprieur 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 mthode graphique incorrecteclass/inst/po/de/0000755000176000001440000000000011754561331013400 5ustar ripleyusersclass/inst/po/de/LC_MESSAGES/0000755000176000001440000000000012204750330015153 5ustar ripleyusersclass/inst/po/de/LC_MESSAGES/R-class.mo0000644000176000001440000000360012121561432017014 0ustar ripleyusersxy0 4*9#d!$('Pg6&-]D6/$;T,!3-a   '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 POT-Creation-Date: 2012-09-23 17:22 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/CITATION0000644000176000001440000000127511754561331013534 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 = "http://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/NEWS0000644000176000001440000000104411754561331013070 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/src/0000755000176000001440000000000012204750330012172 5ustar ripleyusersclass/src/class.c0000644000176000001440000002625112205126342013452 0ustar ripleyusers/* * class/src/class.c by W. N. Venables and B. D. Ripley Copyright (C) 1994-2002 * * 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 #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 = Calloc(ntr, int); for (npat = 0; npat < nte; npat++) { dm = 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; 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 * DOUBLE_XMAX; 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 * DOUBLE_XMAX; } 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 = Calloc(ncodes, double); for (j = 0; j < ncodes; j++) al[j] = *alpha; for (iter = 0; iter < *niter; iter++) { npat = iters[iter]; dm = DOUBLE_XMAX; 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])); } 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 = DOUBLE_XMAX; 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 = DOUBLE_XMAX; /* 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 = DOUBLE_XMAX; /* 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 = 0; dm = DOUBLE_XMAX; 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 = 0; 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} }; #include void R_init_class(DllInfo *dll) { R_registerRoutines(dll, CEntries, NULL, NULL, NULL); R_useDynamicSymbols(dll, FALSE); #if defined(R_VERSION) && R_VERSION >= R_Version(2, 16, 0) R_forceSymbols(dll, TRUE); #endif } class/NAMESPACE0000644000176000001440000000041512055403552012627 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) importFrom(stats, dist) S3method(plot, SOM) S3method(plot, somgrid) class/R/0000755000176000001440000000000012204750330011604 5ustar ripleyusersclass/R/lvq.R0000644000176000001440000001174312027627032012544 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/R/SOM.R0000644000176000001440000001064012027626770012403 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/knn.R0000644000176000001440000000706211754561331012534 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.R0000644000176000001440000000013711754561331012577 0ustar ripleyusers.noGenerics <- TRUE .onUnload <- function(libpath) library.dynam.unload("class", libpath) class/R/multiedit.R0000644000176000001440000000456312027627112013743 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/MD50000644000176000001440000000336712205127043011724 0ustar ripleyuserse7043c670e7531e6a8e72861827bc69b *DESCRIPTION a14861d4c76b0028b6dc635163b00297 *LICENCE.note 018ec39aa0218512d0e6493b9003f7eb *NAMESPACE 44e5755ae2d5d1f1b8509879577c17a5 *R/SOM.R 6985c529cd8fc96dc6c91af6cc9cc964 *R/knn.R 50be3231f5443f347952d0ee4918395d *R/lvq.R acd705e760928c76dc5507dc598872e1 *R/multiedit.R 6eeaac5a4afe30bedaff5567311dc342 *R/zzz.R 3bad31311a37fe2f39e9c2ad876ab94c *inst/CITATION e042788d6870b70eb8ea0bc5f01391ff *inst/NEWS 2d4884f2f724beae0767bf44efa59598 *inst/po/de/LC_MESSAGES/R-class.mo 6529f2e958625883ff19a3d825667966 *inst/po/en@quot/LC_MESSAGES/R-class.mo d10745a6ccb433aeeb6ed691dfdf8918 *inst/po/fr/LC_MESSAGES/R-class.mo cd859451b9fcf42aa531dbd1a02a911c *inst/po/ko/LC_MESSAGES/R-class.mo a73f19863d0c8cc2df8dcfacd791c2f1 *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 7ffe67ce0c67d938298e46b08818f9cb *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 bf9954300d68e0cb85667831b7f1eb13 *man/reduce.nn.Rd 04d8b8fb49626fa41093f3b19ce5edbf *man/somgrid.Rd fdfd2e5c4f5a48bfa9a66424e24525bc *po/R-class.pot 98593b35ec7a47e8442acbbe9feb6846 *po/R-de.po 3195cdd61375917b1dec4d2521cc5ea8 *po/R-fr.po 713057cc64a2800928ad2cc1da2985d4 *po/R-ko.po d95f8ff142012cbf8277f6a0914fbfae *po/R-pl.po 045e79c0d1da224a2e90b92418afb89f *src/class.c class/DESCRIPTION0000644000176000001440000000127512205127043013116 0ustar ripleyusersPackage: class Priority: recommended Version: 7.3-9 Date: 2013-08-21 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. Title: Functions for Classification ByteCompile: yes License: GPL-2 | GPL-3 URL: http://www.stats.ox.ac.uk/pub/MASS4/ Packaged: 2013-08-21 12:04:50 UTC; ripley Author: Brian Ripley [aut, cre, cph], William Venables [cph] Maintainer: Brian Ripley NeedsCompilation: yes Repository: CRAN Date/Publication: 2013-08-21 14:10:11 class/man/0000755000176000001440000000000012204750330012156 5ustar ripleyusersclass/man/lvqinit.Rd0000644000176000001440000000345411754561331014153 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/multiedit.Rd0000644000176000001440000000300511754561331014455 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/reduce.nn.Rd0000644000176000001440000000266011754561331014344 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{ \eqn{\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/SOM.Rd0000644000176000001440000000454211754561331013122 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/knn.Rd0000644000176000001440000000400011754561331013237 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/condense.Rd0000644000176000001440000000276111754561331014263 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/lvq2.Rd0000644000176000001440000000333311754561331013345 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/knn.cv.Rd0000644000176000001440000000362011754561331013655 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/knn1.Rd0000644000176000001440000000235111754561331013327 0ustar ripleyusers% file class/man/knn1.Rd % copyright (C) 1994-9 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/lvqtest.Rd0000644000176000001440000000162011754561331014160 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/olvq1.Rd0000644000176000001440000000306111754561331013521 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/lvq1.Rd0000644000176000001440000000313011754561331013337 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/man/batchSOM.Rd0000644000176000001440000000363111754561331014122 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/somgrid.Rd0000644000176000001440000000241611754561331014126 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/lvq3.Rd0000644000176000001440000000337411754561331013353 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/LICENCE.note0000644000176000001440000000301112164263547013345 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 are copyright (C) 1994-2013 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 http://www.r-project.org/licenses/ Bill.Venables@csiro.au ripley@stats.ox.ac.uk