utf8

#  Ashaar: Automatic Analysis and Generation of Arabic Poetry Using Deep
Learning Approaches

Zaid Alyafeai  Maged S. Al-Shaibani  Moataz Ahmed
King Fahd University of Petroleum and Minerals
Dhahran, Saudi Arabia
<EMAIL_ADDRESS>
###### Abstract

Poetry holds immense significance within the cultural and traditional fabric
of any nation. It serves as a vehicle for poets to articulate their emotions,
preserve customs, and convey the essence of their culture. Arabic poetry is no
exception, having played a cherished role in the heritage of the Arabic
community throughout history and maintaining its relevance in the present era.
Typically, comprehending Arabic poetry necessitates the expertise of a
linguist who can analyze its content and assess its quality. This paper
presents the introduction of a framework called Ashaar
111https://github.com/ARBML/Ashaar, which encompasses a collection of datasets
and pre-trained models designed specifically for the analysis and generation
of Arabic poetry. The pipeline established within our proposed approach
encompasses various aspects of poetry, such as meter, theme, and era
classification. It also incorporates automatic poetry diacritization, enabling
more intricate analyses like automated extraction of the Arudi style.
Additionally, we explore the feasibility of generating conditional poetry
through the pre-training of a character-based GPT model. Furthermore, as part
of this endeavor, we provide three datasets: one for poetry generation,
another for diacritization, and a third for Arudi-style prediction. These
datasets aim to facilitate research and development in the field of Arabic
poetry by enabling researchers and enthusiasts to delve into the nuances of
this rich literary tradition.

##  1 Introduction

In a general setting, Arabic poetry could be divided into two forms: rhymed or
measured and prose. Rhymed poetry was first introduced and theorized by al-
Farahidi (711 – 786 A. D.) who categorized every poem into one of 15 different
classes, later extended to 16, called meters or Buhur as pronounced in Arabic.
These meters govern how each poem should be constructed with specific rules
called Arud or Arudi Style. The main constructs of Arud could be represented
using Tafeelat as plural or Tafeelah as singular for easier memorization. Such
constructs could be used to define how to create each meter using a finite set
of rules. Another important part of Arabic poetry is Qafiyah which refers to
the end rhyme pattern or the rhyme scheme used in the poem. The construction
of meters depends on diacritics which are special symbols assigned to each
letter in the poem. These diacritics are categorized as either harakah or
sukun. Analyzing poems usually needs expertise in the field to figure out the
consistent meter and find out issues if there are any. Poets, nevertheless,
have an intrinsic ability to construct poems from a specific meter without the
need to consult experts. Recently, in the modern era, many poets were
influenced by western culture resulting in a new form of poetry called prose
poetry. Prose poetry is loose in terms of rules but has some structure and
rhythm although not in a strict format. Modern poets used poetry as a medium
to express various emotions and feelings. Prose poetry is similar to English
poetry in the way it is constructed but, due to its long history, Arabic
poetry is richer in terms of metaphors and symbolism.

Figure 1: General pipeline for Ashaar.

In this paper, we utilize deep learning approaches to analyze and generate
poetry. A high-level pipeline is shown in Figure 1. We summarize our
contributions as the following:

  1. 1.

We create four public datasets: Ashaar
dataset222https://huggingface.co/datasets/arbml/Ashaar_dataset is a labeled
dataset with meter, theme, era, etc. that could be used for conditional poetry
generation. Ashaar
diacritized333https://huggingface.co/datasets/arbml/Ashaar_diacritized is a
cleaned dataset with diacritized poems. Ashaar
arudi444https://huggingface.co/datasets/arbml/Ashaar_ardui is a dataset that
gives gold Arudi representations for a given set of verses. Ashaar
tafeelah555https://huggingface.co/datasets/arbml/Ashaar_tafeelah which
contains all the possible tafeelat for a given meter.

  2. 2.

We provide five pre-trained models. Three classification models for era,
theme, and meter. One pre-trained model for diacritization. And, a pre-trained
model for conditional poetry generation.

  3. 3.

We introduce a framework named Ashaar for poetry analysis and generation. The
analysis part uses the meter and diacritization models to predict the Arudi
form. While, the generation part uses the meter, qafiyah, and theme to
generate poem completion.

##  2 Literature Review

Many studies have been proposed to analyze and study the Arabic poetry metric
system. Most of such efforts are directed towards linguistic libraries.
Ziyovuddinova (2021) Manna and Arifin (2021), Paoli (2001), and Maling (1973)
are just examples of the literary work advocated to the subject.

Below is a list of the tasks we found in the literature that deals with Arabic
poetry from various aspects. These tasks include Authorship Attribution, meter
classification, emotion and era classification, poetry identification from
textual sources, poetry generation, and other miscellaneous tasks.

###  2.1 Authorship Attribution

In Arabic literature, there are many studies that dealt with authorship
attribution in general text. Al-Sarem et al. (2020), Altakrori et al. (2018),
Altheneyan and Menai (2014), and Hajja et al. (2019) are instances of various
methods used to approach this problem for general Arabic text. For a special
format of Arabic text like poetry, limited work has been proposed.

Ahmed et al. (2016) used machine learning methods such as Support Vector
Machines (SVM) and Sequential Minimal Optimization (SMO) to study the problem
of the Authorship Attribution of Arabic poetry. The features they extracted
from poetry cover characters, lexical syntactic, and semantic features. They
applied their methods to a corpus of poems belonging to 54 poets. They
achieved 98% precision for SMO as the best score.

Al-Falahi et al. (2015) attempted to approach this problem using Markov
chains. They conducted their experiments on characters and other syntactically
crafted features. The experiments were conducted on a dataset of 33 samples
from 33 authors for training and another different 33 unknown samples for
testing. They achieved more than 96% accuracy score on the test set.

Albaddawi and Abandah (2021) developed a deep-learning model to identify
poetry authors. The features they used are a fusion of the character
embeddings and an LSTM-based pre-trained meter classification model. This
architecture was evaluated on a dataset of more than 100k verses from 10
famous Arabic poets. They achieved around 81% accuracy.

On a different direction, Omer and Oakes (2017) utilized Arud words encoding
as binary features for prose Authorship Attribution. They compare this set of
features to another baseline of only considering the most frequent 100 words.
They showed that their method is superior compared to this baseline. They
tested their method on two different sets of Arabic and English texts.

###  2.2 Meter Classification

The work on textual Arabic meter classification can be divided into two main
categories based on the techniques used. The first category covers the
techniques that are rule-based while the second category approached this
problem using deep learning methods. The prominent drawback of the first
approach is that it requires the poetry text to be diacritized either fully or
partially. Another characteristic of this category is that it has been
evaluated on relatively small datasets as compared to the second category. The
largest evaluation study is reported by (Alabbas et al., 2014) consisting of
less than 7k verses. Below, we survey the literature for both approaches.

Traditional Machine Learning Several methods have been proposed to classify
Arabic poetry meters. Mohammad (2009) proposed a Naive Bayes while Ismail et
al. (2010) proposed a knowledge-based framework. Saleh and Elshafei (2012)
filed a patent for a system that classifies poetry from acoustic as well as
textual input. Alnagdawi et al. (2013), Alabbas et al. (2014), and Abuata and
Al-Omari (2018) proposed rule-based systems. Ahmed and Trausan-Matu (2017)
introduced a rule-based system to analyze the rhyme of the poem. Berkani et
al. (2020) created a matching pattern approach where the verse is matched
against a curated set of meter patterns. Zeyada et al. (2020) suggested a
system that extends the meter classification task for modern Arabic poetry,
albeit that modern Arabic poetry does not need to follow a meter, unlike
classical poetry. Alqasemi et al. (2021) evaluated traditional machine
learning techniques on a partial dataset proposed by Al-Shaibani et al.
(2020a).

Deep Learning Yousef et al. (2019) is the first work that utilizes deep
learning for this task for all the 16-meter classes. They also tried to
approach this task in English and Arabic languages. It is worth noting that
Arabic poetry classes are 16 as compared to only 4 meters in English. This
makes the task more complex to approach for Arabic. In their research, they
introduced, APCD, a large dataset of 1.5M verses of Arabic poetry. The model
they proposed is RNN-based. The results they achieved are 96.38% and 82.31%
for Arabic and English respectively. Al-Shaibani et al. (2020a) proposed a
GRU-based model to classify Arabic poetry meters. The model is a 5-layer
stacked GRU followed by two dense layers. The dataset introduced in this
research is MetRec Al-Shaibani et al. (2020b) constituting more than 55.4K
verses of 14-meter classes. The result they achieved is 94.3% on the accuracy
score. Abandah et al. (2020) extended the work done by Al-Shaibani et al.
(2020a) and Yousef et al. (2019) on this task. They introduced a larger RNN-
based model evaluated on a dataset of poetry and prose, 17 classes in total.
They introduced the APCD2 dataset which is an extended version of APCD with
the prose class. In their research, they mark the use of diacritics as
optional in contrast to Al-Shaibani et al. (2020a) where these characters are
removed from the input stream. The results they reported crossed 97% accuracy
on this task.

###  2.3 Emotion and Era classification

In the literature, there is a lot of focus to work on era classification as
compared to theme classification.

Theme Classification Alsharif et al. (2013) investigated the promise of
machine learning methods to address the task of Arabic poetry emotion
classification. The dataset they collected consists of 1,231 Arabic poems
variable in length with four major emotional classes: Retha (Elegiac), Ghazal
(love or romance), Fakhr (pride or honor), and Heja (Satire). They
experimented with Naive Bayes classification, SVM, Voting Features Intervals
(VFI), and Hyperpipes. They reported the results of their experiments in
precision, recall, and F-measure. They showed that VFI outperforms others in
terms of F-Measure with a result of around 73%.

Era Classification Depending on a set of literary features, Arabic scholars
divided the Arabic poetry timeline into a couple of time segments based on
either political status or literary features specific to that period of time
or location. These segments are called eras. Abbas et al. (2019) tried to
classify Arabic poetry into its recitation era. The era classes they worked on
are 5 ranging from pre-Islamic era to Andalusian era. The dataset comprised a
set of more than 30k poems belonging to these different classes. Various
machine learning methods have been experimented with this dataset. They showed
that Multinomial Naive Bayes achieved the best performance with an F1-score of
68.8% and a kappa score that is very close to 0.4. Orabi et al. (2020)
proposed a deep learning-based approach to address era classification. The
dataset they used is scraped from the web. It consists of 60,377 poems in
classical Arabic recited by 739 poets. They developed two deep learning-based
models and compared their performance. The first is a classification model
with FastText (Bojanowski et al., 2017) embeddings while the second is a CNN-
based model. They showed that the CNN model was superior achieving more than
91% result on F1-score in terms of binary classification into modern and non-
modern poetry. Khorsheed and Al-Thubaity (2013) proposed a comprehensive study
on Arabic text classification with different textual styles including poetry.
The poetry dataset they used comprised 1.95K documents with different 6
classes. They tried different features selections methods along with different
machine learning classifiers. The best classification results they achieved
were for the C5.0 classifier with 80% on average for all styles and 50%
accuracy for poetry only. They attributed this low results to the difficulty
of the classification task on creative materials like poetry. Gharbat et al.
(2019) evaluated various classification models for classify poetry from
Abbasid and Andalusian eras. The evaluated models are logistic regression,
random forest, decision trees, and SVM. They evaluated these models on a
curated dataset from the web. The dataset contains around 10,895 hemistiches
(half a verse) of 15 random poems by 15 poets. Their experiments showed that
SVM achieved the best performance.

###  2.4 Poetry Generation

With the recent advancement of deep learning approaches, there were many
attempts in the literature to generate Arabic poetry.

Talafha and Rekabdar (2019) proposed a GRU-based approach to generate Arabic
poetry. They trained their model on a dataset comprising more than 20.1k poems
with 80.5K verses collected from the web. For evaluation, they conducted two
types of evaluations: quantitative and qualitative. For quantitative analysis,
the BLEU score was used. For qualitative, they involved human subjects to
evaluate the generated poetry.

Beheitt and Hmida (2022) proposed a GPT-based model to generate poetry. The
model was trained from scratch. The methodology they followed is first
training the GPT model on a newswire dataset to develop language understanding
and then fine-tuning the model on a poetry dataset. The model was evaluated on
BLEU as well as human evaluation. They showed that their approach outperformed
other approaches that are based on elementary architectures like RNNs and
GRUs. Elkaref et al. (2022) evaluated the poetry generation task on two
transformer-based models with two different promoting settings. The evaluated
models are BERTShared Rothe et al. (2020) and GPT-j Wang and Komatsuzaki
(2021) and the prompting methods are rhythm or topic based. The dataset used
for this research is a fused collection of an earlier version of Ashaar and a
public dataset published in GitHub Ahm . They found out that GPT-J is better
at capturing the rhyme while BERTShared is better at generating fluent poems.
Abboushi and Azzeh (2023) fine-tuned AraGPT2 Antoun et al. (2020) to generate
poems. The dataset they used to fine-tune the pre-trained model is APCD. In
one of the proposed experiments, the model was constrained to generate poetry
from a specific meter. For evaluation, they used the BLUE score as well as
human evaluation where they showed that this fine-tuning procedure
outperformed all proposed approaches in the literature. They also showed
another study with fake-generated poetry presented to subjects with limited
poetic knowledge. They showed that the generated poetry was able to fool at
least 61% of the population.

