by jsendak | May 16, 2025 | DS Articles
From creating comprehensive essays to writing intriguing fiction, there’s hardly anything untouched by the impact of generative AI. The technology has caught the attention of forward-thinking engineering companies, too. Many have attempted generative AI-assisted code development and seen measurable improvements in overall efficiency. However, the potential of this disruptive technology isn’t limited to code generation.… Read More »Generative AI in software development: Does faster code come at the cost of quality?
Generative AI: A Game Changer in Software Development?
Recently, the potential of generative AI in creating comprehensive essays to intriguing fiction has been recognized globally. This disruptive technology has also grabbed significant attention from trailblazing engineering firms that have experienced the remarkable efficiency that generative AI-assisted code development brings. But as the speed of code production increases, questions have arisen about the possible compromise on quality.
Long-Term Implications
There are several long-term implications of integrating generative AI into software development. The first and most evident is the massive increase in the speed of coding. Where developers used to spend hours writing thousands of lines of code, AI can generate the same amount in a fraction of the time.
However, this shift towards AI-assisted coding may also lead to critical questions about the quality of the resulting software. The utilization of AI in generating codes may bring about a tension between the speed of the coding process and the quality of the final product.
Future Developments
Future developments in this field might involve refining the AI’s coding capabilities. This could mean that AI would increasingly take on the brunt of the code-building process, with human developers focusing more on supervisory and quality assurance roles.
Additionally, as generative AI continues to improve, a future scenario could see AI being able to create not just efficient, but also high-quality code. Therefore, the question of “faster code versus quality” may become obsolete as AI evolves to do both tasks exceptionally well.
Actionable Advice
For forward-thinking engineering companies, it is imperative to invest in generative AI, given its massive potential to revolutionize the coding and software development process.
- Ensure adequate training and development opportunities for staff to learn how to effectively utilize AI-assisted code generation tools.
- At the same time, emphasize the importance of quality assurance in the development process. Despite the automation of coding, human involvement remains crucial in ensuring the quality of the product.
- Keep an eye on advances in the field of generative AI and adapt strategies accordingly. This would allow the company to stay ahead of the curve and reap the benefits of this disruptive technology.
In conclusion, while generative AI seems to be a promising tool in the field of software development, careful implementation and constant vigilance are needed to ensure both the speed and quality of the generated code.
Read the original article
by jsendak | May 16, 2025 | AI
arXiv:2505.09639v1 Announce Type: new
Abstract: Games, in their mathematical sense, are everywhere (game industries, economics, defense, education, chemistry, biology, …).Search algorithms in games are artificial intelligence methods for playing such games. Unfortunately, there is no study on these algorithms that evaluates the generality of their performance. We propose to address this gap in the case of two-player zero-sum games with perfect information. Furthermore, we propose a new search algorithm and we show that, for a short search time, it outperforms all studied algorithms on all games in this large experiment and that, for a medium search time, it outperforms all studied algorithms on 17 of the 22 studied games.
Expert Commentary on Games and Search Algorithms
The intersection of games and artificial intelligence is a fascinating area of study that has far-reaching implications in various fields beyond just entertainment. As mentioned in the abstract, games are prevalent in industries such as economics, defense, education, chemistry, and biology, highlighting the multi-disciplinary nature of this topic.
Search algorithms in games play a crucial role in artificial intelligence methods for playing these games, particularly in two-player zero-sum games with perfect information. However, the lack of studies evaluating the generality of performance in these algorithms is a significant gap that needs to be addressed.
The proposal to fill this gap by introducing a new search algorithm is promising, especially considering the results showing its superior performance compared to existing algorithms. It is essential to continuously innovate and improve search algorithms in games to enhance gameplay experiences and drive advancements in AI technology.
Furthermore, the success of this new algorithm on a diverse set of games underscores its potential applicability across various domains, reinforcing the importance of cross-disciplinary approaches in developing AI solutions. As the field of AI continues to evolve, exploring the synergies between game theory, algorithms, and different disciplines will pave the way for exciting advancements and groundbreaking discoveries.
Read the original article
by jsendak | May 16, 2025 | Computer Science
Expert Commentary: Unveiling Vulnerabilities in Anonymized Speech Systems
The development of SpecWav-Attack, an adversarial model aimed at detecting speakers in anonymized speech, sheds light on the vulnerabilities present in current speech anonymization systems. By utilizing advanced techniques such as Wav2Vec2 for feature extraction, spectrogram resizing, and incremental training, SpecWav-Attack showcases superior performance compared to traditional attacks.
The evaluation of SpecWav-Attack on widely used datasets like librispeech-dev and librispeech-test indicates its ability to outperform conventional attacks, highlighting the critical need for enhanced defenses in anonymized speech systems. The results obtained from benchmarking against the ICASSP 2025 Attacker Challenge further emphasize the urgency for stronger security measures in place.
Insights and Future Directions
- Enhanced Defense Mechanisms: The success of SpecWav-Attack underscores the importance of developing robust defenses against adversarial attacks in speech anonymization. Future research efforts should focus on designing more resilient systems to safeguard user privacy and prevent speaker identification.
- Adversarial Training: Integrating adversarial training techniques into the model development process could potentially mitigate the effectiveness of attacks like SpecWav-Attack. By exposing the system to diverse adversarial examples during training, it can learn to better handle such threats in real-world scenarios.
- Ethical Considerations: As advancements in speaker detection technologies continue to evolve, ethical implications surrounding privacy and data security become paramount. Striking a balance between innovation and protecting user anonymity is essential for promoting trust and transparency in speech processing applications.
Overall, SpecWav-Attack serves as a wake-up call for the research community and industry stakeholders to reevaluate existing security measures in anonymized speech systems. By addressing the vulnerabilities brought to light by this adversarial model, we can pave the way for more secure and resilient technologies in the future.
Read the original article
by jsendak | May 15, 2025 | AI
arXiv:2505.08896v1 Announce Type: new
Abstract: Developing an autonomous vehicle control strategy for signalised intersections (SI) is one of the challenging tasks due to its inherently complex decision-making process. This study proposes a Deep Reinforcement Learning (DRL) based longitudinal vehicle control strategy at SI. A comprehensive reward function has been formulated with a particular focus on (i) distance headway-based efficiency reward, (ii) decision-making criteria during amber light, and (iii) asymmetric acceleration/ deceleration response, along with the traditional safety and comfort criteria. This reward function has been incorporated with two popular DRL algorithms, Deep Deterministic Policy Gradient (DDPG) and Soft-Actor Critic (SAC), which can handle the continuous action space of acceleration/deceleration. The proposed models have been trained on the combination of real-world leader vehicle (LV) trajectories and simulated trajectories generated using the Ornstein-Uhlenbeck (OU) process. The overall performance of the proposed models has been tested using Cumulative Distribution Function (CDF) plots and compared with the real-world trajectory data. The results show that the RL models successfully maintain lower distance headway (i.e., higher efficiency) and jerk compared to human-driven vehicles without compromising safety. Further, to assess the robustness of the proposed models, we evaluated the model performance on diverse safety-critical scenarios, in terms of car-following and traffic signal compliance. Both DDPG and SAC models successfully handled the critical scenarios, while the DDPG model showed smoother action profiles compared to the SAC model. Overall, the results confirm that DRL-based longitudinal vehicle control strategy at SI can help to improve traffic safety, efficiency, and comfort.
Expert Commentary:
The development of autonomous vehicle control strategies for signalized intersections is a crucial area of research, as it presents complex decision-making challenges that need to be addressed for the safe and efficient operation of autonomous vehicles. This study offers a novel approach by leveraging Deep Reinforcement Learning (DRL) techniques for longitudinal vehicle control at signalized intersections.
One of the key strengths of this study is the formulation of a comprehensive reward function that takes into account various factors such as distance headway-based efficiency, decision-making during amber light, and asymmetric acceleration/deceleration responses. By incorporating these criteria into the reward function, the DRL algorithms, specifically Deep Deterministic Policy Gradient (DDPG) and Soft-Actor Critic (SAC), are able to effectively navigate the continuous action space of acceleration/deceleration.
The use of real-world leader vehicle (LV) trajectories combined with simulated trajectories generated using the Ornstein-Uhlenbeck (OU) process for training the DRL models is a noteworthy aspect of this study. This multi-disciplinary approach ensures that the models are exposed to a diverse range of scenarios, improving their robustness and performance in real-world situations.
The evaluation of the proposed models using Cumulative Distribution Function (CDF) plots and comparison with real-world trajectory data demonstrates their effectiveness in maintaining lower distance headway and jerk compared to human-driven vehicles while ensuring safety. Furthermore, the successful handling of diverse safety-critical scenarios, such as car-following and traffic signal compliance, by both DDPG and SAC models underscores the potential of DRL-based longitudinal vehicle control strategies at signalized intersections to enhance traffic safety, efficiency, and comfort.
In conclusion, this study highlights the promising role of DRL techniques in advancing autonomous vehicle control strategies, underscoring the importance of a multi-disciplinary approach that combines expertise from fields such as artificial intelligence, transportation engineering, and control systems.
Read the original article
by jsendak | May 14, 2025 | DS Articles
[This article was first published on
geocompx, and kindly contributed to
R-bloggers]. (You can report issue about the content on this page
here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.
This is the second part of a blog post series on spatial machine learning with R.
You can find the list of other blog posts in this series in part one.
Introduction
This document shows the application of caret for spatial modelling at the example of predicting air temperature in Spain. Hereby, we use measurements of air temperature available only at specific locations in Spain to create a spatially continuous map of air temperature. Therefore, machine-learning models are trained to learn the relationship between spatially continuous predictors and air temperature.
When using machine-learning methods with spatial data, we need to take care of, e.g., spatial autocorrelation, as well as extrapolation when predicting to regions that are far away from the training data. To deal with these issues, several methods have been developed. In this document, we will show how to combine the machine-learning workflow of caret with packages designed to deal with machine-learning with spatial data. Hereby, we use blockCV::cv_spatial()
and CAST::knndm()
for spatial cross-validation, and CAST::aoa()
to mask areas of extrapolation. We use sf and terra for processing vector and raster data, respectively.
The caret package
The caret package contains functions to train machine-learning models, as well as for, e.g., model selection. Its main function is caret::train()
, which provides a uniform interface to over 200 machine-learning algorithms. (User-specified-) Cross-Validation methods can be defined via caret::trainControl()
. An extensive online tutorial is available at https://topepo.github.io/caret/. Furthermore, a paper (https://doi.org/10.18637/jss.v028.i05), as well as a book (http://appliedpredictivemodeling.com/), describing the use of caret are available.
Install and load required R-packages
# install.packages("caret")
# install.packages("CAST")
# install.packages("blockCV")
# install.packages("sf")
# install.packages("terra")
library(caret)
library(CAST)
library(blockCV)
library(sf)
library(terra)
Case study data
Load data needed in this modelling example:
- predictor stack: raster dataset of the environmental predictors used to predict air temperature
- train points: vector dataset of ground measurements of air temperature
- spain: region for which predictions are made
predictor_stack <- terra::rast(
"https://github.com/LOEK-RS/FOSSGIS2025-examples/raw/refs/heads/main/data/predictors.tif"
)
predictor_names <- names(predictor_stack)
spain <- sf::st_read(
"https://github.com/LOEK-RS/FOSSGIS2025-examples/raw/refs/heads/main/data/spain.gpkg"
)
Reading layer `spain' from data source
`https://github.com/LOEK-RS/FOSSGIS2025-examples/raw/refs/heads/main/data/spain.gpkg'
using driver `GPKG'
Simple feature collection with 1 feature and 0 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -13454.15 ymin: 3988025 xmax: 1020771 ymax: 4859816
Projected CRS: ED50 / UTM zone 30N
train_points <- sf::st_read(
"https://github.com/LOEK-RS/FOSSGIS2025-examples/raw/refs/heads/main/data/temp_train.gpkg"
)
Reading layer `temp_train' from data source
`https://github.com/LOEK-RS/FOSSGIS2025-examples/raw/refs/heads/main/data/temp_train.gpkg'
using driver `GPKG'
Simple feature collection with 195 features and 1 field
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 36026.79 ymin: 3988818 xmax: 978160.6 ymax: 4858999
Projected CRS: ED50 / UTM zone 30N
train_data <- terra::extract(
predictor_stack,
train_points,
bind = TRUE,
ID = FALSE
) |>
sf::st_as_sf()
plot(sf::st_geometry(spain))
plot(sf::st_geometry(train_points), col = "blue4", add = TRUE)
Standard modelling workflow
Firstly, a simple modelling workflow without feature selection and hyperparameter tuning is shown:
- split data into training and test data
- train model using the training data only
- predict on test data to obtain error metrics
- predict on predictor stack to obtain spatially continuous prediction of air temperature
Geometry column needs to be dropped before using caret::train()
.
# 1. train-test split
set.seed(321)
trainIndex <- caret::createDataPartition(
train_data$temp,
p = .8,
list = FALSE,
times = 1
)
temperature_train <- train_data[trainIndex, ]
temperature_test <- train_data[-trainIndex, ]
# 2. model training
model <- caret::train(
temp ~ .,
data = sf::st_drop_geometry(temperature_train),
method = "ranger",
tuneGrid = expand.grid(
"mtry" = 4,
"splitrule" = "variance",
"min.node.size" = 5
),
num.trees = 100
)
# 3. predict on test data
test_df <- temperature_test[, "temp", drop = FALSE]
test_df$prediction <- predict(model, temperature_test)
test_metrics <- caret::postResample(
pred = test_df$prediction,
obs = test_df$temp
) |>
round(3) |>
t() |>
as.data.frame()
print(test_metrics)
RMSE Rsquared MAE
1 0.913 0.901 0.741
# 4. predict to raster stack
prediction_spatial <- terra::predict(predictor_stack, model, na.rm = TRUE)
Spatial Cross-Validation for model selection
Cross-validation (CV) methods are often employed to obtain optimal hyperparameter values. Therefore, the training data are split into
folds, and a model is trained on
-1 folds. The fold not used for model training is then used to obtain the test statistic. This is repeated over all folds, and the test metric is averaged over the
folds.
In spatial machine-learning, a spatial CV is often needed to prevent very similar data to be in the training and testing fold at the same time, which is often the case if training data are clustered and leads to overly optimistic CV error estimates. R packages that implement spatial CV include, e.g., blockCV and CAST. Here, we will explore the integration of those two with caret.
Hyperparameter tuning using spatial block cross-validation
The blockCV package implements different blocking methods for spatial CV. The resulting object of the main function blockCV::cv_spatial()
contains a nested list of the
folds and the training data rows that belong to each fold, as well as a list of the test data left out in each of the
iteration. These lists can be obtained using lapply()
and then be used as an input to the caret::trainControl()
function of caret that defines the CV strategy used in caret::train()
. The grid of hyperparameter values tested during CV is defined using the tune_grid
argument in caret::train()
. Here, we test mtry
values from 2 to 12 and min.node.size
values between 5 and 15. The combination of mtry
and min.node.size
that minimizes the RMSE is then automatically used to re-train a final model with the complete training data set.
set.seed(333)
spatial_blocks <- blockCV::cv_spatial(
temperature_train,
k = 5,
progress = FALSE
)
train test
1 126 33
2 126 33
3 128 31
4 128 31
5 128 31
train_ids <- lapply(spatial_blocks$folds_list, function(x) x[[1]])
test_ids <- lapply(spatial_blocks$folds_list, function(x) x[[2]])
tr_control_block <- caret::trainControl(
method = "cv",
index = train_ids,
indexOut = test_ids,
savePredictions = TRUE
)
hyperparameter_grid <- expand.grid(
"mtry" = c(2, 4, 6, 10, 12),
"min.node.size" = c(5, 10, 15),
"splitrule" = "variance"
)
model_spatial <- caret::train(
temp ~ .,
data = sf::st_drop_geometry(temperature_train),
method = "ranger",
trControl = tr_control_block,
tuneGrid = hyperparameter_grid,
num.trees = 100
)
model_spatial$finalModel
Ranger result
Call:
ranger::ranger(dependent.variable.name = ".outcome", data = x, mtry = min(param$mtry, ncol(x)), min.node.size = param$min.node.size, splitrule = as.character(param$splitrule), write.forest = TRUE, probability = classProbs, ...)
Type: Regression
Number of trees: 100
Sample size: 159
Number of independent variables: 22
Mtry: 10
Target node size: 5
Variable importance mode: none
Splitrule: variance
OOB prediction error (MSE): 0.8557959
R squared (OOB): 0.8952759
Hyperparameter tuning using target-oriented CV
Another spatial CV method is kNNDM, which is implemented in the CAST package and aims at emulating the prediction situation encountered by the model during CV. In this case, the prediction situation is to predict from the temperature measurement stations to the whole area of Spain. Since the temperature measurement stations are rather randomly distributed over the area of Spain, no spatial blocking is needed and kNNDM randomly assigns training points to CV folds. The output of kNNDM contains a list of row indices of training data points that are used in each CV-iteration (indx_train
), as well as of indices that are left out in each iteration (indx_test
). These lists can easily be used as input to the caret::trainControl()
function of caret that defines the CV used in caret::train()
.
knndm_folds <- CAST::knndm(
tpoints = temperature_train,
modeldomain = spain,
space = "geographical",
clustering = "kmeans",
k = 5
)
tr_control_knndm <- caret::trainControl(
method = "cv",
index = knndm_folds$indx_train,
indexOut = knndm_folds$indx_test,
savePredictions = TRUE
)
hyperparameter_grid <- expand.grid(
"mtry" = c(2, 4, 6, 10, 12),
"min.node.size" = c(5, 10, 15),
"splitrule" = "variance"
)
model_knndm <- caret::train(
temp ~ .,
data = sf::st_drop_geometry(temperature_train),
method = "ranger",
trControl = tr_control_knndm,
tuneGrid = hyperparameter_grid,
num.trees = 100
)
model_knndm$finalModel
Ranger result
Call:
ranger::ranger(dependent.variable.name = ".outcome", data = x, mtry = min(param$mtry, ncol(x)), min.node.size = param$min.node.size, splitrule = as.character(param$splitrule), write.forest = TRUE, probability = classProbs, ...)
Type: Regression
Number of trees: 100
Sample size: 159
Number of independent variables: 22
Mtry: 12
Target node size: 10
Variable importance mode: none
Splitrule: variance
OOB prediction error (MSE): 0.8728343
R squared (OOB): 0.8931909
Feature selection using target-oriented CV
To reduce the number of environmental predictors, and thus enhance the generalizability of the model, feature selection is commonly applied in machine-learning workflows. CAST implements Forward-Feature-Selection, that can be used with spatial CV. Here, we use the results of the hyperparameter tuning above and kNNDM CV to select the most relevant features. Plotting the results of FFS()
shows that the variables DEM
, Y
, EDF5
and primaryroads
were selected.
selected_hyperparams <- model_knndm$bestTune
model_ffs <- CAST::ffs(
predictors = sf::st_drop_geometry(temperature_train)[, predictor_names],
response = sf::st_drop_geometry(temperature_train)$temp,
method = "ranger",
num.trees = 100,
trControl = tr_control_knndm,
tuneGrid = selected_hyperparams,
verbose = FALSE
)
plot(model_ffs, plotType = "selected")
# obtain prediction
prediction_ffs <- terra::predict(predictor_stack, model_ffs, na.rm = TRUE)
AOA
Lastly, the area which is too dissimilar from the training data for the models to make reliable predictions (area of applicability, AOA) is delineated using the function CAST::aoa()
. The function CAST::aoa()
takes as inputs the predictor stack, as well as the trained caret model. The resulting object contains the dissimilarity values, the threshold used to delineate the AOA (every dissimilarity value above this threshold is considered outside the AOA), as well as the final AOA raster. Since our training data are randomly distributed in the study area, most of the area falls within the AOA.
AOA_without_tuning <- CAST::aoa(
newdata = predictor_stack,
model = model,
verbose = FALSE
)
AOA_with_tuning <- CAST::aoa(
newdata = predictor_stack,
model = model_ffs,
verbose = FALSE
)
Compare predictions obtained by the un-tuned model vs the tuned model
par(mfrow = c(2, 2))
plot(prediction_spatial, main = "prediction without tuning")
plot(AOA_without_tuning$AOA, main = "AOA without tuning")
plot(prediction_ffs, main = "prediction with model selection")
plot(AOA_with_tuning$AOA, main = "AOA with model selection")
Conclusion
caret has no functions that explicitly deal with spatial data. However, due to its rather flexible design, caret is compatible with several packages designed for spatial machine-learning. The caret::trainControl()
takes a list of CV indices as input, which makes it quite flexible to work with the output of e.g. CAST::knndm()
and blockCV::cv_spatial()
. Furthermore, caret is easy to use due to its functional programming paradigm. The documentation is extensive, and it’s rather easy to find modelling algorithms and their hyperparameters. Lastly, it should be noted that caret is not actively developed, since its main developer moved to tidymodels.
This blog post was originally written as a supplement to the poster “An Inventory of Spatial Machine Learning Packages in R” presented at the FOSSGIS 2025 conference in Muenster, Germany. The poster is available at https://doi.org/10.5281/zenodo.15088973.
Citation
BibTeX citation:
@online{linnenbrink2025,
author = {Linnenbrink, Jan},
title = {Spatial Machine Learning with Caret},
date = {2025-05-14},
url = {https://geocompx.org/post/2025/sml-bp2/},
langid = {en}
}
For attribution, please cite this work as:
Linnenbrink, Jan. 2025.
“Spatial Machine Learning with
Caret.” May 14, 2025.
https://geocompx.org/post/2025/sml-bp2/.
Continue reading: Spatial machine learning with caret
Analysis of Spatial Machine Learning Involving the Caret Methodology
In the field of spatial data analysis, the caret technique is becoming progressively auxiliary due to its inherent compatibility with multiple spatial machine-learning packages. The recent blog post from xy has illustrated how the robust machine-learning tool, caret, can be combined with specific techniques to accommodate spatial data.
The author replicates the predictive model of Spain’s air temperature by utilizing various R packages, such as caret, CAST, blockCV, sf and terra. The model establishes a relationship between air temperature and specific spatial variables within Spanish territories. The particularly innovative aspect of this model is the incorporation of spatial cross-validation methodologies to ensure better performance.
Long-Term Implications & Future Developments
With the rising interest and increasingly diverse requirements in spatial analysis, the utilization of caret in spatial machine learning would become more prevalent due to its versatility and adaptability. It would enable more robust and accurate spatial predictions and analyses, such as forecasting climate variables, predicting disease spread or assessing resource allocation.
Additionally, the applicability of this approach is set to increase as newer and more specialized spatial data analysis packages develop and become mainstream. Also, as spatial data become more accessible, we can expect more complex and sophisticated spatial models to be developed. In terms of machine learning, we could see more advanced, nuanced techniques, as well as models that integrate both spatial and non-spatial data.
Actionable Advice
- With the increasing prevalence in the usage of spatial data, organizations dealing with geographic data should consider investing in tools for spatial machine learning, like caret, to leverage the benefits of predictive modeling and exploratory analysis. It would empower them to gain comprehensive insights into their data and make more intelligent decisions.
- Organizations and data analysts should prioritize the skill-building of utilizing R packages such as caret for spatial data handling. These skills are increasingly valuable in a myriad of professional domains, including but not limited to urban planning, healthcare, real estate, and environmental science.
- The integration of spatial machine learning in operational practices can boost effectiveness by utilizing data effectively to draw sophisticated insights. For instance, public health officials can predict potential outbreaks in specific locations by studying patterns in spatial data using machine learning.
- Researchers and data scientists should contribute to the evolution of caret and similar spatial data analysis packages that accommodate diverse requirements. This could further expand the horizon of spatial data analysis.
Read the original article