# Environment used for execution of examples:
# Operating system: Ubuntu 24.04.3 LTS
# Compiler: g++ 13.3.0 (supports C++17 standard)
# Software: Python 3.12.3, TensorFlow 2.16.2
# R environment: R 4.5.2, RStudio 2024.12.1
# Installed packages: 'Rcpp' 1.1.0, 'tensorflow' 2.20.0,
# 'ganGenerativeData' 2.1.6, 'ganDataModel' 2.0.0
# Package 'tensorflow' provides an interface to machine learning framework
# TensorFlow. To complete the installation function install_tensorflow() has to
# be called.
if (FALSE) {
library(tensorflow)
install_tensorflow()}
# 1. Prerequisite for building a metric subspaces data model for the iris
# dataset: Create a data source, generate generative data and calculate density
# values for the iris dataset.
# Load library
if (FALSE) {
library(ganGenerativeData)}
# Create a data source with passed iris data frame.
if (FALSE) {
dsCreateWithDataFrame(iris)}
# Deactivate the column with index 5 and name Species in order to exclude it in
# generation of generative data.
if (FALSE) {
dsDeactivateColumns(c(5))}
# Write the data source including settings of active columns to file "ds.bin" in
# binary format.
if (FALSE) {
dsWrite("ds.bin")}
# Read data source from file "ds.bin", train a generative model in iterative
# training steps (used number of iterations in tests is in the range of 10000 to
# 50000), write trained generative model and generated data in training steps to
# files "gm.bin" and "gd.bin".
if (FALSE) {
gdTrain("gm.bin", "gd.bin", "ds.bin", c(1, 2), gdTrainParameters(1000))}
# Read generative data from file "gd.bin", calculate density values and
# write generative data with density values to original file.
if (FALSE) {
gdCalculateDensityValues("gd.bin")}
# 2. Build a metric subspaces data model for the iris data set
# Load library
if (FALSE) {
library(ganDataModel)}
# Read a data source and generative data from files "ds.bin" and "gd.bin",
# train a neural network which approximates density values for a data source
# in iterative training steps (used number of iterations in tests is in the
# range of 250000 to 300000), create a data model containing the trained neural
# network and write it to a file "dm.bin" in binary format.
if (FALSE) {
dmTrain("dm.bin", "ds.bin", "gd.bin", 10000)}
# Read a data model and generative data from files "dm.bin" and "gd.bin",
# build metric subspaces for level 0.7,
# add obtained metric subspaces to the data model
# and write it to original file.
if (FALSE) {
dmBuildMetricSubspaces("dm.bin", 0.38, "gd.bin")}
# Read a data model and generative data from files "dm.bin" and "gd,bin".
# Read in data is accessed in function dmPlotMetricSubspaces.
if (FALSE) {
dmRead("dm.bin", "gd.bin")}
# Create an image showing a two-dimensional projection of generative data
# contained in metric subspaces fpr level 0.38 for column indices 3, 4 and write
# it to file "ms.png".
if (FALSE) {
dmPlotMetricSubspaces(
list(dmPlotMetricSubspaceParameters(level = 0.38,
labels = c("*"),
percent = 100,
boundary = TRUE,
color = "red",
backgroundPercent = 0,
backgroundColor = "red",
backgroundReset = TRUE,
plotLabels = TRUE)),
"msl.png",
"Metric Subspaces for the Iris Dataset",
c(3, 4),
"ds.bin",
dmPlotEvaluateDataSourceParameters(0.38))}
# Read a data model and generative data from files "dm.bin" and "gd.bin",
# build metric subspaces for level 0.5,
# add obtained metric subspaces to the data model
# and write it to original file.
if (FALSE) {
dmBuildMetricSubspaces("dm.bin", 0.5, "gd.bin")}
# Read a data model and generative data from files "dm.bin" and "gd,bin".
# Read in data is accessed in function dmPlotMetricSubspaces.
if (FALSE) {
dmRead("dm.bin", "gd.bin")}
# Create an image showing a two-dimensional projection of generative data
# contained in metric subspaces for levels 0.38, 0.5 for column indices 3, 4
# and write it to file "msls.png".
if (FALSE) {
dmPlotMetricSubspaces(
list(dmPlotMetricSubspaceParameters(level = 0.38,
labels = c("*"),
percent = 100,
boundary = TRUE,
color = "red",
backgroundPercent = 0,
backgroundColor = "red",
backgroundReset = TRUE,
plotLabels = TRUE),
dmPlotMetricSubspaceParameters(level = 0.5,
labels = c("*"),
percent = 100,
boundary = TRUE,
color = "green",
backgroundPercent = 5,
backgroundColor = "red",
backgroundReset = TRUE,
plotLabels = TRUE)),
"msls.png",
"Metric Subspaces for the Iris Dataset",
c(3, 4),
"ds.bin",
dmPlotEvaluateDataSourceParameters(0.38))}
Run the code above in your browser using DataLab