###  2.5 Poetry Identification from the Web

Almuhareb et al. (2013) proposed a system to identify poetry from a text
document. The proposed system relies extensively on the structural patterns of
textual poetry. The system is evaluated on collected data from the web. The
dataset has 23K lines with 161 classical poem instances. The method achieved
an F-measure of 95%. Almuhareb et al. (2015) extended their work by
considering modern poetry that is different in style than classical poetry.
The method is similar to the one with classical poetry in the sense that it
focuses on the structural patterns of modern poetry. The method was evaluated
on a dataset of 2,067 plain text documents containing 513 modern Arabic poems.
The method achieves an accuracy of more than 99.81%. Almuhareb (2016)
developed a system for recalling Arabic poetry material from the web. The
system consists of two main components, a classifier, and a distiller. The
classifier classifies whether a page contains poetic material while the
distiller absorbs the poetic material from the selected page. The system
achieves a precision of 94% on an initially selected 14 domains as a seed
list.

###  2.6 Miscellaneous Tasks

Khan (2014) applied the Arud meter system as a stenography tool. The idea is
that the poem will be used as a cover message. Its binary representation is
used to hide the secret message with the help of some special Arabic
characters like diacritics. They compared their approach with other methods in
the literature and they showed that their method outperforms others in the
literature in the capacity score. Abandah et al. (2020) investigated the model
architecture proposed by Abandah and Abdel-Karim (2020) which was designed for
prose text to automatically diacritize Arabic poetry. They evaluated the model
on an extended version of the dataset proposed by Yousef et al. (2019). They
selected samples where the diacritization ratio is 0.5 or higher resulting in
368.6K verses. The results they showed are 6% and 20% for DER and WER
respectively where it was 1.9% and 5.1% respectively for prose.

##  3 Datasets

The release of large Arabic poetry datasets did not happen until recently with
the surge of deep learning. The first sufficiently large dataset published
were, MetRec Al-Shaibani et al. (2020b), APCD Yousef et al. (2019), and APCD
2.0 Abandah et al. (2020). MetRec is the smallest among the three of these
datasets. It contains verses from the most frequent 14 meters of Arabic poetry
with a total of 55.4K verses. APCD is a massive dataset compared to MetRec
with more than 1.8M verses containing samples from all 16 meters. APCD was
extended by Abandah et al. (2020) introducing APCD2.0. They added another
class for prose to distinguish poetry from prose in their proposed
classification model. Ashaar dataset extends APCD by adding more poetry while
considering more sources. We also added a column for the poem theme which was
not available in APCD. Table 1 compares APCD with Ashaar. As can be seen from
this table, Ashaar is almost an order of magnitude larger than APCD in terms
of verses and poets. This plenty of poetic data along with poets is useful for
many tasks concerning poetry generation such as language modeling and
authorship attribution. It can be noted from the table that Ashaar is also
larger in terms of diacritized verses. In this comparison, we considered
verses where diacritics constitute more than 25% of its characters. This is
helpful for tasks that involve diacritics predictions.

| APCD | Ashaar
---|---|---
Poems | - | 254,630
Poets | 3,569 | 7,167
Verses | 1,831,770 | 3,857,429
Verses with meter | 1,739,436 | 1,947,648
Verses with theme | - | 1,757,639
Verses with era | 1,831,770 | 1,899,567
Diacritized verses | 817,756 | 1,389,564
Table 1: Comparison between Ashaar dataset and APCD on different aspects. Table 2: Comparison between our model and Abandah et al. (2020). We compare our models as a combination of dataset size and diacritics training. Also, we show the speed of running inference per 1024 batch size.  Model/Metric | Diacritics | Training Corpus size | Prediction Time / 1024 | Accuracy
---|---|---|---|---
Abandah et al. (2020) | ✓ | 1,493,086 | 388 ms | 96.18 %
Transformer Model | ✓ | 806,062 | 84 ms | 95.51 %
Transformer Model | ✓ | 1,460,255 | 84 ms |  96.24 %
Abandah et al. (2020) |  | 1,493,086 | 388 ms | 94.18 %
Transformer Model |  | 806,062 | 84 ms | 93.90 %
Transformer Model |  | 1,460,255 | 84 ms |  95.22 %

##  4 Poetry Classification

In this section, we mainly discuss three types of classifications which are
era, theme, and meter classification. In each subsection, we illustrate the
dataset used and the architecture for training.

###  4.1 Meter Classification

As discussed in the literature, there are mainly 16 meters that govern how
each poem should be constructed. In this subsection, we discuss our approach
to generating a system that can predict a meter for a given poem.

#### Preprocessing and Augmentation

We first remove duplicates from the training corpus that exist in the testing
corpus. Then for each verse in the training corpus, we split the two parts
using a special symbol #. We then remove all special characters except for the
hashtag and diacritics. After that, we augment the corpus by randomly
splitting each bait using # then randomly swap the first and second parts.
Also, to make the corpus more robust against partial diacritization at each
step of training we randomly remove diacritics. We end up with 1,717,948
verses for training. We use a 15% subset for validation. For testing, we use a
dataset of size 362,798 verses.

Figure 2: Model architecture for the meter classification model.

#### Training and Results

We use a transformer base model with multi-head attention. We start with an
embedding of size 64. We use a transformer block with two dense layers at the
end with ReLU activation functions. The transformer block contains, multi-head
attention followed by dropout and layer normalization with a skip connection.
We then add 3 Bidirectional GRU layers followed by one dense layer. The last
block contains the same skip connections as in the previous block. In Figure
2, we show the main architecture of the model. We train the model for 15
epochs and we save the model that achieves the best validation accuracy. In
Table 2, we compare the results of our transformer base model to the work of
Abandah et al. (2020). We mainly compare training on the smaller dataset and
larger dataset with and without diacritics. Our base model trained on
comparable corpus compared to the state of the art achieves better results
with and without diacritics on the test set. Also, our models are 4 times
faster in terms of inference when evaluated on a Tesla T4 machine with around
16GB of memory.

###  4.2 Era Classification

We group the classes of poems into four main eras in Hijri corresponding to 1)
before Islam - 132, 2) 132-232, 3) 232 - 784, and 4) 784-now. We use a max
length of 64 verses for each poem. We then fix the max size of each class into
50,000 poems in order to avoid bias towards classes with many poems. For
tokenization, we use a sentence-piece tokenizer and we create a model with a
10,000 vocabulary size with 128 max number of tokens for each poem. We train a
model with 3 bidirectional layers and two dense layers with a dropout of size
30% for 5 epochs with batch size 128. Figure 3, shows the confusion matrix on
the test set. We can notice that in general, we see confusion, especially in
consecutive eras.

Table 3: Time distribution of Arabic Poetry. The dates are in Hijri which is calculated using the Lunar calendar.  Era | Date (Hijri)
---|---
Umayyad | 041 - 132
Abbasid | 132 - 232
Al-Andalus | 113 - 172
Fatimid | 358 - 567
Ayyubid | 569 - 626
Mamluk | 648 - 784
Ottoman | 699 - 1200
Modern | 1200 - now
Figure 3: Confusion matrix for era classification.

###  4.3 Theme Classification

We group the classes of poems into four main categories that are, elegy (sad)
poems, lampoon (sarcasm) poems, boosting (praise) poems, and romantic poems.
We use a similar training setup as in era classification. Figure 4, shows the
confusion matrix on the test set. Generally, we observe that the model finds
it much more difficult to predict the correct classes as compared to the era
classification. We think the reason is the contamination of the dataset which
might contain a lot of incorrect labels.

Figure 4: Confusion matrix for theme classification. Table 4: Diacritization metrics on the test set of Ashaar. pre-training | DER | WER | DER* | WER*
---|---|---|---|---
Tashkeela | 20.40 % | 62.3 % | 18.22 % | 50.42 %
Ashaar |  14.03 % |  47.97 % |  12.09 % |  36.09 %

##  5 Poetry Diacritization

In this section, we try to tackle the problem of diacritizing Arabic poetry.
Usually, poetry contains many classical words and metaphors which makes
assigning diacritics to sentences more challenging.

###  5.1 Training datasets

We use the Tashkeela dataset for pre-training the model Zerrouki and Balla
(2017). Since the dataset doesn’t contain any splits, we utilize the splits
suggested by Fadel et al. (2019) which contains 50k training, 2.5k validation,
and 2.5k testing. For Ashaar, since there are many sentences that are not
diacritized we filter by percentages of diacritics. If the verse has more than
5% missing diacritics we discard it from training the model. We end up with
26,091 poems after also discarding short poems. We use 23,481, 1,305, and
1,305 for training, validation, and testing respectively. We utilize the word
error rate (WER), diacritics error rate (DER), WER without case ending called
WER*, and DER without case ending DER*.

###  5.2 Results

We use a 1-D convolution bank, highway network, and bidirectional GRUs from
Madhfar and Qamar (2020) as our main model for pre-training. We pre-train two
models, one on Tashkeela and another on the diacritized version of Ashaar. We
train each model for 10,000 steps and evaluate both on the test subset of
Ashaar. In Table 4, we compare the two training strategies for diacritization.
We observe that pre-training and then evaluating on Ashaar provide better
results.

##  6 Predicting Arudi Style

Each given meter has a closed set of tafeelat that represent how the meter
should be constructed. For example, the Taweel meter has this sequence where 1
represents harakah and 0 represents a sukun:

$\displaystyle\color[rgb]{0,.5,.5}\definecolor[named]{pgfstrokecolor}{rgb}{0,.5,.5}11010\,1101010\,11010\,110110$

When a verse or hemistich is created it should follow one of the permissible
representations. If the verse doesn’t follow the meter, we can map it to the
original sequence by addition, deletion, or flipping. As an example, the
following sequence could be mapped to the previous sequence using that
coloring scheme:

$\displaystyle\color[rgb]{0,.5,.5}\definecolor[named]{pgfstrokecolor}{rgb}{0,.5,.5}1101\color[rgb]{0,0,1}\definecolor[named]{pgfstrokecolor}{rgb}{0,0,1}0\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}0\,\color[rgb]{0,.5,.5}\definecolor[named]{pgfstrokecolor}{rgb}{0,.5,.5}1101010\,1101\color[rgb]{1,.5,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,.5,0}1\,\color[rgb]{0,.5,.5}\definecolor[named]{pgfstrokecolor}{rgb}{0,.5,.5}110110$

Using that representation, we can predict whether a given poem has any
problems as the following.

  1. 1.

We first created a dataset of all permissible changes of a given meter.

  2. 2.

For a given poem we diacritize it using the approach mentioned in section 5.
We then map every harakah to 1 and sukun to 0.

  3. 3.

Then we use our collected dataset to find the sequence with the largest cosine
similarity match. We utilize the built-in function in python SequenceMatcher
which gives a similarity score between input patterns. We can use our meter
classification model to also reduce the cost of the search.

This makes our algorithm robust because even if the verse doesn’t follow any
given Tafeelah if the diacritized form is not accurate we will still predict
the Tafeelah with high confidence. Furthermore, using our color coding
representation we will be able to predict if a given character needs to be
added, deleted or flipped. In order to assess the ability of our system to
predict correctly a given Arudi style, we created manually an independent test
set containing 100 hemstitches. We use our system to predict the patterns and
then compare the gold patterns to the output. Using that we get an average
score of 93.41% which indicates a high similarity score. We get 43% with an
exact match i.e. similarity score of 100% which indicates a precise approach.

Table 5: Descriptions of the special tokens used in the tokenizer. Functionality | Tokens
---|---
Poem separators | ["<|psep|>", "</|psep|>"]
Bait separators | ["<|bsep|>", "</|bsep|>"]
Verse separator | ["<|vsep|>"]
Themes | ["<|theme_0|>",..., "<|theme_17|>"]
Meters | ["<|meter_0|>",..., "<|meter_15|>"]
Unused tokens | ["<|res_0|>",..., "<|res_9|>"]
Other tokens | ["<|pad|>", "<|endoftext|>"]

##  7 Poetry Generation

In this section, we consider training a poetry model from scratch rather than
fine-tuning. Our early experiments show that usually poetry doesn’t work well
with word pieces (see Appendix A) so instead we retrain the whole model on
characters.

