Title: | Design of Optimum-Path Forest Classifiers |
---|---|
Description: | The 'LibOPF' is a framework to develop pattern recognition techniques based on optimum-path forests (OPF), João P. Papa and Alexandre X. Falcão (2008) <doi:10.1007/978-3-540-89639-5_89>, with methods for supervised learning and data clustering. |
Authors: | Rafael Junqueira Martarelli [aut, cre], João Paulo Papa [aut], Alexandre Xavier Falcão [cph] |
Maintainer: | Rafael Junqueira Martarelli <[email protected]> |
License: | BSD_2_clause + file LICENSE |
Version: | 2.6.0 |
Built: | 2024-11-06 03:40:10 UTC |
Source: | https://github.com/rafaeljm/libopf-in-r |
Computes the OPF accuracy
opf_accuracy(dataSet, classification)
opf_accuracy(dataSet, classification)
dataSet |
Data object used in the opf_classify function (subGraph object), normaly is the testing object |
classification |
The output list produced by opf_classify function |
Returns the classification accuracy
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Computes the OPF accuracy for each class of a given set
opf_accuracy4label(dataSet, classification)
opf_accuracy4label(dataSet, classification)
dataSet |
Data object used in in the opf_classify function (subGraph object), normaly is the testing object |
classification |
The output list produced by opf_classify function |
Returns the classification accuracy for each class
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy4label(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy4label(T2, class)
Checks the OPF file for proper formatting purposes
opf_check(file)
opf_check(file)
file |
The text OPF file name |
usage opf_check <input ASCII file in the LibOPF format>: Note that the input file for opf_check must be a text file. Use opf2txt to convert your OPF binary file into a text file.
'NULL'
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) File <- file.path(tempdir(), "boat.txt") opf2txt(dataset,File) opf_check(File)
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) File <- file.path(tempdir(), "boat.txt") opf2txt(dataset,File) opf_check(File)
Executes the test phase of the OPF classifier
opf_classify(dataSet, classifier, precomputedDistance = NA)
opf_classify(dataSet, classifier, precomputedDistance = NA)
dataSet |
The testing data object produced by the opf_split function (subGraph object) |
classifier |
The classifier object produced by one of the classification functions (model object) |
precomputedDistance |
The precomputed distance matrix produced by the opf_distance (leave it in blank if you are not using this resource) |
Returns the given subGraph classification list (predicted labels)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Computes clusters by unsupervised OPF
opf_cluster(dataSet, kmax, calculateOp, value, precomputedDistance = NA)
opf_cluster(dataSet, kmax, calculateOp, value, precomputedDistance = NA)
dataSet |
The training object produced by the opf_split function (subGraph object) |
kmax |
The kmax (maximum degree for the knn graph) |
calculateOp |
Clusters by: 0 for height, 1 for area and 2 for volume |
value |
Value of parameter "calculateOp" in [0-1] |
precomputedDistance |
The precomputed distance matrix produced by the opf_distance (leave it in blank if you are not using this resource) |
Returns a list which contains the classifier object and the classification list object (i.e., clusters' id)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.8,0,0.2,0) T <- X$training T2 <- X$testing Y <- opf_cluster(T,100,1,0.2) class <- opf_knn_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.8,0,0.2,0) T <- X$training T2 <- X$testing Y <- opf_cluster(T,100,1,0.2) class <- opf_knn_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Creates an empty subGraph structure
opf_create_subGraph(nnodes)
opf_create_subGraph(nnodes)
nnodes |
Number of nodes |
Returns an empty subGraph
EmptySubgraph <- opf_create_subGraph(10)
EmptySubgraph <- opf_create_subGraph(10)
Generates the precomputed distance file for the OPF classifier
opf_distance(dataSet, distanceOp, normalize = 0)
opf_distance(dataSet, distanceOp, normalize = 0)
dataSet |
The subGraph object, normaly is the whole data |
distanceOp |
Distance calculation option |
normalize |
Distance normalization? 1- yes 0 - no |
Options for distance calculation:
1 - Euclidean
2 - Chi-Square
3 - Manhattan (L1)
4 - Canberra
5 - Squared Chord
6 - Squared Chi-Squared
7 - BrayCurtis
Returns the distance matrix
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) dist <- opf_distance(dat,3,0) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T,dist) class <- opf_classify(T2, Y$classifier,dist) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) dist <- opf_distance(dat,3,0) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T,dist) class <- opf_classify(T2, Y$classifier,dist) acc <- opf_accuracy(T2, class)
Generates k folds (objects) for the OPF classifier
opf_fold(dataSet, k, normalize = 0)
opf_fold(dataSet, k, normalize = 0)
dataSet |
The subGraph object |
k |
Number of folds |
normalize |
Distance normalization? 1- yes 0 - no |
Returns a list of subGraph objects
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) folds <- opf_fold(dat, 4)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) folds <- opf_fold(dat, 4)
Gives information about the OPF file
opf_info(dataSet)
opf_info(dataSet)
dataSet |
The OPF file |
'NULL'
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) opf_info(dat)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) opf_info(dat)
Executes the test phase of the OPF classifier with knn adjacency
opf_knn_classify(dataSet, classifier, precomputedDistance = NA)
opf_knn_classify(dataSet, classifier, precomputedDistance = NA)
dataSet |
The testing object produced by the opf_split (subGraph object) |
classifier |
The classifier object produced by one of the classification functions (model object) |
precomputedDistance |
The precomputed distance matrix produced by the opf_distance (leave it in blank if you are not using this resource) |
Returns the given subGraph classification list
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.8,0,0.2,0) T <- X$training T2 <- X$testing Y <- opf_cluster(T,100,1,0.2) class <- opf_knn_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.8,0,0.2,0) T <- X$training T2 <- X$testing Y <- opf_cluster(T,100,1,0.2) class <- opf_knn_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Executes the training phase of the OPF classifier with knn adjacency
opf_knn_train(trainFile, evaluatFile, kmax, precomputedDistance = NA)
opf_knn_train(trainFile, evaluatFile, kmax, precomputedDistance = NA)
trainFile |
The training object produced by the opf_split (subGraph object) |
evaluatFile |
The evaluation object produced by the opf_split (subGraph object) |
kmax |
The kmax (maximum degree for the knn graph) |
precomputedDistance |
The precomputed distance matrix produced by the opf_distance (leave it in blank if you are not using this resource) |
Returns a list which contains the classifier object and the classification list object
Returns a list which contains the classifier object and the classification list object (i.e., clusters' id)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.3,0.2,0.5,0) T <- X$training T2 <- X$testing E <- X$evaluating Y <- opf_knn_train(T,E,100) class <- opf_knn_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.3,0.2,0.5,0) T <- X$training T2 <- X$testing E <- X$evaluating Y <- opf_knn_train(T,E,100) class <- opf_knn_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Executes the learning phase of the OPF classifier
opf_learn(trainFile, evaluatFile, precomputedDistance = NA)
opf_learn(trainFile, evaluatFile, precomputedDistance = NA)
trainFile |
The training object produced by the opf_split (subGraph object) |
evaluatFile |
The evaluation produced object by the opf_split (subGraph object) |
precomputedDistance |
The precomputed distance matrix produced by the opf_distance (leave it in blank if you are not using this resource) |
Executes the training phase
Returns a list which contains the classifier model object
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.3,0.2,0.5,0) T <- X$training T2 <- X$testing E <- X$evaluating Y <- opf_learn(T,E) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.3,0.2,0.5,0) T <- X$training T2 <- X$testing E <- X$evaluating Y <- opf_learn(T,E) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Merge subGraphs
opf_merge(dataSets)
opf_merge(dataSets)
dataSets |
An array of subGraph objects |
Returns the merged subGraph object
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) dat2 <- opf_read_subGraph(system.file("extdata/Z1LINE.dat",package = "LibOPF")) dataSet <- opf_merge(c(dat,dat2))
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) dat2 <- opf_read_subGraph(system.file("extdata/Z1LINE.dat",package = "LibOPF")) dataSet <- opf_merge(c(dat,dat2))
Normalizes data for the OPF classifier
opf_normalize(dataSet)
opf_normalize(dataSet)
dataSet |
The subGraph object |
Returns the normalized subGraph
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) dat <- opf_normalize(dataset)
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) dat <- opf_normalize(dataset)
Executes the pruning algorithm
opf_pruning( dataTraining, dataEvaluating, percentageAccuracy, precomputedDistance = NA )
opf_pruning( dataTraining, dataEvaluating, percentageAccuracy, precomputedDistance = NA )
dataTraining |
The training object produced by the opf_split (subGraph object) |
dataEvaluating |
The evaluating object produced by the opf_split (subGraph object) |
percentageAccuracy |
Max percentage of lost accuracy [0,1] |
precomputedDistance |
The precomputed distance matrix produced by the opf_distance (leave it in blank if you are not using this resource) |
Returns a list which contains the classifier model object
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.3,0.2,0.5,0) T <- X$training T2 <- X$testing E <- X$evaluating Y <- opf_pruning(T,E,0.8) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.3,0.2,0.5,0) T <- X$training T2 <- X$testing E <- X$evaluating Y <- opf_pruning(T,E,0.8) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Reads a file which contains the nodes' predicted labels
opf_read_classification(file)
opf_read_classification(file)
file |
The file which contains the nodes' predicted labels |
Returns the predicted labels list
File <- system.file("extdata/classification.txt",package = "LibOPF") classification <- opf_read_classification(File)
File <- system.file("extdata/classification.txt",package = "LibOPF") classification <- opf_read_classification(File)
Reads a file which contains the precalculated distances
opf_read_distances(file)
opf_read_distances(file)
file |
The file which contains the distances matrix |
Returns the precalculated distances matrix
distances <- opf_read_distances(system.file("extdata/distances.dat",package = "LibOPF"))
distances <- opf_read_distances(system.file("extdata/distances.dat",package = "LibOPF"))
Reads a file which contains the learned model
opf_read_modelfile(file)
opf_read_modelfile(file)
file |
The file which contains the learned model |
Returns the learned model object
classifier <- opf_read_modelfile(system.file("extdata/classifier.opf",package = "LibOPF"))
classifier <- opf_read_modelfile(system.file("extdata/classifier.opf",package = "LibOPF"))
Reads a file which contains the subGraph
opf_read_subGraph(file)
opf_read_subGraph(file)
file |
The file name |
Returns the subGraph object
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
This function will run this example:
dat <- opf_read_subGraph(dataset) (dataset is the subgraph file)
X <- opf_split(dat,0.5,0,0.5,0)
T <- X$training
T2 <- X$testing
Y <- opf_train(T)
class <- opf_classify(T2, Y$classifier)
acc <- opf_accuracy(T2, class)
opf_run_example(dataset)
opf_run_example(dataset)
dataset |
A dataset folder for the test |
Returns the accuracy
Executes the semi supervised training phase
opf_semi( labeledTrainSubGraph, unLabeledTrainSubGraph, evaluatFile = NA, precomputedDistance = NA )
opf_semi( labeledTrainSubGraph, unLabeledTrainSubGraph, evaluatFile = NA, precomputedDistance = NA )
labeledTrainSubGraph |
The labeled training object (subGraph object) |
unLabeledTrainSubGraph |
The unlabeled training object (subGraph object) |
evaluatFile |
The evaluation object produced by the opf_split (subGraph object) |
precomputedDistance |
The precomputed distance matrix produced by the opf_distance (leave it in blank if you are not using this resource) |
Returns the learned model object
Returns a list which contains the classifier object and the classification list object
Training <- opf_read_subGraph(system.file("extdata/Z1LINE.dat",package = "LibOPF")) TUnlabeled <- opf_read_subGraph(system.file("extdata/Z1DOUBLELINE.dat",package = "LibOPF")) Testing <- opf_read_subGraph(system.file("extdata/Z3.dat",package = "LibOPF")) Y <- opf_semi(Training,TUnlabeled) class <- opf_classify(Testing, Y$classifier) acc <- opf_accuracy(Testing, class)
Training <- opf_read_subGraph(system.file("extdata/Z1LINE.dat",package = "LibOPF")) TUnlabeled <- opf_read_subGraph(system.file("extdata/Z1DOUBLELINE.dat",package = "LibOPF")) Testing <- opf_read_subGraph(system.file("extdata/Z3.dat",package = "LibOPF")) Y <- opf_semi(Training,TUnlabeled) class <- opf_classify(Testing, Y$classifier) acc <- opf_accuracy(Testing, class)
Generates training, evaluation and test sets for the OPF classifier
opf_split(dataSet, training_p, evaluating_p, testing_p, normalize = 0)
opf_split(dataSet, training_p, evaluating_p, testing_p, normalize = 0)
dataSet |
The data (subGraph object) |
training_p |
Percentage for the training set size [0,1] |
evaluating_p |
Percentage for the evaluation set size [0,1] (leave 0 in the case of no learning) |
testing_p |
Percentage for the test set size [0,1] |
normalize |
Distance normalization? 1- yes 0 - no |
Returns the training, evaluating and the testing objects
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Executes the training phase of the OPF classifier
opf_train(dataSet, precomputedDistance = NA)
opf_train(dataSet, precomputedDistance = NA)
dataSet |
The training object produced by the opf_split (subGraph object) |
precomputedDistance |
The precomputed distance matrix produced by the opf_distance (leave it in blank if you are not using this resource) |
Returns a list which contains the classifier object and the classification list object
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) class <- opf_classify(T2, Y$classifier) acc <- opf_accuracy(T2, class)
Writes into a file the predicted labels produced by the opf classificator
opf_write_classification(classes, file)
opf_write_classification(classes, file)
classes |
The classification list (i.e.,predicted labels) produced by the classifier |
file |
Where you want to save the classification vector |
'NULL'
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) opf_write_classification(Y$classification, file.path(tempdir(), "classification.txt"))
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) opf_write_classification(Y$classification, file.path(tempdir(), "classification.txt"))
Writes into a file the precalculated distances computed by opf_distances function
opf_write_distances(distances, file)
opf_write_distances(distances, file)
distances |
The matrix produced by the opf distances function |
file |
The file name where you want to save the distances |
'NULL'
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) dist <- opf_distance(dat,3,0) opf_write_distances(dist, file.path(tempdir(), "distances.dat"))
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) dist <- opf_distance(dat,3,0) opf_write_distances(dist, file.path(tempdir(), "distances.dat"))
Writes into a file the trained OPF classifier
opf_write_modelfile(g, file)
opf_write_modelfile(g, file)
g |
The classifier object |
file |
The file name to save the classifier |
'NULL'
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) opf_write_modelfile(Y$classifier, file.path(tempdir(), "classifier.opf"))
dat <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) X <- opf_split(dat,0.5,0,0.5,0) T <- X$training T2 <- X$testing Y <- opf_train(T) opf_write_modelfile(Y$classifier, file.path(tempdir(), "classifier.opf"))
Writes into a file a subGraph
opf_write_subGraph(g, file)
opf_write_subGraph(g, file)
g |
The subGraph object |
file |
The file name to save the subGraph |
'NULL'
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) opf_write_subGraph(dataset, file.path(tempdir(), "boat.dat"))
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) opf_write_subGraph(dataset, file.path(tempdir(), "boat.dat"))
Converts an OPF subGraph object to a LIBSVM file
opf2svm(data, outputFile)
opf2svm(data, outputFile)
data |
The subGraph object |
outputFile |
LIBSVM output file name |
'NULL'
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) File <- file.path(tempdir(), "boat.svm") opf2svm(dataset,File) opf_check(File)
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) File <- file.path(tempdir(), "boat.svm") opf2svm(dataset,File) opf_check(File)
Converts an OPF subGraph object to a text file
opf2txt(data, outputFile)
opf2txt(data, outputFile)
data |
OPF subGraph object |
outputFile |
Text output file name |
'NULL'
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) File <- file.path(tempdir(), "boat.txt") opf2txt(dataset,File)
dataset <- opf_read_subGraph(system.file("extdata/boat.dat",package = "LibOPF")) File <- file.path(tempdir(), "boat.txt") opf2txt(dataset,File)
Converts a LIBSVM file to an OPF subGraph object
svm2opf(inputFile)
svm2opf(inputFile)
inputFile |
LIBSVM input file |
Returns the OPF object
dataset <- svm2opf(system.file("extdata/boat.svm",package = "LibOPF"))
dataset <- svm2opf(system.file("extdata/boat.svm",package = "LibOPF"))
Converts a text file to an OPF subGraph object
txt2opf(inputFile)
txt2opf(inputFile)
inputFile |
Text input file |
Returns the OPF object
dataset <- txt2opf(system.file("extdata/boat.txt",package = "LibOPF"))
dataset <- txt2opf(system.file("extdata/boat.txt",package = "LibOPF"))