Skip to content

Commit

Permalink
removed FLIBS from Makevars and included new file sits_predictors
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed May 12, 2023
1 parent 87ac3b7 commit 4f12ca7
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Collate:
'sits_parallel.R'
'sits_patterns.R'
'sits_plot.R'
'sits_predictors.R'
'sits_reclassify.R'
'sits_raster_data.R'
'sits_raster_sub_image.R'
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ export(sits_mlp)
export(sits_model_export)
export(sits_mosaic)
export(sits_patterns)
export(sits_pred_features)
export(sits_predictors)
export(sits_reclassify)
export(sits_reduce_imbalance)
export(sits_regularize)
Expand Down
151 changes: 151 additions & 0 deletions R/sits_predictors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#' @title Obtain predictors for time series samples
#' @name sits_predictors
#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
#' @description Predictors are X-Y values required for machine learning
#' algorithms, organized as a data table where each row corresponds
#' to a training sample. The first two columns of the predictors table
#' are categorical ("label_id" and "label"). The other columns are
#' the values of each band and time, organized first by band and then by time.
#'
#'
#' @param samples Time series in sits format
#'
#'
#' @return The predictors for the sample: a data.frame with one row per sample.
#'
#' @note
#' Please refer to the sits documentation available in
#' <https://e-sensing.github.io/sitsbook/> for detailed examples.
#' @examples
#' if (sits_run_examples()) {
#' summary(samples_modis_ndvi)
#' }
#'
#' @export
sits_predictors <- function(samples) {
pred <- .predictors(samples)
}

#' @title Obtain numerical values of predictors for time series samples
#' @name sits_pred_features
#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
#' @description Predictors are X-Y values required for machine learning
#' algorithms, organized as a data table where each row corresponds
#' to a training sample. The first two columns of the predictors table
#' are categorical ("label_id" and "label"). The other columns are
#' the values of each band and time, organized first by band and then by time.
#' This function returns the numeric values associated to each sample.
#'
#' @param pred X-Y predictors: a data.table with one row per sample.
#'
#' @return The Y predictors for the sample: a data.frame with one row per sample.
#'
#' @note
#' Please refer to the sits documentation available in
#' <https://e-sensing.github.io/sitsbook/> for detailed examples.
#' @examples
#' if (sits_run_examples()) {
#' summary(samples_modis_ndvi)
#' }
#'
#' @export
sits_pred_features <- function(pred){
features <- .pred_features(pred)
}
#' @title Obtain categorical id and labels of predictors for time series samples
#' @name sits_pred_reference
#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
#' @description Predictors are X-Y values required for machine learning
#' algorithms, organized as a data table where each row corresponds
#' to a training sample. The first two columns of the predictors table
#' are categorical ("label_id" and "label"). The other columns are
#' the values of each band and time, organized first by band and then by time.
#' This function returns the numeric values associated to each sample.
#'
#' @param pred X-Y predictors: a data.table with one row per sample.
#'
#' @return The label associated to each training sample.
#'
#' @note
#' Please refer to the sits documentation available in
#' <https://e-sensing.github.io/sitsbook/> for detailed examples.
#' @examples
#' if (sits_run_examples()) {
#' summary(samples_modis_ndvi)
#' }
sits_pred_references <- function(pred){
ref <- .pred_references(pred)
}
#' @title Normalize predictor values
#' @name sits_pred_normalize
#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
#' @description Most machine learning algorithms require data to be
#' normalized. This applies to the "SVM" method and to all deep learning ones.
#' To normalize the predictors, it is required that the statistics per band
#' for each sample have been obtained by the "sits_stats" function.
#'
#' @param pred X-Y predictors: a data.table with one row per sample.
#' @param stats The output of the "sits_stats" function applied to the samples.
#'
#' @return A normalized set of predictor values
#'
#' @note
#' Please refer to the sits documentation available in
#' <https://e-sensing.github.io/sitsbook/> for detailed examples.
#' @examples
#' if (sits_run_examples()) {
#' summary(samples_modis_ndvi)
#' }
sits_pred_normalize <- function(pred, stats) {
pred <- .pred_normalize(pred, stats)
}
#' @title Obtain a fraction of the predictors data frame
#' @name sits_pred_sample
#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
#' @description Many machine learning algorithms (especially deep learning)
#' use part of the original samples as test data to adjust its hyperparameters
#' and to find an optimal point of convergence using gradient descent.
#' This function extracts a fraction of the predictors to serve as test values
#' for the deep learning algorithm.
#'
#' @param pred X-Y predictors: a data.table with one row per sample.
#' @param frac Fraction of the X-Y predictors to be extracted
#'
#' @return A fraction of the X-Y predictors.
#'
#' @note
#' Please refer to the sits documentation available in
#' <https://e-sensing.github.io/sitsbook/> for detailed examples.
#' @examples
#' if (sits_run_examples()) {
#' summary(samples_modis_ndvi)
#' }
sits_pred_sample <- function(pred, frac){
sample <- .pred_sample(pred, frac)
}
#' @title Obtain statistics for all sample bands
#' @name sits_stats
#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br}
#' @description Most machine learning algorithms require data to be
#' normalized. This applies to the "SVM" method and to all deep learning ones.
#' To normalize the predictors, it is necessary to extract the statistics
#' of each band of the samples. This function computes the 2% and 98% quantiles
#' of the distribution of each band of the samples. This values are used as
#' minimum and maximum values in the normalization operation performed by
#' the sits_pred_normalize() function.
#'
#' @param samples Time series samples uses as training data.
#'
#' @return A list with the 2% and 98% quantiles for each band of the
#' training data.
#'
#' @note
#' Please refer to the sits documentation available in
#' <https://e-sensing.github.io/sitsbook/> for detailed examples.
#' @examples
#' if (sits_run_examples()) {
#' summary(samples_modis_ndvi)
#' }
sits_stats <- function(samples){
stats <- .sits_stats(samples)
}
35 changes: 35 additions & 0 deletions man/sits_pred_features.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/sits_pred_normalize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions man/sits_pred_reference.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions man/sits_pred_sample.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/sits_predictors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions man/sits_stats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS)

0 comments on commit 4f12ca7

Please sign in to comment.