###  7.1 Data Preparation

Representation Our main objective is to train a model that can generate poetry
that preserves the meter, theme, and structure of classical poetry. To do
that, we introduce new types of tokens to the model as in Table 5. Below we
show a simple example of how to encode a given poem that contains two verses.
We use an HTML-like prompting approach to be applied for a given input poem.
Note that n is in the range(0, 15) and k in the range range(0, 17).

<|meter_n|> qafyiah <|theme_k|> <|psep|> <|bsep|> verse_1<|vsep|>verse_2
</|bsep|> </|psep|>

Note that, for poems that don’t have a meter we use our pre-trained meter
classification to predict that meter. To make the prediction more robust, we
use a majority vote over the poem to be more accurate. We filter out poems
that don’t match our meter classifier label. For the theme, we reserve a token
for unknown theme.

Data Cleaning and Filtration We apply the following cleaning procedures for
each poem

  1. 1.

We map characters using their Unicode representation.

  2. 2.

Remove poems that don’t have an even number of verses.

  3. 3.

Remove poems that have very small verses i.e number of characters less than 5.

  4. 4.

Remove poems with meters that are not one of the 16 classes we have.

We release our dataset pre-processed in that format in HuggingFace
666https://huggingface.co/datasets/arbml/Ashaar_dataset.

###  7.2 Training

For this task, we don’t remove any diacritics and we consider this as an
approach to generate poetry with diacritics as well. Training a GPT-based
model using BPE tokenization will be expensive because the frequency of word
pieces will be much less, especially with partially diacritized text. So, we
use a character-based tokenization approach. We train the model for 450,000
steps with batch size 16 and context size 512. The max vocabulary size is 121
which equals the number of characters plus diacritics in the corpus in
addition to the reserved tokens in Table 5. We use the default GPT-2
transformer-based
architecture777https://huggingface.co/docs/transformers/model_doc/gpt2 with 10
layers.

Table 6: Predicting conditional poetry based on the qafiyah, meter, and theme of the poem. قصيدة حزينه من بحر الكامل مع قافية بحرف الكاف يا صاحبيّ أفي تحمُّلِ ذاكا فمتى متى يُمْحى هواكا يا نومَ عينِى ما أطالَ تجلّدي طيفُ الخيالِ يطولُ في هجراكا |  قصيدة غزل من بحر البسيط مع قافية بحرف الهاء ما لي أراك كأنّي مستهاماً بها افتخرتَ بلذاتي وأبلاها فلذةُ القلبِ في أحشاء مسكنها ولذة العيش في أنات أحلاها
---|---
Table 7: Comparison to State of the Art in rhythm evaluation results. We compare the tokenizer, number of layers Top-n accuracy where n is varied across 1, 3, and, 5. Model | Tokenizer | Accuracy | Top-3 Accuracy | Top-5 Accuracy
---|---|---|---|---
Abboushi and Azzeh (2023) | BPE | 56.70 | - | -
Ashaar | Char | 64.40 | 69.40 % | 71.13

###  7.3 Evaluation

Evaluating language models is a difficult task, let alone poetry generation
which is a creative challenging task. For this purpose, we use a set of novel
evaluation metrics, to evaluate the generative power of our pre-trained
models.

Figure 5: Confusion matrix for rhythm evaluation.

#### Rhythm Evaluation

In order to evaluate how much rhythm is encoded in our generated poetry we use
meter classification for such a task. Given a generated poetry output we can
evaluate how much the model can generate poetry that belongs to the same meter
with high confidence. We use the same meter classification model that we
created in section 4.1. Because we can not force the model to generate certain
poetry, we use the model which gets a high accuracy to evaluate how much
rhythm is able to generate. At each step, we generate 10 verses for the 15
meters used in Abboushi and Azzeh (2023). We repeat the process 100 times for
each meter resulting in 1,500 generated poems. Then, we pass the generated
poems to our classification model to predict the meter. We use majority voting
to decide if the poem meter is correct. For Top-3 and Top-5 accuracy, we
predict correctly if one of the top 3 and 5 predicted meters contains the true
meter. In Table 7, we show the results and compare them to the work done by
Abboushi and Azzeh (2023). Even though, our model is much smaller it, still
achieves better results on the poem level. In Figure 5, we show the confusion
matrix for meter classification on the generated poetry. We mostly observe
that the more popular the meter the better results. Still, for 50% of the
meters, we achieve more than 90%.

#### Zero-shot Analysis

Zero-shot evaluation is used to evaluate how much pre-trained models can
incorporate or generalize to new tasks without explicit pre-training or fine-
tuning. The model was not pre-trained explicitly to predict diacritics for a
given text in a supervised way. In Table 8, we evaluate the correctness of our
model in predicting diacritics. We evaluate the model against our pre-trained
diacritization model in Section 5. We consider our model as the gold
prediction. We pre-train an unconditional character-based model on Ashaar and
evaluate its diacritization ability. We sample with different probabilities
and evaluate the DER and WER metrics. We observe that the model is able to
predict diacritics with at most a 50 % error rate.

Table 8: Zero shot evaluation on diacritics. We compare an unconditional pre-trained character-based GPT in zero-shot dicaritization abilities with different sampling rates. Sampling Probability | WER | DER
---|---|---
sampling with 2 | 88.77 % | 43.30 %
sampling with 3 | 88.57 % | 44.62 %
sampling with 5 | 90.71 % | 47.85 %
sampling with 7 | 91.18 % | 50.28 %

##  8 Conclusion

To summarize, our paper introduces a system called Ashaar capable of analyzing
and generating conditional poetry. Additionally, we curate multiple datasets
and assess their effectiveness in various tasks such as classification,
diacritization, Arud prediction, and conditional poetry generation.
Furthermore, we leverage this dataset to generate poetry and evaluate the
performance of our character-based model in diacritization, where we observe a
satisfactory level of proficiency.

##  9 Acknowledgement

We would like to thank the colleague of Computing and Mathematics at KFUPM for
providing the compute to train some of the models. Also, we would like to
thank ML Collective for providing compute part which was used to train the
generative models. We also would like to thank Omar Hammad, with whom we
discuss some of the ideas during the early phases of the project. In addition,
we would like to thank Kyle McDonald for providing the compute to pre-train
some of the earlier models.

## References

  * (1) Ahmedabdel-aal/arabic-poem-generator: A pytorch rnn model to generate arabic poems.  https://github.com/AhmedAbdel-Aal/Arabic-poem-Generator.  (Accessed on 03/17/2023).
  * Abandah and Abdel-Karim (2020) Gheith Abandah and Asma Abdel-Karim. 2020.  Accurate and fast recurrent neural network solution for the automatic diacritization of arabic text.  _Jordanian Journal of Computers and Information Technology_ , 6(2).
  * Abandah et al. (2020) Gheith A Abandah, Mohammed Z Khedher, Mohammad R Abdel-Majeed, Hamdi M Mansour, Salma F Hulliel, and Lara M Bisharat. 2020.  Classifying and diacritizing arabic poems using deep recurrent neural networks.  _Journal of King Saud University-Computer and Information Sciences_.
  * Abbas et al. (2019) Mourad Abbas, Mohamed Lichouri, and Ahmed Zeggada. 2019.  Classification of arabic poems: from the 5th to the 5th century.  In _International Conference on Image Analysis and Processing_ , pages 179–186. Springer.
  * Abboushi and Azzeh (2023) Omar Abboushi and Mohammad Azzeh. 2023.  Toward fluent arabic poem generation based on fine-tuning aragpt2 transformer.  _Arabian Journal for Science and Engineering_ , pages 1–13.
  * Abuata and Al-Omari (2018) Belal Abuata and Asma Al-Omari. 2018.  A rule-based algorithm for the detection of arud meter in classical arabic poetry.  _International Arab Journal of Information Technology_ , 15(4):1–5.
  * Ahmed et al. (2016) Alfalahi Ahmed, Ramdani Mohamed, and Bellafkih Mostafa. 2016.  Authorship attribution in arabic poetry using nb, svm, smo.  In _2016 11th International Conference on Intelligent Systems: Theories and Applications (SITA)_ , pages 1–5. IEEE.
  * Ahmed and Trausan-Matu (2017) Munef Abdullah Ahmed and Stefan Trausan-Matu. 2017.  A program for analyzing classical arabic poetry for teaching purposes.  _Rom. J. Hum.-Comput. Interact_ , 10(4):331–344.
  * Al-Falahi et al. (2015) A Al-Falahi, M Ramdani, M Bellafkih, and M Al-Sarem. 2015.  Authorship attribution in arabic poetry’context using markov chain classifier.
  * Al-Sarem et al. (2020) Mohammed Al-Sarem, Faisal Saeed, Abdullah Alsaeedi, Wadii Boulila, and Tawfik Al-Hadhrami. 2020.  Ensemble methods for instance-based arabic language authorship attribution.  _IEEE Access_ , 8:17331–17345.
  * Al-Shaibani et al. (2020a) Maged S Al-Shaibani, Zaid Alyafeai, and Irfan Ahmad. 2020a.  Meter classification of arabic poems using deep bidirectional recurrent neural networks.  _Pattern Recognition Letters_ , 136:1–7.
  * Al-Shaibani et al. (2020b) Maged S Al-Shaibani, Zaid Alyafeai, and Irfan Ahmad. 2020b.  Metrec: A dataset for meter classification of arabic poetry.  _Data in Brief_ , 33:106497.
  * Alabbas et al. (2014) Maytham Alabbas, Zainab A Khalaf, and Khashan M Khashan. 2014.  Basrah: an automatic system to identify the meter of arabic poetry.  _Natural Language Engineering_ , 20(1):131–149.
  * Albaddawi and Abandah (2021) Mohammad M Albaddawi and Gheith A Abandah. 2021.  Pattern and poet recognition of arabic poems using bilstm networks.  In _2021 IEEE Jordan International Joint Conference on Electrical Engineering and Information Technology (JEEIT)_ , pages 72–77. IEEE.
  * Almuhareb (2016) Abdulrahman Almuhareb. 2016.  Arabic poetry focused crawling using svm and keywords.  In _2016 4th Saudi International Conference on Information Technology (Big Data Analysis)(KACSTIT)_ , pages 1–4. IEEE.
  * Almuhareb et al. (2013) Abdulrahman Almuhareb, Ibrahim Alkharashi, Lama AL Saud, and Haya Altuwaijri. 2013\.  Recognition of classical arabic poems.  In _Proceedings of the Workshop on Computational Linguistics for Literature_ , pages 9–16.
  * Almuhareb et al. (2015) Abdulrahman Almuhareb, Waleed A Almutairi, Haya Al-Tuwaijri, Abdulelah Almubarak, and Marwa Khan. 2015.  Recognition of modern arabic poems.  _J. Softw._ , 10(4):454–464.
  * Alnagdawi et al. (2013) Mohammad A Alnagdawi, Hasan Rashideh, and Ala Fahed Aburumman. 2013.  Finding arabic poem meter using context free grammar.
  * Alqasemi et al. (2021) Fahd Alqasemi, AL-Hagree Salah, Nail Adeeb Ali Abdu, Baligh Al-Helali, and Ghaleb Al-Gaphari. 2021.  Arabic poetry meter categorization using machine learning based on customized feature extraction.  In _2021 International Conference on Intelligent Technology, System and Service for Internet of Everything (ITSS-IoE)_ , pages 1–4. IEEE.
  * Alsharif et al. (2013) Ouais Alsharif, Deema Alshamaa, and Nada Ghneim. 2013.  Emotion classification in arabic poetry using machine learning.  _International Journal of Computer Applications_ , 65(16).
  * Altakrori et al. (2018) Malik H Altakrori, Farkhund Iqbal, Benjamin CM Fung, Steven HH Ding, and Abdallah Tubaishat. 2018.  Arabic authorship attribution: An extensive study on twitter posts.  _ACM Transactions on Asian and Low-Resource Language Information Processing (TALLIP)_ , 18(1):1–51.
  * Altheneyan and Menai (2014) Alaa Saleh Altheneyan and Mohamed El Bachir Menai. 2014.  Naïve bayes classifiers for authorship attribution of arabic texts.  _Journal of King Saud University-Computer and Information Sciences_ , 26(4):473–484.
  * Antoun et al. (2020) Wissam Antoun, Fady Baly, and Hazem Hajj. 2020.  Aragpt2: Pre-trained transformer for arabic language generation.  _arXiv preprint arXiv:2012.15520_.
  * Beheitt and Hmida (2022) Mohamed El Ghaly Beheitt and Moez Ben Haj Hmida. 2022.  Automatic arabic poem generation with gpt-2.  In _ICAART (2)_ , pages 366–374.
  * Berkani et al. (2020) Abdelmalek Berkani, Adrian Holzer, and Kilian Stoffel. 2020.  Pattern matching in meter detection of arabic classical poetry.  In _2020 IEEE/ACS 17th International Conference on Computer Systems and Applications (AICCSA)_ , pages 1–8. IEEE.
  * Bojanowski et al. (2017) Piotr Bojanowski, Edouard Grave, Armand Joulin, and Tomas Mikolov. 2017.  Enriching word vectors with subword information.  _Transactions of the association for computational linguistics_ , 5:135–146.
  * El-Khair (2016) Ibrahim Abu El-Khair. 2016.  1.5 billion words arabic corpus.  _arXiv preprint arXiv:1611.04033_.
  * Elkaref et al. (2022) Nehal Elkaref, Mervat Abu-Elkheir, Maryam ElOraby, and Mohamed Abdelgaber. 2022\.  Generating classical arabic poetry using pre-trained models.  In _Proceedings of the The Seventh Arabic Natural Language Processing Workshop (WANLP)_ , pages 53–62.
  * Fadel et al. (2019) Ali Fadel, Ibraheem Tuffaha, Mahmoud Al-Ayyoub, et al. 2019.  Arabic text diacritization using deep neural networks.  In _2019 2nd international conference on computer applications & information security (ICCAIS)_, pages 1–7. IEEE.
  * Gharbat et al. (2019) Mohammad Gharbat, Heba Saadeh, and Reem Q Al Fayez. 2019.  Discovering the applicability of classification algorithms with arabic poetry.  In _2019 IEEE Jordan International Joint Conference on Electrical Engineering and Information Technology (JEEIT)_ , pages 453–458. IEEE.
  * Hajja et al. (2019) Maha Hajja, Ahmad Yahya, and Adnan Yahya. 2019.  Authorship attribution of arabic articles.  In _International Conference on Arabic Language Processing_ , pages 194–208. Springer.
  * Ismail et al. (2010) MA Ismail, M Eladawy, Hesham Keshk, and S Saleh. 2010.  Expert system for testing the harmony of arabic poetry.  _Journal of Engineering Sciences_ , 1:401–411.
  * Khan (2014) E Khan. 2014.  Using arabic poetry system for steganography.  _Asian Journal of Computer Science and Information Technology_ , 4(6):55–61.
  * Khorsheed and Al-Thubaity (2013) Mohammad S Khorsheed and Abdulmohsen O Al-Thubaity. 2013.  Comparative evaluation of text classification techniques using a large diverse arabic dataset.  _Language resources and evaluation_ , 47(2):513–538.
  * Madhfar and Qamar (2020) Mokthar Ali Hasan Madhfar and Ali Mustafa Qamar. 2020.  Effective deep learning models for automatic diacritization of arabic text.  _IEEE Access_ , 9:273–288.
  * Maling (1973) Joan Mathilde Maling. 1973.  _The theory of classical Arabic metrics._ Ph.D. thesis, Massachusetts Institute of Technology.
  * Manna and Arifin (2021) Hashim Saleh Manna and Zamri Arifin. 2021.  Metrics in arabic poetry.
  * Mohammad (2009) IA Mohammad. 2009.  Naive bayes for classical arabic poetry classification.  _Al-Nahrain Journal of Science_ , 12(4):217–225.
  * Omer and Oakes (2017) Ahmed Ibrahim Ahmed Omer and Michael Philip Oakes. 2017.  Arud, the metrical system of arabic poetry, as a feature set for authorship attribution.  In _2017 IEEE/ACS 14th International Conference on Computer Systems and Applications (AICCSA)_ , pages 431–436. IEEE.
  * Orabi et al. (2020) Mariam Orabi, Hozayfa El Rifai, and Ashraf Elnagar. 2020.  Classical arabic poetry: Classification based on era.  In _2020 IEEE/ACS 17th International Conference on Computer Systems and Applications (AICCSA)_ , pages 1–6. IEEE.
  * Paoli (2001) Bruno Paoli. 2001.  Meters and formulas: The case of ancient arabic poetry.  _Belgian journal of linguistics_ , 15(1):113–136.
  * Rothe et al. (2020) Sascha Rothe, Shashi Narayan, and Aliaksei Severyn. 2020.  Leveraging pre-trained checkpoints for sequence generation tasks.  _Transactions of the Association for Computational Linguistics_ , 8:264–280.
  * Saleh and Elshafei (2012) Al-Zahrani Abdul Kareem Saleh and Moustafa Elshafei. 2012.  Arabic poetry meter identification system and method.  US Patent 8,219,386.
  * Talafha and Rekabdar (2019) Sameerah Talafha and Banafsheh Rekabdar. 2019.  Arabic poem generation with hierarchical recurrent attentional network.  In _2019 IEEE 13th International Conference on Semantic Computing (ICSC)_ , pages 316–323. IEEE.
  * Wang and Komatsuzaki (2021) Ben Wang and Aran Komatsuzaki. 2021.  GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model.  https://github.com/kingoflolz/mesh-transformer-jax.
  * Yousef et al. (2019) Waleed A Yousef, Omar M Ibrahime, Taha M Madbouly, and Moustafa A Mahmoud. 2019\.  Learning meters of arabic and english poems with recurrent neural networks: a step forward for language understanding and synthesis.  _arXiv preprint arXiv:1905.05700_.
  * Zerrouki and Balla (2017) Taha Zerrouki and Amar Balla. 2017.  Tashkeela: Novel corpus of arabic vocalized texts, data for auto-diacritization systems.  _Data in brief_ , 11:147–151.
  * Zeyada et al. (2020) Sherif Zeyada, Mohamed Eladawy, Manal Ismail, and Hesham Keshk. 2020.  A proposed system for the identification of modem arabic poetry meters (imap).  In _2020 15th International Conference on Computer Engineering and Systems (ICCES)_ , pages 1–5. IEEE.
  * Ziyovuddinova (2021) Mukhlisa Ziyovuddinova. 2021.  Arud system in view of metric theory.  _The American Journal of Applied sciences_ , 3(05):234–239.

