compare_documents: Compare Documents

View source: R/compare.R

compare_documentsR Documentation

Compare Documents

Description

Compare two handwritten documents to predict whether they were written by the same person. Use either a similarity score or a score-based likelihood ratio as a comparison method.

Usage

compare_documents(
  sample1,
  sample2,
  score_only = TRUE,
  rforest = NULL,
  project_dir = NULL,
  reference_scores = NULL
)

Arguments

sample1

A filepath to a handwritten document scanned and saved as a PNG file.

sample2

A filepath to a handwritten document scanned and saved as a PNG file.

score_only

TRUE returns only the similarity score. FALSE returns the similarity score and a score-based likelihood ratio for that score, calculated using reference_scores.

rforest

Optional. A random forest created with ranger::ranger(). If a random forest is not supplied, random_forest will be used.

project_dir

Optional. A folder in which to save helper files and a CSV file with the results. If no project directory is supplied. Helper files will be saved to tempdir() > comparison but deleted before the function terminates. A CSV file with the results will not be saved, but a dataframe of the results will be returned.

reference_scores

Optional. A list of same writer and different writer similarity scores used for reference to calculate a score-based likelihood ratio. If reference scores are not supplied, ref_scores will be used only if score_only is FALSE. If score only is true, reference scores are unnecessary because a score-based likelihood ratio will not be calculated. If reference scores are supplied, score_only will automatically be set to FALSE.

Value

A dataframe

Examples


# Compare two documents from the same writer with a similarity score
s1 <- system.file(file.path("extdata", "docs", "w0005_s01_pLND_r03.png"),
  package = "handwriterRF"
)
s2 <- system.file(file.path("extdata", "docs", "w0005_s02_pWOZ_r02.png"),
  package = "handwriterRF"
)
compare_documents(s1, s2, score_only = TRUE)

# Compare two documents from the same writer with a score-based
# likelihood ratio
s1 <- system.file(file.path("extdata", "docs", "w0005_s01_pLND_r03.png"),
  package = "handwriterRF"
)
s2 <- system.file(file.path("extdata", "docs", "w0005_s02_pWOZ_r02.png"),
  package = "handwriterRF"
)
compare_documents(s1, s2, score_only = FALSE)



handwriterRF documentation built on April 4, 2025, 5:38 a.m.