##  Appendix A Modern Poetry Generation

In this section, we discuss our experiments of pre-training on modern poetry.

###  A.1 Pre-training Dataset

This is a large dataset collected from around 10 Arabic newspapers El-Khair
(2016). Arabic newspapers are written in Modern Standard Arabic (MSA) which
really meets our needs. One more advantage of such newspapers is their
diversity. Topics are written in many domains, such as sports, politics,
economy, etc. The total size of the text is about 15GB with 1.5 billion words.
Working on such large datasets needs special techniques even in reading and
extracting some useful statistics. We read it in chunks in parallel settings
to speed up. We mainly use a GPT-2 architecture with context size 512 with 12
heads and 12 layers. In order to fit the model on a V100 with a reasonable
number of batch sizes we trained a model with the following parameters: We
reduced the context size (which refers to the number of tokens or history to
train in parallel) to half which is a reasonable compromise because usually
poems are not long. For training, we used the transformer-lm which is a
Pytorch implementation that allows training in multiple GPUs. We trained on a
4 x V100 machine with a 200 GB HDD drive, 32 virtual CPUs, and 120 GB memory.
The speed-up was around 2.6x compared to one GPU. However, in each epoch, the
speed up was reduced which might have been caused by some memory leak. The 120
GB memory was necessary to tokenize the 14GB dataset all at once. Training
using SentencePiece tokenizer. Training on the full corpus for around 10
epochs took around 20 days.

يا أمة الإسلام هبي من سباتك … و اخلدي من سباتك … فلقد غفوت قرون و اضطرب الوجود … منذ أجيال و شعوب تداولها … سكرة الأحلام حين الشعور … وفتون الأعالي من تراه يعودها … ذكرى أرق و دنيا دفينة لا ترجع |  وقالوا : إني سأمضي … فكنتين معي … لكي تحسي بقايانا … وراكضين على الدروب … بين المروج الحالمات … بعطر الهوى … ونسائم الربيع … حيث الهوى يقضم شفاهنا … ويأكل من رحيق الوداد … فكرة حائر
---|---
والأمر كل الأمر أنك غائبه … وأنا حضرت لأجملك بالغياب … وقبلك كنت أعرف أنني لا أحسن سوى الكلام … فكيف لك الحضور ؟ … لست الغياب |  الآن يا حبيبتي … هل تعلمين … ما معنى دمي الذي ينساب مبلولا في الفراغ … وكآبات النخيل على الأفق الحزين … وكأني أغزل الآن أنشودة سوداء … وأستعير … من ذكرى الرحيل إلها للمساء
Table 9: Predicting samples in free form.

###  A.2 Fine-tuning

There is a big shift in terms of context writing style and vocabulary from the
poetry of old traditional Arabic and the Modern Standard recent one. This will
cause undesirable results as the model is trained on a Modern Standard Arabic
text! We tried to limit or eliminate the old poetry to the best of our
capabilities. In terms of the datasets collected, we collected poetry from
three famous Arabic poetry websites: Aldiwan, Abudhabi poetry encyclopedia,
and Adab. Aldiwan and Abu Dhabi encyclopedia sources hold, kind of, similar
poetry in terms of structure, and categorization methodology. On the other
hand, Adab is more comprehensive and contains more recent poetry that is close
to MSA in terms of vocabulary and context and also more prose poetry than the
other two repositories. It is the best fit to be used in the transfer learning
task. Aldiwan and Abudhabi encyclopedia sources hold, kind of, similar poetry
in terms of structure, and categorization methodology. On the other hand, Adab
is more comprehensive and contains more recent poetry that is close to MSA in
terms of vocabulary and context and also more prose poetry than the other two
repositories. It is the best fit to be used in the transfer learning task.

We fine-tuned the pre-trained model on a poetry dataset. We experimented with
different approaches to see what is the effect on the generated poetry. First,
we trained on a poetry dataset that is based on meters extracted from Aldiwan.
However, we realized that the model was not able to preserve the meter.
Basically, it jumped between different meters. To see the effect of training
on a certain meter, we extracted all the poems that belong to a certain meter
which is Taweel. However, we realized something interesting. The generated
poetry was somehow meaningless because the model tried to pick specific words
to preserve the chosen meter. GPT-2 is a subword model but to generate a poem
from a certain meter, it has to have some knowledge about characters.
Moreover, there are 16 meters and training on the highest class (Taweel)
reduced the size of the dataset to only around 15 MB. Arabic is a
morphologically rich language and in order to capture language understanding
we need a larger dataset. Moreover, most of them were old and contained many
words that are not used anymore in modern literature. This created a
vocabulary shift between pre-training and fine-tuning. In order to overcome
these we only extracted modern poems from Adab. We created an algorithm to
clean the dataset and remove short poems as well as rhythmic poems. We ended
up with around a 26 MB dataset. We applied the same process for segmentation
and tokenization as we did for our pre-training. In addition, we added special
characters to recognize the end of poems “#” and “&” for the end of verses.
Training without these special characters mostly caused incoherent results. We
also did a lot of cleaning in order to increase the quality of generated
poems. We made sure to normalize the characters (Some characters had different
Unicode so we made sure that they are mapped to the same set of characters),
remove digits (some poems had digits indicating different parts of a given
poem), remove special characters (there was a lot of, metadata and diacritics.
We realized that the quality of the dataset affected a lot the generated poems
in some way or another. We did a lot of back and forth by fine-tuning,
inspecting the output, cleaning then fine-tuning again.

Then we fine-tuned our pre-trained model for around 200 epochs with the same
parameters. This time we fine-tuned the model on Google Colab with a single
V100 GPU for around three days. To see the effect of training longer we
analyzed the results after each 50 iteration. To see if the model memorized
some poems we randomly extracted some poems and ran the model for inspection.
We realized that the model learned a lot of variations in the generated poems.
We applied some post-processing approaches to increase the readiness of the
generated poems. We first segmented, replaced “&” and “#” with new lines, and
resolved some issues with FARASA which created some unneeded characters. For
inference, we append the special character “#” to the prefix indicating the
start of a new poem. We use the top 3 predictions for randomly predicting the
next token. We tested with larger numbers but it resulted in some bad output.
In Table 9, we show a sample of predicted modern poetry.


Now fix $\alpha=0,c=\frac{\left\lVert\overline{y}\right\rVert_{2}}{\delta}$.
Set $w=\delta\cdot\frac{\overline{y}}{\left\lVert\overline{y}\right\rVert}$.
Then we have that

$\displaystyle
S(\frac{\left\lVert\overline{y}\right\rVert_{2}}{\delta},0)=\frac{1}{n}\sum_{i=1}^{n}\left\lVert\overline{y}-y_{i}\right\rVert^{2}_{2}<\frac{1}{n}\sum_{i=1}^{n}\left\lVert
y_{i}\right\rVert^{2}_{2}$
$\displaystyle=\mathrm{Obj}^{A}_{\lambda}(\mathbb{0})$ (183)

The inequality comes from the fact that we assumed $\overline{y}\neq 0$ and
noting that $\overline{y}$ is the minimizer of the function
$p(z)=\frac{1}{n}\left\lVert z-y_{i}\right\rVert^{2}_{2}$. Continuity of $S$
ensures that there exists $\alpha_{0}>0$ such that

$\displaystyle
S(\frac{\left\lVert\overline{y}\right\rVert_{2}}{\delta},\alpha_{0})<\frac{1}{n}\sum_{i=1}^{n}\left\lVert
y_{i}\right\rVert^{2}_{2}$
$\displaystyle=\mathrm{Obj}^{A}_{\lambda}(\mathbb{0})$ (184)

Now consider
$U(t)=S((1+t)\frac{\left\lVert\overline{y}\right\rVert_{2}}{\delta},(1+t)\alpha_{0})$
for $t\geq 0$. Note that $U$ is continuous with respect to $t$. Furthermore,
we note that $t\rightarrow\infty$ implies $U(t)\rightarrow\infty$ which
implies there exists some time $t=T_{f}$ such that
$U(T_{f})>\mathrm{Obj}^{A}_{\lambda}(\mathbb{0})$. Therefore, by the
intermediate value theorem, there exists a time $t=T$ such that
$U(T)=\mathrm{Obj}^{A}_{\lambda}(\mathbb{0})$. Finally, set
$c=(T+1)\frac{\left\lVert\overline{y}\right\rVert_{2}}{\delta}$,
$\alpha=(T+1)\alpha_{0}$, and $g^{*}$ as the matrix where
$g^{*}_{1}=\delta\cdot\frac{\overline{y}}{\left\lVert\overline{y}\right\rVert}$
and $\mathbb{0}$ for the other columns. By equation 181 and equation 182 we
have

$\displaystyle\mathrm{Obj}^{A}_{\lambda}(g^{*}\circ
f_{\theta})=\inf_{g\in{\mathcal{G}}^{S}}\mathrm{Obj}^{A}_{\lambda}(g\circ
f_{\theta})=U(T)=\mathrm{Obj}^{A}_{\lambda}(\mathbb{0})$ (185)

Furthermore, if we choose another $\lambda^{\prime}\geq 0$, since
$c=(T+1)\frac{\left\lVert\overline{y}\right\rVert_{2}}{\delta}>\frac{\left\lVert\overline{y}\right\rVert_{2}}{\delta}$
by equation 182, we have that

$\displaystyle\mathrm{Obj}^{A}_{\lambda^{\prime}}({g^{*}}^{\prime}\circ
f_{\theta})=\inf_{g\in{\mathcal{G}}^{S}}\mathrm{Obj}^{A}_{\lambda^{\prime}}(g\circ
f_{\theta})$ (186)

and

$\displaystyle\frac{1}{n}\sum_{i=1}^{n}\left\lVert J_{{g^{*}}^{\prime}\circ
f_{\theta}}(x_{i})\right\rVert_{2}=\alpha\left\lVert{g^{*}}^{\prime}\right\rVert_{2}=\alpha\delta$
(187)

which is nonzero as $\delta>0$ and $\alpha=(T+1)\alpha_{0}>0$.

∎

Proof of C.4

Clearly, we have
${\mathcal{F}}^{A}_{\lambda_{2}}\subset{\mathcal{F}}^{A}_{\lambda_{1}}$. If we
can show that $f_{\theta_{1}}\not\in{\mathcal{F}}^{A}_{\lambda_{2}}$ then we
have
${\mathcal{F}}^{A}_{\lambda_{2}}\subsetneq{\mathcal{F}}^{A}_{\lambda_{1}}$.

Using lemma C.5 we can find $f_{\theta_{1}}\in{\mathcal{F}}^{A}_{\lambda_{1}}$
such that

$\inf_{g\in G^{S}}\mathrm{Obj}^{A}_{\lambda_{1}}(g\circ
f_{\theta_{1}})=\mathrm{Obj}^{A}_{\lambda_{1}}(\mathbb{0})$

In addition lemma C.5 guarantees minimizers $g^{*}_{1}$ and $g^{*}_{2}$ such
that

$\displaystyle\mathrm{Obj}^{A}_{\lambda_{1}}(g^{*}_{1}\circ f_{\theta_{1}})$
$\displaystyle=\inf_{g\in G^{S}}\mathrm{Obj}^{A}_{\lambda_{1}}(g\circ
f_{\theta_{1}})\,\textrm{and}\,\frac{1}{n}\sum_{i=1}^{n}\left\lVert
J_{g^{*}_{1}\circ f_{\theta}}(x_{i})\right\rVert_{2}>0$ (188)
$\displaystyle\mathrm{Obj}^{A}_{\lambda_{2}}(g^{*}_{2}\circ f_{\theta_{1}})$
$\displaystyle=\inf_{g\in G^{S}}\mathrm{Obj}^{A}_{\lambda_{2}}(g\circ
f_{\theta_{1}})\,\textrm{and}\,\frac{1}{n}\sum_{i=1}^{n}\left\lVert
J_{g^{*}_{2}\circ f_{\theta_{1}}}(x_{i})\right\rVert_{2}>0$ (189)

Thus, we have that

$\displaystyle\mathrm{Obj}^{A}_{\lambda_{1}}(g^{*}_{2}\circ f_{\theta_{1}})$
$\displaystyle=\hat{R}(g^{*}_{2}\circ
f_{\theta_{1}})+\lambda_{2}\cdot\epsilon\frac{1}{n}\sum_{i=1}^{n}\left\lVert
J_{g^{*}_{2}\circ f_{\theta_{1}}}(x_{i})\right\rVert_{2}$ (190)
$\displaystyle>\hat{R}(g^{*}_{2}\circ
f_{\theta_{1}})+\lambda_{1}\cdot\epsilon\frac{1}{n}\sum_{i=1}^{n}\left\lVert
J_{g^{*}_{2}\circ f_{\theta_{1}}}(x_{i})\right\rVert_{2}$
$\displaystyle\textrm{since}~{}\lambda_{2}>\lambda_{1}$ (191)
$\displaystyle\geq\hat{R}(g^{*}_{1}\circ
f_{\theta_{1}})+\lambda_{1}\cdot\epsilon\frac{1}{n}\sum_{i=1}^{n}\left\lVert
J_{g^{*}_{1}\circ f_{\theta_{1}}}(x_{i})\right\rVert_{2}$
$\displaystyle\textrm{def of }~{}g^{*}_{1}$ (192)
$\displaystyle=\mathrm{Obj}^{A}_{\lambda_{1}}(\mathbb{0})$ lemma C.5 (193)

Thus $f_{\theta_{1}}\not\in{\mathcal{F}}^{A}_{\lambda_{2}}$ which implies
${\mathcal{F}}^{A}_{\lambda_{2}}\subsetneq{\mathcal{F}}^{A}_{\lambda_{1}}$. It
remains to show for $\lambda_{1}\geq 0$, we have that
${\mathcal{F}}^{A}_{\lambda_{1}}\subsetneq{\mathcal{F}}$.

Consider any $g\in{\mathcal{G}}^{S}$. For $j\in[L]$, define $W^{j}$ as the
weight matrix where $W^{j}=I_{d\times d}$ (identity matrix) for $j\in[L-1]$
and let the final weight $W^{L}=B\cdot I_{d\times d}$ for some constant $B>0$.
Set the bias vectors $b^{j}=\mathbb{0}$ for $j\geq 2$. Let the first bias
equal $b^{1}=R\cdot\mathds{1}$ where $\mathds{1}$ is the vector of all 1’s and
$R$ is the upper bound such that $\left\lVert x\right\rVert_{\infty}\leq R$.
Set $\theta=(W^{1},b^{1},\dots,W^{L},b^{L})$ and let $h_{\theta}=g\circ
f_{\theta}$

We compute

$\displaystyle\mathrm{Obj}^{A}_{\lambda_{1}}(h_{\theta})$
$\displaystyle=\hat{R}(h_{\theta})+\lambda_{1}\cdot\epsilon\frac{1}{n}\sum_{i=1}^{n}\left\lVert
J_{h_{\theta}}(x_{i})\right\rVert_{2}$ (195)
$\displaystyle=\frac{1}{n}\sum_{i=1}^{n}\left\lVert
B(x_{i}+R\mathds{1})-y_{i}\right\rVert^{2}+\frac{1}{n}\sum_{i=1}^{n}\left\lVert
J_{h_{\theta}}(x_{i})\right\rVert_{2}$ (196)
$\displaystyle=\frac{1}{n}\sum_{i=1}^{n}\left\lVert
B(x_{i}+R\mathds{1})-y_{i}\right\rVert^{2}+B\left\lVert g\right\rVert_{2}$
(197) $\displaystyle\geq\frac{1}{n}\sum_{i=1}^{n}\left\lVert
B(x_{i}+R\mathds{1})-y_{i}\right\rVert^{2}+B\delta$ (198)

We note that sending $B\rightarrow\infty$ we get
$\mathrm{Obj}^{A}_{\lambda_{1}}(h_{\theta})\rightarrow\infty$ which implies
that there exists a $B=B^{\prime}$ such that
$\mathrm{Obj}^{A}_{\lambda_{1}}(h_{\theta})>\mathrm{Obj}^{A}_{\lambda_{1}}(\mathbb{0})$.
Setting $B=B^{\prime}$ implies
$f_{\theta}\not\in{\mathcal{F}}^{A}_{\lambda_{1}}$.

∎

##  Appendix D Extra Experiment Results

###  D.1 Absolute Transferability vs. Model Robustness

We show the absolute transferability versus robustness of different models in
Figure 8,9,10 and 11 respectively.

Figure 8: Robustness and absolute transferability when we control the norm of
last layer with last-layer regularization (LLR) and last-layer orthogonal
training (LLOT) with different parameters.

Figure 9: Robustness and absolute transferability when we regularize the
feature extractor with Jacobian Regularization (JR) and weight decay (WD) with
different parameters.

Figure 10: Robustness and absolute transferability when we use Gaussian noise
(Gauss) and posterize (Pos) as data augmentations with different parameters.

Figure 11: Robustness and absolute transferability when we use rescale and
blur as data augmentations with different parameters.

###  D.2 Absolute Transferability vs. Regularization Magnitude

We show the absolute transferability w.r.t. different regularization magnitude
in Fig 12,13,14 and 15 respectively. The green dashed line is the
transferability of vanilla trained model and the red dashed line is that of
adversarially trained model. We can observe that with most single
regularization or augmentation, the model transferability can be improved
compared with vanilla trained model and sometimes even outperform the
adversarially trained ones. In some cases (e.g. jacobian regularize), the
performance drops because the larger regularization hurts benign accuracy and
therefore the absolute transferability drops.

Figure 12: Absolute transferability when we control the norm of last layer
with last-layer regularization (LLR) and last-layer orthogonal training (LLOT)
with different parameters. Green dashed line is the transferability of vanilla
trained model and red dashed line is that of adversarially trained model.

Figure 13: Absolute transferability when we regularize the feature extractor
with Jacobian Regularization (JR) and weight decay (WD) with different
parameters. Green dashed line is the transferability of vanilla trained model
and red dashed line is that of adversarially trained model.

Figure 14: Absolute transferability when we use Gaussian noise (Gauss) and
posterize (Pos) as data augmentations with different parameters. Green dashed
line is the transferability of vanilla trained model and red dashed line is
that of adversarially trained model.

Figure 15: Absolute transferability when we use rescale and blur as data
augmentations with different parameters for ImageNet. Green dashed line is the
transferability of vanilla trained model and red dashed line is that of
adversarially trained model.

###  D.3 Results of Other Model Structures

To further validate our evaluation results, we evaluate the experiments on
another model structure. We use a simpler CNN model for CIFAR-10 to SVHN and a
more complicated WideResNet-50 for ImageNet to CIFAR-10. The CNN model
consists of four convolutional layer with $3\times 3$ kernels and 32,32,64,64
channels respectively, followed by two hidden layer with size 256. A $2\times
2$ max pooling is calculated after the second and fourth layer. Other settings
are the same as in the main text. Note that in some settings the new model
cannot converge, and therefore we will omit the result. In addition, Jacobian
regularization cannot be applied on WideResNet-50 because of the large memory
cost, so we do not include it in the figures. The results are shown in Figure
16, 17 and 18.

Figure 16: Robustness and transferability for the other model structure when
we control the norm of last layer with last-layer regularization (LLR) and
last-layer orthogonal training (LLOT) with different parameters.

Figure 17: Robustness and transferability for the other model structure when
we regularize the feature extractor with Jacobian Regularization (JR) and
weight decay (WD) with different parameters.

Figure 18: Robustness and transferability for the other model structure when
we use Gaussian noise (Gauss) and posterize (Pos) as data augmentations with
different parameters.

###  D.4 Robustness Evaluation with AutoAttack

Besides PGD attack, we also evaluate the model robustness using the stronger
AutoAttack. We use APGD-CE, APGD-T and FAB-T as the sub-attacks in AutoAttack
with 100 steps. Since the accuracy will decrease after the stronger attack, we
use a slightly smaller ${\epsilon}=0.2$ to better visualize the trend. The
results are shown in Fig. 19. We can observe that the trend is similar with
what we observed before when we used the PGD attack - domain generalization is
an effect of regularization and data augmentation, and it is sometimes
negatively correlated with model robustness. Also, augmentations like rotation
and translation, which violates the sufficient condition, do not improve the
domain generalization.

Figure 19: Relationship between robustness and transferability on CIFAR-10
when we use AutoAttack to evaluate model robustness.


# Low Complexity Adaptation for Reconfigurable Intelligent Surface-Based MIMO
Systems

Zehra Yigit, Ertugrul Basar, and Ibrahim Altunbas Z. Yigit and Ibrahim
Altunbas are with the Department of Electronics and Communication Engineering,
Istanbul Technical University, Maslak 34469, Istanbul, Turkey. E-mail:
<EMAIL_ADDRESS><EMAIL_ADDRESS>Basar is with the Communications
Research and Innovation Laboratory (CoreLab), Department of Electrical and
Electronics Engineering, Koç University, Sariyer 34450, Istanbul, Turkey.
E-mail<EMAIL_ADDRESS>
###### Abstract

Reconfigurable intelligent surface (RIS)-based transmission technology offers
a promising solution to enhance wireless communication performance cost-
effectively through properly adjusting the parameters of a large number of
passive reflecting elements. This letter proposes a cosine similarity theorem-
based low-complexity algorithm for adapting the phase shifts of an RIS that
assists a multiple-input multiple-output (MIMO) transmission system. A semi-
analytical probabilistic approach is developed to derive the theoretical
average bit error probability (ABEP) of the system. Furthermore, the validity
of the theoretical analysis is supported through extensive computer
simulations.

###### Index Terms:

Reconfigurable intelligent surfaces (RISs), multiple-input multiple-output
(MIMO), cosine similarity theorem.

††This work was supported by the Scientific and Technological Research Council
of Turkey (TÜBİTAK) under grant no 117E869.

##  I Introduction

The fifth generation (5G) wireless communication technology promises an
explosive growth on data rate, massive connectivity and latency performance.
To achieve these goals, various transmission technologies have been developed
in recent years. Massive multiple-input multiple-output (MIMO) and milimeter
wave (mmWave) communication systems are considered as some of the prominent
candidates among these technologies. On the other hand, to meet this challenge
beyond 5G requirements, utilization of an increasing number of multi-antenna
systems has raised strong concerns about the energy efficiency and hardware
cost of large-scale MIMO systems.

Recently, reconfigurable intelligent surface (RIS)-assisted communication
technology has been considered as a promising solution to overcome the energy
efficiency related issues of future wireless networks [1, 2, 3]. An RIS is a
planar metasurface that consists of a number of low-cost passive reflecting
elements, each of which smartly induces an independent phase shift to modify
the propagation environment in more favorable way for the communication
performance [4].

The unprecedented potential of RISs on the signal quality of a communication
system has led researchers to largely consider the RIS technology in various
frontiers. In one of the early studies [3], the error performance of an RIS
aided single-input single-output (SISO) system is investigated through a
mathematical framework. Also, in [5, 6], to improve the spectral efficiency,
the RIS aided index modulation (IM) systems have been proposed. Later, RISs
are considered for multiuser systems to enhance the energy efficiency [7] and
to maximize the signal-interference-noise ratio (SINR) [2, 8, 9]. Even more
recently, to facilitate practical implementation of the RIS aided systems, new
path loss models [10, 11], open-source channel models [12, 13] and a practical
phase shift model [14] have been developed.

Notably, most of the existing RIS-aided designs developed for multiple-input
single-output (MISO) [8, 7, 2, 15] and MIMO systems [1, 9] exploit
computationally intensive and complex algorithms. Specifically, no single
study exists performing a statistical analysis on the theoretical bit error
rate (BER) performance of RIS-aided multi-antenna systems.

In this letter, an efficient low-complexity algorithm, which is based on
cosine similarity theorem [16] and adapts the phase shift of each reflecting
elements, is proposed for RIS-aided MIMO (RIS-MIMO) and RIS-aided spatial
modulation (RIS-SM) schemes in which the transmission principles of classical
MIMO and classical SM [17, 5] are considered, respectively. Moreover, a semi-
analytical probabilistic model is developed to derive the average bit error
probability (ABEP) of the proposed RIS-MIMO and RIS-SM schemes. Furthermore,
through the comprehensive computer simulations, the BER performance of the
RIS-aided MIMO systems with the proposed algorithm is investigated for the
various conditions including perfect/imperfect channel estimation,
continous/discrete phase reflection and path loss effect.

The rest of this letter is structured as follows. In Section II, the system
model of the proposed RIS-aided MIMO transmission systems is presented. The
theoretical performance analysis of the system is carried out in Section III.
Computer simulation results are described in Section IV and the paper is
concluded in Section V111Notation: Bold lowercase and uppercase letters are
used for vectors and matrices, respectively. $(\cdot)^{\mathrm{T}}$,
$(\cdot)^{\mathrm{H}}$ and $||\cdot||$ stand for transposition, Hermitian
transposition and Euclidean/Frobenious norm operators, respectively.
$\operatorname{vec}(\cdot)$ denotes vectorization operator and $\det(\cdot)$
symbolizes determinant of a matrix. The Kronecker product and Euclidean inner
product of two vectors are denoted by $\otimes$ and $<\cdot,\cdot>$,
respectively. $\mathbb{C}^{a\times b}$ represents the set of $a\times b$
dimensional matrices while $\operatorname{diag}\left\\{\cdot\right\\}$
symbolizes a square diagonal matrix. $\mathcal{CN}(\mu,\sigma^{2})$ denotes
the complex Gaussian distribution of a random variable with $\mu$ mean and
$\sigma^{2}$ variance. $\mathcal{O}(\cdot)$ and $P(\cdot)$ stand for the big
$\mathcal{O}$ notation and probability of an event, respectively.
$\mathbf{I}_{n}$ denotes $n\times n$ identity matrix while $\mathbf{1}$
represents all-ones column vector. .

##  II System Model

In this section, the concept of the proposed low-complexity algorithm and the
system models of the RIS-MIMO and RIS-SM schemes are introduced. In the
proposed systems, the transmitter and the receiver are assumed to be equipped
with $T_{x}$ and $R_{x}$ antennas, respectively, as shown in Fig. 1. In
addition, an RIS with $N$ passive reflecting elements is used to improve the
communication performance by appropriately adjusting phase shift of each
reflecting element.

Figure 1: RIS aided MIMO Systems

Consider $\mathbf{H}\in\mathbb{C}^{N\times T_{x}}$ and
$\mathbf{G}\in\mathbb{C}^{N\times R_{x}}$ as the matrices of uncorrelated
Rayleigh fading channel from the transmitter to the RIS, and from the RIS to
the receiver, respectively, whose elements are independent and identically
distributed (i.i.d.) and follow $\mathcal{CN}(0,1)$ distribution. On the other
hand, $\mathbf{\Phi}\in\mathbb{C}^{N\times N}$ stands for the matrix of RIS
reflection coefficients with
$\mathbf{\Phi}=\operatorname{diag}\left\\{\beta_{1}e^{j\phi_{1}},\beta_{2}e^{j\phi_{2}},\ldots,\beta_{N}e^{j\phi_{N}}\right\\}$,
where $\phi_{i}\in[-\pi,\pi]$ is phase shift and $\beta_{i}\in(0,1]$ is the
amplitude reflection coefficient of the $i$th reflecting element, for
$i\in\left\\{1,2,\ldots,N\right\\}$. However, for the sake of simplicity, we
set $\beta_{i}=1$. Therefore, the composite MIMO channel matrix
$\mathbf{C}\in\mathbb{C}^{R_{x}\times T_{x}}$ from the transmitter to the
receiver becomes $\mathbf{C}=\mathbf{G}^{\mathrm{H}}\mathbf{\Phi H}$. In the
proposed systems, perfect channel state information (CSI) of all channels are
available at all nodes and quasi-static block fading channels are assumed.

###  II-A Proposed Algorithm

In this subsection, we develop a low-complexity algorithm to maximize the
average received signal-noise ratio (SNR) of the RIS aided MIMO systems, which
results in maximizing the overall channel gain of the system by arranging the
phase shift of each reflecting element. Then, using
$\mathbf{C}=\mathbf{G}^{\mathrm{H}}\mathbf{\Phi
H}=\sum_{i=1}^{N}\mathbf{g}_{i}^{H}e^{j{\phi}_{i}}\mathbf{h}_{i}$, our problem
is formulated as

$\displaystyle\vspace*{-0.3cm}\max_{{\phi}_{i}}\left\|\mathbf{C}\right\|=\max_{{\phi}_{i}}||\sum\nolimits_{i=1}^{N}\mathbf{g}_{i}^{H}e^{j{\phi}_{i}}\mathbf{h}_{i}||$
$\displaystyle\hskip 2.84544pt\mathrm{s.t.}\hskip 14.22636pt|e^{j\phi_{i}}|=1$
(1)

where $\mathbf{g}_{i}^{\mathrm{H}}$ and $\mathbf{h}_{i}$ stand for the $i$th
column and $i$th row of $\mathbf{G}^{\mathrm{H}}$ and $\mathbf{H}$,
respectively. Although the maximization problem in (1) is non-convex due to
the constraint $\phi_{i}\in[-\pi,\pi]$, the achievable channel gain can be
upper bounded as

$\left\|\mathbf{C}\right\|=||\sum\nolimits_{i=1}^{N}\mathbf{g}_{i}^{H}e^{j{\phi}_{i}}\mathbf{h}_{i}||\leq\sum\nolimits_{i=1}^{N}||\mathbf{g}_{i}^{\mathrm{H}}||\left\|\mathbf{h}_{i}\right\|.$
(2)

Then, exploiting (2), the maximum achievable gain of the component at the
$k$th row and the $l$th column of $\mathbf{C}$, shown by $c_{k,l}$, can be
given as

$\left|c_{k,l}\right|=|\sum\nolimits_{i=1}^{N}g_{k,i}e^{j\phi_{i}}h_{i,l}|\leq\sum\nolimits_{i=1}^{N}|g_{k,i}||h_{i,l}|$
(3)

where $g_{k,i}$ and $h_{i,l}$ are the $k$th and $l$th components of the
channel vectors $\mathbf{g}_{i}^{\mathrm{H}}$ and $\mathbf{h}_{i}$,
respectively, for $k\in\left\\{1,2,\ldots,R_{x}\right\\}$ and
$l\in\left\\{1,2,\ldots,T_{x}\right\\}$. It is quite obvious that there exists
an optimum $\mathbf{\Phi}$ matrix that satisfies (3) with an equality to
achieve the maximum channel gain. However, due to the non-convex constraints,
it is difficult to find an optimal solution for this problem in a
computationally efficient and robust manner. Moreover, this challenge
increases when a multi-antenna system is considered at both the transmitter
and the receiver. Due to these limitations, we develop an efficient suboptimal
solution using the cosine similarity theorem [16], where the angle between
$\mathbf{u}$ and $\mathbf{v}$ vectors is calculated, using their inner product
and magnitudes [16], as

$\cos(\mathbf{u},\mathbf{v})=\frac{<\mathbf{u},\mathbf{v}>}{||\mathbf{u}||||\mathbf{v}||}.$
(4)

In the proposed algorithm, to maximize the individual gain of each $c_{k,l}$
component (3) the phase shift $\phi_{i}$ is adjusted to approximate the
complex channel vectors $\mathbf{h}_{i}$ and $\mathbf{g}_{i}^{\mathrm{H}}$ to
their component-wise absolute vectors
$\tilde{\mathbf{h}}_{i}=[|h_{i,1}|,|h_{i,2}|,,\ldots|h_{i,T_{x}}|]$ and
$\tilde{\mathbf{g}}_{i}^{\mathrm{H}}=[|g_{1,i}|,|g_{2,i}|,,\ldots|g_{R_{x},i}|]^{\mathrm{H}}$,
respectively. Therefore, in Algorithm 1, real $\phi_{i}^{h}$ and
$\phi_{i}^{g}$ angles are calculated in order to measure the cosine similarity
between the vectors $\mathbf{h}_{i}$ and $\tilde{\mathbf{h}}_{i}$ and
$\mathbf{g}_{i}^{\mathrm{H}}$ and $\tilde{\mathbf{g}}_{i}^{\mathrm{H}}$,
respectively. Then, for the $i$th reflecting element, the overall phase shift
$\phi_{i}$ is determined as $\phi_{i}=-(\phi_{i}^{h}+\phi_{i}^{g})$ and the
overall reflection matrix $\mathbf{\Phi}$ is obtained accordingly.

Algorithm 1 Cosine Similarity-based Low-Complexity Algorithm

Input: ${\mathbf{h}}_{i}$, $\mathbf{g}_{i}$, $\tilde{\mathbf{h}}_{i}$,
$\tilde{\mathbf{g}}_{i}$
Output: $\mathbf{\Phi}$

1:for $i=1:N$ do

2:
$\phi_{i}^{h}=\arccos\left(\frac{<\mathbf{h}_{i},\tilde{\mathbf{h}}_{i}>_{\operatorname{Re}}}{||\mathbf{h}_{i}||||\tilde{\mathbf{h}}_{i}||}\right)$

3:
$\phi_{i}^{g}=\arccos\left(\frac{<\mathbf{g}_{i}^{\mathrm{H}},\tilde{\mathbf{g}}_{i}^{\mathrm{H}}>_{\operatorname{Re}}}{||\mathbf{g}_{i}^{\mathrm{H}}||||\tilde{\mathbf{g}}_{i}^{\mathrm{H}}||}\right)$

4: $\phi_{i}=-(\phi_{i}^{h}+\phi_{i}^{g})$

5:end for

6:$\mathbf{\Phi}=\operatorname{diag}(e^{j\phi_{1}},e^{j\phi_{2}},\ldots,e^{j\phi_{N}})$

Let us present the concept of the proposed algorithm by an example. Consider
an RIS-aided MIMO system, with $T_{x}=2$, $R_{x}=3$ ve $N=2$ whose composite
channel matrix $\mathbf{C}=\mathbf{G}^{\mathrm{H}}\mathbf{\Phi H}$ is
constructed as

$\displaystyle\mathbf{C}=\begin{bmatrix}g_{11}&g_{12}\\\ g_{21}&g_{22}\\\
g_{31}&g_{32}\end{bmatrix}\begin{bmatrix}e^{j\phi_{1}}&0\\\ 0&e^{j\phi_{2}}\\\
\end{bmatrix}\begin{bmatrix}h_{11}&h_{12}\\\ h_{21}&h_{22}\end{bmatrix}$ (5)

which can be rewritten, in the form of
$\mathbf{C}=\sum_{i=1}^{N}\mathbf{g}_{i}^{H}e^{j{\phi}_{i}}\mathbf{h}_{i}$, as

$\displaystyle\mathbf{C}=\begin{bmatrix}g_{11}\\\ g_{21}\\\
g_{31}\end{bmatrix}e^{j\phi_{1}}\begin{bmatrix}h_{11}&h_{12}\end{bmatrix}+\begin{bmatrix}g_{12}\\\
g_{22}\\\
g_{32}\end{bmatrix}e^{j\phi_{2}}\begin{bmatrix}h_{21}&h_{22}\end{bmatrix}.$
(6)

Since the phase shift $\phi_{i}$ only affects $\mathbf{g}_{i}^{\mathrm{H}}$
and $\mathbf{h}_{i}$ vectors, instead of jointly adjusting all phases, each
$\phi_{i}$ can be individually determined in a more computationally efficient
manner. Therefore, in the proposed algorithm, considering (3), we singly
determine each $\phi_{i}$ to improve the overall channel gain. For this aim,
$\phi_{i}$ is properly adjusted to make the channel vectors $\mathbf{h}_{i}$
and $\mathbf{g}_{i}^{\mathrm{H}}$ approximate to their component-wise absolute
vectors $\tilde{\mathbf{h}}_{i}=[|h_{i,1}|,|h_{i,2}|]$, and
$\tilde{\mathbf{g}}_{i}^{\mathrm{H}}=[|g_{1,i}|,|g_{2,i}|,|g_{3,i}|]^{\mathrm{H}}$,
respectively. Therefore, as given in Algorithm 1, the real angles
$\phi_{i}^{h}$ and $\phi_{i}^{g}$, which respectively measure the similarities
between the vectors $\mathbf{h}_{i}$ and $\tilde{\mathbf{h}}_{i}$, and the
vectors $\mathbf{g}_{i}^{\mathrm{H}}$ and
$\tilde{\mathbf{g}}_{i}^{\mathrm{H}}$, are calculated using the cosine
similarity theorem [16]. Then, the effective phase shift of $i$th reflecting
elements is set to $\phi_{i}=-(\phi_{i}^{h}+\phi_{i}^{g})$. After $N$
repetitions are performed, the overall reflection matrix $\mathbf{\Phi}$ is
constructed.

The required complexity to perform this algorithm is
$\mathcal{O}(6N(T_{x}+R_{x}))$ in terms of real multiplications (RMs). It is
worth noting that when a SISO system ($T_{x}=R_{x}=1$) is considered, this
algorithm satisfies (3) with an equality that achieves the optimum channel
gain in [3].

###  II-B RIS-MIMO Scheme

In the proposed RIS-MIMO scheme with $T_{x}$ transmit antennas, $R_{x}$
receive antennas and $N$ reflecting elements, a classical MIMO transmission
principle is applied and the reflection parameters are determined by
performing the proposed low-complexity algorithm to improve the overall
channel gain. Let
$\mathbf{x}=\left[x_{1},x_{2},\ldots,x_{T_{x}}\right]^{\mathrm{T}}\in\mathbb{C}^{T_{x}\times
1}$ be the transmitted signal vector of the RIS-MIMO scheme, where $x_{j}$
denotes an $M$-ary phase shift keying/quadrature amplitude modulation
(PSK/QAM) symbol transmitted through $j$th transmit antenna, for
$j\in\left\\{1,2,\ldots,T_{x}\right\\}$. Then, the received signal vector
$\mathbf{y}\in\mathbb{C}^{R_{x}\times 1}$ becomes

$\displaystyle\mathbf{y}=\mathbf{G}^{\mathrm{H}}\mathbf{\Phi Hx}+\mathbf{n}$
$\displaystyle\hskip 7.11317pt=\mathbf{Cx}+\mathbf{n}$ (7)

where $\mathbf{n}\in\mathbb{C}^{R_{x}\times 1}$ is the vector of additive
white Gaussian noise samples whose elements are i.i.d. and follow
$\mathcal{CN}(0,N_{0})$ distribution.

###  II-C RIS-SM Scheme

In this subsection, the system model of the RIS-SM scheme, where an RIS-aided
MIMO scheme applying the traditional SM transmission principle [17] is
presented. Unlike traditional SM [17], in the proposed RIS-SM scheme, the
transmitted signal quality is significantly improved by the RIS, whose each
reflection parameter is arranged using the proposed low-complexity algorithm.

In RIS-SM, one of the $T_{x}$ transmit antenna is activated and a modulated
symbol $s$ from the $M$-PSK constellation is transmitted through this active
antenna. Since the remaining transmit antennas are deactivated, the signal
vector is determined as $\mathbf{x}=\begin{bmatrix}0&\ldots
0&s&0&\ldots&0\end{bmatrix}^{\mathrm{T}}$ and transmitted through the overall
channel matrix $\mathbf{C}$ as given in (7).

Note that in the proposed RIS-SM scheme, the knowledge of the active antenna
index is not provided to the RIS.

At the receiver of both RIS-MIMO and RIS-SM schemes, to obtain the best BER
performance, a maximum likelihood (ML) detector is considered, and the
transmit RIS-SM and RIS-MIMO vectors are detected by considering all possible
$\mathbf{x}$ realizations as follows

$\hat{\mathbf{x}}=\arg\min_{\mathbf{x}}\left\|\mathbf{y}-\mathbf{Cx}\right\|^{2}.$
(8)

##  III Performance Analysis

In this section, the theoretical BER performance of the proposed RIS-MIMO and
RIS-SM schemes is evaluated by performing a semi-analytical probabilistic
approach.

###  III-A Numerical Analysis

As given in Algorithm 1, since the proposed algorithm relates the phase shifts
of the reflecting elements with the channel statistics, the reflection matrix
$\mathbf{\Phi}$ is directly correlated with the channel matrices $\mathbf{H}$
and $\mathbf{G}$. Therefore, the distribution of the composite channel matrix
$\mathbf{C}$ could not be derived through a fully analytic approach. As a
result, we resort to a comprehensive numerical analysis in order to obtain the
statistics of the channel matrix $\mathbf{C}$.

As it is stated in the previous section, the elements of the channel matrices
$\mathbf{H}$ and $\mathbf{G}$ are i.i.d. and follow $\mathcal{CN}(0,1)$
distribution. Our comprehensive numerical analysis, which performs $10^{6}$
Monte-Carlo trials for each $R_{x}\times T_{x}$ configuration, indicates that
the elements of the composite $\mathbf{C}$ matrix are complex Gaussian random
variables with $\mathcal{CN}(N\mu,N)$ distribution, where $\mu$ is numerically
calculated, in terms of $T_{x}$ and $R_{x}$, as

$\mu=\frac{1.8}{(1+2T_{x})(1+2R_{x})}.$ (9)

For supporting the accuracy of this estimation, in Fig. 2, $(\ref{mu})$ is
compared to the the channel statistics of $\mathbf{C}$ for $N=1$, which is
obtained through the Monte Carlo simulations performing at least $10^{6}$
trials for each $R_{x}\times T_{x}$ set-up. The results show that the
estimated $\mu$ in (9) perfectly fit the computer simulations per $R_{x}\times
T_{x}$.

Then, (9) is utilized to determine the ABEP of the system in the following
subsection.

Figure 2: Comparison of the mean $\mu$ (9) with the Monte-Carlo simulations
for different $T_{x}$ ve $R_{x}$ antennas.

###  III-B ABEP Analysis

In this subsection, after obtaining a numerical approximation for the
statistics of the channel matrix $\mathbf{C}$, an upper bound expression for
the ABEP of the proposed system is given as follows [18]:

$P_{e}\leq\frac{1}{\kappa
2^{\kappa}}\sum_{\mathbf{x}}\sum_{\hat{\mathbf{x}}}P(\mathbf{x}\rightarrow\hat{\mathbf{x}})e(\mathbf{x},\hat{\mathbf{x}})$
(10)

where $\kappa$ is the number of incoming information bits,
$P(\mathbf{x}\rightarrow\hat{\mathbf{x}})$ is the unconditional pairwise error
probability (PEP) and $e(\mathbf{x},\hat{\mathbf{x}})$ is the number of error
bits for the corresponding PEP event.

To obtain the PEP expression, first, the conditional PEP (CPEP) of the system
is derived, using the $Q$-function, as follows

$\vspace*{-0.17cm}P(\mathbf{x}\rightarrow\hat{\mathbf{x}}|\mathbf{C})=Q\Bigl{(}\sqrt{\frac{\Omega}{2\sigma^{2}}}\Bigr{)}$
(11)

where $\Omega$ is given, for
$\mathbf{\Delta}=(\mathbf{x}-\hat{\mathbf{x}})(\mathbf{x}-\hat{\mathbf{x}})^{H}$,
as

$\displaystyle\Omega=||\mathbf{C}\big{(}\mathbf{x}-\hat{\mathbf{x}}\big{)}||^{2}$
(12) $\displaystyle\hskip
7.11317pt=\mathrm{vec}({\mathbf{C}}^{\mathrm{H}})^{\mathrm{H}}(\mathbf{\Delta}\otimes\mathbf{I}_{R_{x}})\mathrm{vec}({\mathbf{C}}^{\mathrm{H}}).$
(13)

Therefore, considering
$Q(x)=\frac{1}{\pi}\int_{0}^{\pi/2}e^{-x^{2}/2\sin^{2}\theta}\mathit{d}\theta$,
the CPEP (11) can be rewritten as

$\displaystyle\begin{split}&P\left(\mathbf{x}\rightarrow\hat{\mathbf{x}}|\mathbf{C}\right)=\\\
&\hskip
14.22636pt\frac{1}{\pi}\int_{0}^{{\pi/2}}\exp\Bigl{(}-\varphi\frac{\mathrm{vec}({\mathbf{C}}^{\mathrm{H}})^{\mathrm{H}}(\mathbf{\Delta}\otimes\mathbf{I}_{R_{x}})\mathrm{vec}({\mathbf{C}}^{\mathrm{H}})}{4\sin^{2}\theta}\Bigr{)}\mathit{d}\theta\end{split}$
(14)

where $\varphi=1/N_{0}$. Then, averaging (14) over the matrix $\mathbf{C}$
through moment generating function (MGF) approach results in the following PEP
expression

$\displaystyle\begin{split}&P\left(\mathbf{x}\rightarrow\hat{\mathbf{x}}\right)=\frac{1}{\pi}\int_{0}^{{\pi/2}}M_{\Omega}\biggl{(}\frac{-\varphi}{4\sin^{2}\theta}\biggr{)}\mathit{d}\theta.\end{split}$
(15)

In [19], the MGF of $\mathbf{z}^{\mathrm{H}}\mathbf{Bz}$, for any Hermitian
$\mathbf{B}$ matrix, is given by

$M(s)=\text{exp}\biggl{(}\frac{s\bar{\mathbf{z}}^{\mathrm{H}}\mathbf{B}(\mathbf{I}-s\mathbf{C_{z}B})^{-1}\bar{\mathbf{z}}}{\det(\mathbf{I}-s{\mathbf{C_{z}B}})}\biggr{)}$
(16)

where $\bar{\mathbf{z}}$ is the mean vector and $\mathbf{C_{z}}$ is the
covariance matrix of the vector $\mathbf{z}$.

Clearly, in our system $\mathbf{B}=\mathbf{\Delta}\otimes\mathbf{I}_{R_{x}}$
and $\mathbf{z}={\operatorname{vec}({\mathbf{C}}^{\mathrm{H}}})$. Using the
numerically obtained channel statistics given in the previous subsection,
$\bar{\mathbf{z}}=\overline{\operatorname{vec}({\mathbf{C}}^{\mathrm{H}})}=\mu
N\mathbf{1}$ and $\mathbf{C_{z}}=N\mathbf{I}$ are respectively defined as the
mean vector and the covariance matrix for the Gaussian vector
$\mathbf{z}=\operatorname{vec}({\mathbf{C}}^{\mathrm{H}})$. Therefore, the PEP
of the system becomes

$\displaystyle\begin{split}&P\left(\mathbf{x}\rightarrow\hat{\mathbf{x}}\right)=\\\
&\frac{1}{\pi}\int_{0}^{\pi/2}\frac{\exp\biggr{(}-\bar{\mathbf{z}}^{\mathrm{H}}\frac{\varphi}{4\sin^{2}{\theta}}\mathbf{B}\biggr{(}\mathbf{I}+\frac{\varphi}{4\sin^{2}{\theta}}\mathbf{C_{z}}\mathbf{B}\biggl{)}^{-1}\bar{\mathbf{z}}\biggl{)}}{\det\biggl{(}\mathbf{I}+\frac{\varphi}{4\sin^{2}\theta}\mathbf{C_{z}}\mathbf{B}\biggr{)}}\mathit{d}\theta.\end{split}$
(17)

##  IV Simulation Results

In this section, the BER performance of the proposed RIS-MIMO and RIS-SM
schemes are investigated through theoretical analysis and comprehensive
computer simulations. All results are performed as a function of transmitted
signal energy to noise ratio ($E_{s}/N_{0}$) and for different $R_{x}\times
T_{x}$ MIMO configurations and BPSK modulation ($M=2$).

Figure 3: Theoretical and simulation results of the RIS-MIMO ve RIS-SM
schemes.

(a)  (b)

Figure 4:  Comparison of the proposed algorithm to the pinv algoritm [9] on
the BER performance of the a) RIS-MIMO and b) RIS-SM schemes.

In Fig. 3, for $4\times 2$ MIMO and various $N$ reflecting elements, the
theoretical BER performance of RIS-MIMO and RIS-SM schemes are compared with
the computer simulation results. It is obvious from this figure that the
derived semi-analytic results perfectly match with the simulation results as
$N$ increases.

In Fig. 4, for $4\times 4$ system configuration, the BER performance of the
RIS-MIMO and RIS-SM schemes using the proposed cosine similarity theorem-based
algorithm and pseudoinverse (pinv)-based algorithm [9] is compared. The
results show that compared to [9], the BER performance of both RIS-MIMO and
RIS-SM schemes using the proposed algorithm, which requires significantly
lower computational complexity, improves better as $N$ increases.

Figure 5: BER Performance of RIS-MIMO scheme with discrete and continous phase
reflection for the channel estimation error variance $\sigma_{e}^{2}$.

As an illustration, the proposed algorithm with $\mathcal{O}(6N(T_{x}+R_{x}))$
complexity performs $3072$ RMs for $N=64$, while the reference pinv algorithm
[9] with $\mathcal{O}(N^{3})$ complexity performs $262144$ RMs. This means,
the proposed algorithm provides $98.8\%$ reduction in computational complexity
over the reference algorithm [9] for $N=64$.

In Fig. 5, the impact of the imperfect channel knowledge and the use of
discrete phase shifts on the BER performance of the $4\times 4$ RIS-MIMO
scheme is investigated for $N$ reflecting elements.

For discrete phase shifts model, we assume that each reflecting element at the
RIS takes a finite number of discrete phase values. Therefore, a set of
discrete phase shifts is constructed by uniformly quantizing $[0,\pi]$222In
Algorithm I, for $\arccos(\cdot)$ operation, MATLAB function $\textit{acos}()$
is used, which returns phase values between the interval $[0,\pi]$. interval
into $N$ levels as
$\mathcal{F}=\\{0,\>\Delta\phi,\>\ldots,\>(N-1)\Delta\phi\\}$, where
$\Delta\phi=\pi/N$. Then, the continous phase shift of the each reflecting
element, which is obtained via the proposed algorithm, is rounded to the
nearest discrete level. The simulation results demonstrate that discrete phase
reflection causes a minor BER performance degradation compared to the
continous phase reflection. However, this performance difference gradually
disapperars as $N$ increases.

Moreover, to analyze the effect of the channel estimation error, the imperfect
CSI is assumed at both the RIS and the receiver. Therefore, we consider that
both the RIS and the receiver errorneously estimate $\mathbf{H}$ and
$\mathbf{G}$ channel matrices as $\bar{\mathbf{H}}\in\mathbb{C}^{N\times
T_{x}}=\mathbf{H}+\mathbf{E_{t}}$ and $\bar{\mathbf{G}}\in\mathbb{C}^{N\times
R_{x}}=\mathbf{G}+\mathbf{E_{r}}$, respectively, where $\mathbf{E_{t}}$ and
$\mathbf{E_{r}}$ are the matrices of the channel estimation errors whose each
entry is i.i.d. and distributed as $\mathcal{CN}(0,\sigma_{e}^{2})$.
Therefore, after the proposed algorithm determines the diagonal reflection
matrix $\bar{\mathbf{\Phi}}\in\mathbb{C}^{N\times N}$ considering the
imperfect channels $\bar{\mathbf{H}}$ and $\bar{\mathbf{G}}$, the overall
estimated channel matrix becomes $\bar{\mathbf{C}}\in\mathbb{C}^{R_{x}\times
T_{x}}=\bar{\mathbf{G}}^{\mathrm{H}}\bar{\mathbf{\Phi}}\bar{\mathbf{H}}$. The
simulation results reveal that the assumption of the imperfect CSI at both the
RIS and the receiver significantly degrades the BER performance of the RIS-
MIMO scheme. However, increasing the number of reflecting elements at the RIS
reduces this performance degradation.

Fig. 6 demonstrates the BER performance of the proposed RIS-MIMO scheme with
$4\times 4$ when path loss effect [10] is considered. Denoting the distances
from the transmitter to the RIS and from the RIS to the receiver as $d_{1}$
and $d_{2}$, respectively, the path loss $P_{L}$ of the overall system is
calculated as [10]

$P_{L}^{-1}=\frac{\lambda^{4}}{256\pi^{2}}\frac{1}{d^{2}_{1}d^{2}_{2}}$ (18)

Figure 6: BER Performance of RIS-MIMO scheme in case of the path loss effect
[10].

where $\lambda$ is the wavelength at $2.4$ GHz operating frequency. The
simulations are performed for $d_{1}=d_{2}=10$ m and $d_{1}=2$ m, $d_{2}=18$
m. It can be deduced from the results that compared to the performance in the
absence of the path loss given in Fig. 4, the error performance of the RIS-
MIMO scheme significantly degrade with the path loss effect. On the other
hand, since the $P_{L}$ is proportional to $d_{1}^{2}d_{2}^{2}$, the BER
performance of the system fairly improves when the RIS is closer to the
transmitter or the receiver ($d_{1}=2$ m and $d_{2}=18$ m).

##  V Conclusion

In this letter, a low-complexity algorithm has been developed exploiting the
cosine similarity theorem for RIS aided MIMO transmission schemes to enhance
the overall path gain of the communication channel. Moreover, performing a
semi-analytic approach, the ABEP of the system has been derived. Furthermore,
through the comprehensive computer simulations the BER performance of RIS
aided MIMO schemes for different circumstances including discrete phase
reflection, path loss effect and imperfect CSI has been investigated.

## References

  * [1] S. Zhang and R. Zhang, “Capacity characterization for intelligent reflecting surface aided MIMO communication,” _arXiv preprint arXiv:1910.01573_ , 2019\.
  * [2] Q.-U.-A. Nadeem, A. Kammoun _et al._ , “Large intelligent surface assisted MIMO communications,” _arXiv preprint arXiv:1903.08127_ , 2019.
  * [3] E. Basar, “Transmission through large intelligent surfaces: A new frontier in wireless communications,” in _IEEE European Conf. Netw. and Commun. (EuCNC)_ , June 2019, pp. 112–117.
  * [4] E. Basar, M. Di Renzo _et al._ , “Wireless communications through reconfigurable intelligent surfaces,” _IEEE Access_ , vol. 7, pp. 116 753–116 773, Aug. 2019.
  * [5] E. Basar, “Reconfigurable intelligent surface-based index modulation: A new beyond MIMO paradigm for 6G,” _IEEE Trans. Commun._ , Feb. 2020.
  * [6] S. Gopi, S. Kalyani, and L. Hanzo, “Intelligent reflecting surface assisted beam index-modulation for millimeter wave communication,” _arXiv preprint arXiv:2003.12049_ , 2020.
  * [7] C. Huang, A. Zappone _et al._ , “Reconfigurable intelligent surfaces for energy efficiency in wireless communication,” _IEEE Tran. Wireless Commun._ , vol. 18, no. 8, pp. 4157–4170, June 2019.
  * [8] Q. Wu and R. Zhang, “Intelligent reflecting surface enhanced wireless network via joint active and passive beamforming,” _IEEE Trans. Wireless Commun._ , vol. 18, no. 11, pp. 5394–5409, Aug. 2019.
  * [9] T. Hou, Y. Liu _et al._ , “MIMO assisted networks relying on large intelligent surfaces: A stochastic geometry model,” _arXiv preprint arXiv:1910.00959_ , 2019.
  * [10] S. W. Ellingson, “Path loss in reconfigurable intelligent surface-enabled channels,” _arXiv preprint arXiv:1912.06759_ , 2019.
  * [11] W. Tang, M. Z. Chen _et al._ , “Wireless communications with reconfigurable intelligent surface: Path loss modeling and experimental measurement,” _arXiv preprint arXiv:1911.05326_ , 2019.
  * [12] E. Basar, I. Yildirim, and I. F. Akyildiz, “Indoor and outdoor physical channel modeling and efficient positioning for reconfigurable intelligent surfaces in mmWave bands,” _arXiv preprint arXiv:2006.02240_ , 2020.
  * [13] ——, “SimRIS channel simulator for reconfigurable intelligent surface-empowered communication systems,” _arXiv preprint arXiv:2006.00468_ , 2020.
  * [14] S. Abeywickrama, R. Zhang _et al._ , “Intelligent reflecting surface: Practical phase shift model and beamforming optimization,” _arXiv preprint arXiv:2002.10112_ , 2020.
  * [15] Q. Wu and R. Zhang, “Weighted sum power maximization for intelligent reflecting surface aided SWIPT,” _IEEE Wireless Commun. Lett._ , vol. 9, no. 5, pp. 586–590, 2019.
  * [16] T. K. Moon and W. C. Stirling, _Mathematical Methods and Algorithms for Signal Processing_. Prentice Hall Upper Saddle River, NJ, 2000, vol. 1.
  * [17] R. Y. Mesleh, H. Haas _et al._ , “Spatial modulation,” _IEEE Trans. Veh. Technol._ , vol. 57, no. 4, pp. 2228–2241, July 2008.
  * [18] M. K. Simon and M.-S. Alouini, _Digital communication over fading channels_. John Wiley & Sons, 2005, vol. 95.
  * [19] G. L. Turin, “The characteristic function of hermitian quadratic forms in complex normal variables,” _Biometrika_ , vol. 47, no. 1/2, pp. 199–201, 1960.