#  The Economics of the DeLend Project
Agent-based Simulations

Frederico Dutilh Novaes, PhD
<EMAIL_ADDRESS>Gabriel de Abreu Madeira, PhD
<EMAIL_ADDRESS>Aurimar Cerqueira
<EMAIL_ADDRESS>
( February 2023)

###### Abstract

This paper presents our methodology to simulate the behavior of the DeLend
Platform. Such simulations are important to verify if the system is able to
connect the different sets of agents linked to the platform in a functional
manner. They also provide inputs to guide the choices of operational
parameters, such as the platform spread, and strategies by DeLend, since they
estimate how the key variables of interest respond to different policies. We
discuss the methodology and provide examples meant to clarify the approach and
to how we intend to use the tool in practice – they should not be interpreted
as representative of real life scenarios.

##  1 Introduction

Complex collective behaviors can, sometimes, be modeled by decomposing systems
into a set of _agents_ that interact between themselves following relatively
simple rules/interactions. Simulations built on such modeled agents are called
agent-based simulations. Our agent-based simulation tool is presented, which
is designed to simulate the behavior of the DeLend platform, and illustrative
examples of such simulations are provided. The numerical exercises provided
build on the market design presented on [2]. DeLend connects, through its
platform, different sets of agents: borrowers, investors and guarantors. The
parameters governing the platform must be set so that there is coherency among
the actions of such actors. Resources anticipated for borrowers should be
similar to the amount provided by investors. Guarantors must have incentives
to truly facilitate the borrowing process 111 Incentives constraints are
crucial for guarantors to be interested in endorsing loans and for such
endorsement to be worthwhile for borrowers and investors. See for instance [5]
and [3]. Simulations can be used to verify if such properties are achievable
with the platform design proposed. Additionally, they provide an estimate of
the gains obtained by each agent connected to the platform. Finally,
simulations reveal impacts on amounts lent, prices and return to investors of
different parameters under multiple scenarios, thus guiding the choices of
operational parameters and policies by DeLend.

We start by briefly introducing the agents and their interactions222Although a
simplified representation of reality, the specification of these agents still
involves some level o math, and their implementation must be thoroughly
tested. This more in-depth discussion has not been included in this main text,
as it is meant to be an overview., including a discussion on the important
topic of (loan) demand modeling. Next, we simulate somewhat realistic
examples, where all classes of agents are present, and obtain the optimal
spreads on different scenarios, as an example usage of the tool. The results
indicate that the system is capable of channeling the resources from investors
to borrowers with a reasonable return for investors and relative stability of
the liquidity pool. They also suggest that a good engine for rating loans is
crucial, and that guarantors are an important tool to improve the performance
of the system whenever the rating engine is not sufficiently accurate. We then
conclude and discuss next steps.

##  2 Agent-based simulation

Agent-based simulations require a characterization of the behavior of agents
and rules of interaction amongst such agents. The set of agents and their
interaction rules are described below.

###  2.1 Agents

Figure 1: Agents and their interactions. We also include environmental
parameters, so far we have only considered a _risk free interest rate_ , that
acts as a base rate.

Three classes of agents drive the simulations: investors, borrowers and
guarantors. Those are the agents that will connect through the DeLend
platform. Two classes of investors are modeled: (i) seed investors, which
provide liquid assets to the platform initially; and (ii) regular investors,
which provide liquid assets for lending over time. The number of those agents
usually varies over time – agents can enter and leave the system. The behavior
of agents depends on preference parameters and information available to them.

The Platform is the engine that computes the anticipation offers for each
potential borrower – it may also refuse to offer an anticipation, if it
considers the borrower to be too risky. The anticipation is computed
considering four main parameters: (i) a risk evaluation (quantified as a
default probability); (ii) the environment’s risk free interest rate; (iii) a
spread, which stipulates extra returns per loan (when compared to the risk-
free rate) (iv) guarantors contributions. Section 2.2.1 discusses the basic
setup, without guarantors. If guarantors are involved, the offer will take
into account the guarantor’s stake and their (guarantors) expected gains (see
section 2.2.2).

The Liquidity Pool manages the cash flow, by transferring and receiving
resources from borrowers and investors. Given the dynamical nature of the
system, there may be periods where there are not enough resources to
anticipate or to fully pay an investor (in which case, the investor will only
partially withdraw, since we have not yet implemented a secondary market yet).
Thus, the management of the liquidity pool is a key piece of the DeLend
system.

Figure 1 depicts the agents and their interactions. Since the interactions
between borrowers and guarantors with the liquidity pool are very simple,
being simply a cash transfer, we will only focus on describing the
interactions between borrowers and the platform, with and without guarantors,
and between investors and the liquidity pool333In reality, investors – and
borrowers, and guarantors – interact only with the platform, the latter
managing the liquidity pool. Here we are representing as if they interacted
directly with the liquidity pool in order to facilitate the representation of
the different cash flows..

###  2.2 Interactions between agents

The following sections describe the interaction between agents. Investors and
guarantors provide funds, while borrowers absorb such resources. The
interactions presented are just a subset of the possible options given the
structure of the DeLend system. Other arrangements may be analysed in a future
work.

To actually perform a simulation means to let the system evolve in time. As
represented in Figure 2, the time evolution is discrete, where, at each time
step, agents may interact (take actions) according to the behaviours described
bellow.

Figure 2: The time evolution is discrete, where each step can be constructed
to represent a day, a month, a year, or whatever convenient unit of time. At
each time step, agents interact: borrowers can ask for anticipations or pay
installments, investors may decide to invest or withdraw (or do nothing), and
so on. We have also represented the fact that borrowers and investors may
enter/quit the environment, thus their number may vary.

####  2.2.1 Borrower $\longleftrightarrow$ Platform: Anticipation without
guarantors

As depicted in Figure 1, borrowers may trade a set of receivables for an
anticipation. The platform’s job is to make an anticipation offer based on the
set of receivables (amount and number of installments) and its risk
evaluation. If the borrower accepts the anticipation offer, the anticipation
value is transferred from the liquidity pool to the borrower, in return for
the installments. Over time, the liquidity pool then receives the
installments444For now we have only consider full payment of each
installment., except for in the event of a default. We now (qualitatively)
discuss our approach.

Given a set of $N$ receivables (e.g. installments of a sale), a merchant may
want to trade these receivables for cash anticipation. Here, we consider a
scenario without guarantors, where, in order to make an anticipation offer,
the platform considers two main factors that impact the anticipation discount:
(i) the default risk discount (that depends on the estimated default
probability we refer as $p$); and (ii) the present value discount (a
combination of the risk free interest rate $r$, the platform’s spread $s$, and
the number of installments $N$).

As an example of cash flow, suppose a borrower is willing to negotiate a set
of $N=4$ (equally spaced) receivables totaling 100 (4 installments of 25), as
shown in Figure 3 – where upward arrows indicate cash inflow, and downward
arrows cash outflows. If the platform makes an anticipation offer for the set
of receivables and the borrower accepts it, the platform pays an amount A to
the borrower in return for the receivables (Figure 4).

Figure 3: Cash flow of 4 receivables (installments) totaling 100. In general,
installments need not have equal values, nor be equally spaced, but often are.
Typically, the time periods $t_{i}$ represent months. Figure 4: Cash flow if
the trade between the borrower and the platform occurs: the platform pays the
borrower an amount $A<100$ for the set of future receivables. Being future
payments, there will be a certain level of default to be expected, thus
impacting the anticipation discount.

The challenge for the platform is to compute the amount $A$ to anticipate, and
the loan’s return will be directly related to the discount offered: the bigger
the discounts, the higher the returns for investors. However, if discounts are
too greedy, lower volumes will be captured, since borrowers are more likely to
reject anticipation offers, resulting in sub-optimal allocation of the
liquidity pool. Also, if risk discounts are not properly computed, returns may
become negative and/or lead to adverse selection.

Figure 5 shows how the anticipation value changes as a function of the
different parameters we have included in our anticipation formula in this
context. As it can be noted, the estimated default probability $p$
significantly impacts the value of the anticipation offer. As long as the
platform’s risk assessment is accurately estimating these values, these would
be the proper discounts in order to have a healthy operation. However, if, for
whatever reason, the rating engine is not properly calibrated, guarantors may
come to help, as we discuss in the next section.

Figure 5: Anticipation values for a set of receivables that sum 100, as a
function of the number of installments $N$, the platform’s spread $s$, its
estimated default probability $p$ and for a base rate $r=0.1$ (left), and
$r=0.3$ (right). When guarantors are not involved, these are the parameters
that we have included to compute the anticipation offer.

####  2.2.2 Borrower $\longleftrightarrow$ Guarantor $\longleftrightarrow$
Platform: Anticipation with guarantors

Guarantors can contribute in different ways to the dynamics of the system. In
particular, when they are able to provide more accurate risk assessments
regarding particular borrowers, their role can be beneficial to all players:
it enables lending by improving anticipation offers (as we’ll discuss below)
while also being profitable to the guarantor.

As shown in Figure 1, guarantors participate in the trade between a borrower
and a platform: they have their own risk assessment and they ask for an extra
spread in return for their investment (collateral). The platform then decides
if it is worth involving the guarantor555The simplest criteria, which is the
one we have used, is to establish a threshold of improvement for anticipation
– e.g. 10% better than without guarantors. However, more elaborate criteria
may be needed, for example in order to avoid possible collusion between
borrowers and guarantors..

The dynamics works as follows. Guarantors must first deposit a collateral
$V_{c}$. If the borrower defaults, the guarantor loses the collateral, being
an investment with higher risks than for standard investors. Thus, the loan’s
fund return alone, usually, would not be enough as an incentive to attract
guarantors, and the platform must also offer an extra gain, characterized by
the guarantor’s spread $s_{g}$. Guarantors also have an estimate for the
borrower’s default probability666Indirectly acting in a similar way as a _peer
prediction index_ , [6], in order to compute expected losses. The following
elements characterize a guarantor: (i) $s_{g}$ the guarantor’s extra spread;
(ii) $V_{c}$ the guarantor’s collateral amount; and (iii) $p_{g}$ the
guarantor’s default probability estimate (its risk assessment).

From the platform’s perspective, since we have not (yet) included a (extra)
financial reward coming from the partnership with the guarantor, the advantage
comes from being able to offer better anticipation deals to the borrowers,
increasing the acceptance probability. From the guarantor’s perspective the
reward is profitability.

Figure 6: Anticipation offer for a set of receivables that sum 100, with
$N=3$, $s=0.1$ and $r=0.1$. The platform estimates the default probability to
be $p=0.1$, while the guarantor’s default probability estimate is $p_{g}$
($s_{g}$ is the guarantor’s extra spread and $V_{c}$ is the staked amount).
The black, dashed line is the anticipation offer without guarantor. The
difference in the default probability estimates is the main factor that
impacts the anticipation offer. For this reason, when guarantors are able to
provide a better risk assessment, their involvement can significantly improve
the anticipation offer.

As already mentioned, the type of guarantor we are discussing here becomes
more relevant the bigger the asymmetry between the default probability
estimates: the platform assigns a high default probability to a borrower,
while the guarantor estimates a (much) lower value777The anticipation formula
now also includes the three extra parameters $p_{g}$, $s_{g}$ and $V_{c}$..
This is what is shown in Figure 6, where, as an example, the platform default
estimate is 10%, and we consider two situations, one where a guarantor
estimates this probability to be 8% and one where it estimates it to be 4%.
The difference between the anticipation offer with and without guarantor grows
with the difference between the two default probability estimates, showing
that this kind of guarantor would be most relevant in situations with bigger
_information asymmetry_ , guarantors being able to make better risk
assessments than the platform. As also shown, the bigger the collateral/stake,
the better becomes the anticipation offer.

Such situations, where guarantors are better at estimating risks, may occur,
for example, in new markets, where data may not be available, or of poor
quality. In any case, whenever a guarantor is willing to stake and asks for a
_reasonable_ extra gain888Since this gain is discounted from the anticipation,
if they ask for too much, it will automatically make the offer unattractive,
even if they happen to be wrong on their risk assessment, the impact for the
platform is minimized (_hedged_), given the collateral.

####  2.2.3 Investor $\longleftrightarrow$ Liquidity Pool: Providing resources
to the system

Investors provide resources for the loans/anticipations, expecting an extra
spread in return (with respect to the base rate $r$). The greater this spread,
the better for investors, as long as there is still demand to efficiently
allocate the liquidity pool resources. This balance, in order to attract both,
investors and borrowers, is adjusted by the platform via its spread rate $s$.
Default rates also impact returns. Even with a perfect rating engine, returns
would be as expected only on average, with a certain level of variance.
Different investors may have quite different strategies/criteria when making
investment decisions (both, to invest and to withdraw). Since this influx of
investments is an important component of the simulations, we have to include
it.

In our simulations, investors decide when to invest/withdraw only by
considering the funds historical performance, which is a simplified version of
the complex reality of investment decision policies. These are the main
parameters that describe each investor999As with other agents, for each
investor instance, a set of parameters is sampled from specified
distributions.: (i) investment amount; (ii) (annualized) expected performance
over a certain number of periods; (iii) loss and profit withdrawal rate,
where, with a certain withdrawal probability, investors withdraw their
investments; (iv) minimum holding period.

Given the stochastic nature of the simulations, even when all input parameters
are held fixed, outcomes will vary. As an example, consider Figure 7, where we
show the number of investors over time during different simulations (gray
lines), with a fixed set of input parameters. Without getting into the details
of why these curves look the way they look – section 3 provides a more
comprehensive discussion of simulations –, we can see the variability between
simulations, in this case, the number of investors over time.

Figure 7: Different simulation outcomes while keeping the input parameters
fixed. The gray lines represent the number of investors at each moment of
time, for each individual simulations, while the red line is the average from
all the simulations.

The parameters we have just described specify the investors population, and
how this population will behave during the time evolution of the system – even
if it is an stochastic behavior. From the borrowers side, the loan demand
side, the characterization is a bit more complex, and this is what we discuss
on the next section.

###  2.3 Borrowers anticipation demand modeling

Given that there are two parties involved on the anticipation _negotiation_ ,
borrowers may or may not accept the platform’s anticipation offer. It is
important, thus, to determine the _price sensitivity_ of borrowing – i.e.
model borrowing demand. Without data to fit a model to infer the price
elasticity of credit demand, we’ll assume an analytical approach and tune its
parameters in order to emulate different price sensitivities for the
borrowers. This demand may be influenced by the the presence of guarantors,
since the anticipation value may change. However, here we assume that
borrowers only consider the anticipation _price_ , i.e., they do not
distinguish a particular offer having the same price due to the presence of
guarantors or because the platform estimated a lower default probability.

From the platform’s perspective, the main pricing mechanism is setting its
spread $s$. From the borrowers’ side (the demand side), however, the
anticipation _price_ is probably the main factor they are sensitive to – here,
by _price_ , we mean the discount with respect to the sum of the receivables
in negotiation. Also, we’ll consider that the borrowers’ response to a
particular offer is probabilistic, let’s call it $f(A)$, where $f(A)$ is a
number between $0$ and $1$, representing the acceptance probability for that
particular offer. Figure 8-a shows an example of such a function: as the
anticipation discount increases, the acceptance probability decreases.

Figure 8: Example of price sensitivity curves as a function of the
anticipation discount (a). As made explicit on the right plot (b), these
curves depend on parameters like the number of installments $N$.

Given that the anticipation offer depends on a number of factors, such as the
number of installments $N$ and the base rate $r$, this price sensitivity curve
$f$ must also depend on these factors, and Figure 8-b shows an example on the
dependency on $N$: as the number of installments increases, so does the
tolerance for bigger discounts101010There is no unique price reference, it
depends on the particular conditions, it could be an _environmental_ parameter
like $r$, or a _contract_ aspect, like $N$..

An advantage of this approach is that these curves can be constructed in two
ways: (i) by tuning their parameters in order to represent different market
conditions, e.g. more/less elastic demand; (ii) by fitting them to
data111111Acquiring such data can be challenging, but also, properly fitting
such a model to observational data, may also be a difficult task.. For now,
we’ll consider only the first approach, as we have not obtained data to fit
yet.

##  3 Simulations

The previous section introduced how we modeled the interactions of our set of
agents, borrowers, investors and guarantors with the DeLend platform. We can
now show examples of simulations outcomes.

Figure 9 (left plot) shows the time evolution of the liquidity pool and of the
loan fund, the sum of them compose the total assets resulting from the
investments and the loans (see [2]). In this simulation we have kept the total
number of borrowers constant. As a consequence, after a certain number of
periods ($\sim 190$), the market _saturates_ , when loan demand is fully
fulfilled. As already mentioned, whenever the allocation of the liquidity pool
is sub-optimal, the overall performance is also sub-optimal (lower than
expected return rates), and investors start to withdraw (from the liquidity
pool, see 9 right plot). This re-balances the overall performance. However,
this mechanism is not completely efficient and there are periods with lower
allocation of the liquidity pool.

Figure 9: Time evolution of the assets, loan fund and liquidity pool (left).
On the right we show the liquidity pool transaction volumes per type of
transaction (a subset of the time window for clarity).

A second important outcome from the simulations is to evaluate variances. Even
when input parameters are kept constant, each simulation run results, in
general, in different outcomes. Different metrics can be computed after each
simulation, like the number of investors, the quota value and the historical
returns over a certain number of periods (see Figure 10). Each metric will
have its own average behavior and variance.

Figure 10: Time evolution of a set of metrics that can be computed for each
simulation. The green dashed line at the returns plot is the target return,
and returns were computed using an 18 period moving window (bottom right
plot).

Finally, we can leverage simulations to estimate optimal operational
parameters, like the platform’s spread $s$. As an example, let’s assume we
wanted to maximize the loan’s fund volume over a period of 36 months, keeping
the spread constant during the time evolution of the system, and considering
different scenarios. The first scenario considers a situation with just one
seed investor (Figure 11 top plot). In this case, the optimal spread would be
$s\sim 35\%$ (annualized value). The optimal values for the spread come from
the relation between _price_ (spread) and demand: as the spread increases, the
_volume_ per loan increases, but, at the same time, demand decreases (see
section 2.3 and Figure 8). Since the total volume is the product of these
conflicting effects, there will always be an optimal spread value – we may
also choose different objective functions, instead of the loan’s fund volume.

Considering the same scenario (input parameters), but now simulating a biased
risk assessment engine, one that overestimates the default probabilities, with
and without guarantors, we obtain the reusts shown in Figure 11 bottom left
plot121212The frequency of guarantors in the population is also an input
paramter, for this examplo we have set it to be 30%, meaning that each
borrower $\leftrightarrow$ platform interaction has a $0.3$ probability to
involve a guarantor.. The consequence of overestimating the default
probability is to overcharge for the loans/anticipations. In order to
compensate, the platform’s spread must be lowered to obtain optimal results.

To conclude, instead of having a biased risk assessment engine, we introduce
investors to the system (Figure 11 bottom right plot). As expected, investors
can significantly improve loan volumes, especially for cheaper spreads.

Figure 11: Optimization of the platform’s spread rate for different scenarios.
Here we use relative volumes, considering the lowest volume at each scenario
as the reference value. The results are represented using boxplots to express
the variance too.

##  4 Final remarks and next steps

We have presented our agent-based methodology to be able to simulate the
behavior of the DeLend platform. As shown in section 3, we can consider
realistic scenarios, and use the simulations in order to estimate outcomes,
depending on factors such as default rates distributions, rating engine
capabilities and benefits that guarantors may bring.

The numerical results suggest that the system is capable of governing the
channeling of resources from investors to borrowers with a reasonable return
for investors and relative stability of the liquidity pool. They also reveal
that a good engine for rating loans is essential, and that guarantors are an
important tool to improve the performance of the system.

The simulation strategy described in this paper can be extended to richer
settings, with parameters adjusted to fit real data and more functionalities
added to the system. For instance, other classes of guarantors should be
considered131313The system admits different roles for guarantors additionally
to those examined here. For instance, multiple guarantors could be
simultaneously used for sets of loans, as stakers in mutual funds or mutual
guarantors in the joint liability arrangements discussed in [1]. The model
could also be extended to richer environments, including situations in which
the economy is subject to shocks. In this case, it is important to model a
dynamic behavior of the platform parameters to respond to such shocks.

At this point, we have not yet focused on the optimal choice of platform
parameters. This is a key numerical exercise to be performed in future work,
once a good fit to real data is obtained.

As next steps, we plan to:

  * •

Obtain _real world_ data in order to validate/adjust our approach.

  * •

Implement a secondary market so that investors can trade their quotas, as a
Decentralized Finance (_DeFi_) marketplace.

  * •

Add transaction fees to the model.

  * •

Include tax effects, which may depend on specific jurisdictions.

  * •

Incorporate different liquid assets in the Liquidity Pool and hedge mechanisms
for currency tokens exchange risks.

  * •

As exemplified during the discussion about the platform’s spread (section 3),
depending on the scenario, there will be optimal values for the platform’s
parameters. We plan to perform optimisations based on the simulations in order
to evaluate how these parameters could be optimally set for a wider variety of
scenarios.

## References

  * [1] Maitreesh Ghatak and Timothy W Guinnane  “The economics of lending with joint liability: theory and practice”  In _Journal of development economics_ 60.1 Elsevier, 1999, pp. 195–228
  * [2] Gabriel de Abreu Madeira, Aurimar Cerqueira, Licio Carvalho and Fernando Steler  “The Economics of the DeLend Project: Contributions and Decentralized Finance Market Design”  In _delend.com.br_ delend.com.br, 2022
  * [3] Bernard Salanié  “The economics of contracts: a primer”  MIT press, 2005
  * [4] Joseph E Stiglitz and Andrew Weiss  “Credit rationing in markets with imperfect information”  In _The American economic review_ 71.3 JSTOR, 1981, pp. 393–410
  * [5] Robert M Townsend  “Distributed Ledgers: Design and Regulation of Financial Infrastructure and Payment Systems”  MIT Press, 2020
  * [6] Robert M. Townsend and James Killian  “Distributed ledgers: Innovation and regulation in financial infrastructure and payment systems”, 2019

##  Appendix A Appendices

The following set of appendices provide more in-depth discussions regarding:

  * •

A.1 \- Derivation of the anticipation formula without guarantors.

  * •

A.2 \- Anticipations involving guarantors, and the anticipation formula in
this context.

  * •

A.3 \- A set of _unit tests_ for the simulator components, in order to
validate them.

###  A.1 Anticipation formula

In order to compute the anticipation offer, we first ignore the possibility of
default, and consider only the time discount. Since the borrower will receive
the full anticipation amount $A$ immediately in cash, and the receivables
$R_{i}$ will be cashed by the platform in future instalments, these $R_{i}$
must be discounted by at least a risk free interest rate (a base
rate)141414For instance, in Brazil, a reasonable _proxy_ for a risk free rate
is the CDI, which is the interbank rate set by the Central Bank.. Denoting
this rate as r, in the default-free case, the anticipation value would be the
sum of the $R_{i}$ brought to present value (we can treat each receivable
independently, and let’s call it the _base rate anticipation_
$A_{br}$)151515The formulas consider a generic number of installments $N$,
with $N=4$ for the example we provided in section 2.2.1.,

$A_{br}=\sum_{i}^{N}\frac{R_{i}}{(1+r)^{i}}$ (1)

In order to obtain a better return, the platform may also add a spread $s$,
and the _no default anticipation_ $A_{nd}$ becomes,

$A_{nd}=\sum_{i}^{N}\frac{R_{i}}{(1+r+s)^{i}}$ (2)

This extra (compound) percentage $s$, on top of the base rate, is the
additional return for investors over the risk-free investment options.

In real situations, however, there will always be some level of default. Risk
assessment is a crucial task for the platform, since losses related to default
should be considered by investors. A good risk assessment also minimize
informational frictions, such as adverse selection ([4]). The simulator can
consider both, the possibility of default and of delayed payments, but for the
simulations discussed here, have ignored the latter.

As an example, suppose two of the four installments ($R_{2}$ and $R_{3}$,
dashed arrows) are not honored in their due time, as shown in Figure 12. In
this scenario, there are two possible outcomes (Figure 13): _i)_ all the
installments/receivables are eventually paid; or _ii)_ payments are only
partially honored.

Figure 12: Cash flow where $R_{2}$ and $R_{3}$ are not paid on time Figure 13:
Cash flow with delays (_i_), and with both, delays and defaults (_ii_)

Figure 13 depicts a particular view, where we consider the second payment to
be $R_{2}$, irrespective of the period, the third to be $R_{3}$, and so on.
One advantage of this formulation is that there will not be ambiguities to
classify any payment.

In the numerical exercises presented in this document, for simplicity, we
focus on a subset of the possible profiles of payment. We define the default
probability $p$ to be the probability that a borrower expected to pay an
installment at a given period stops making payments. We can certainly model
the payment behavior in more elaborate ways, but for now we’ll consider this
simple definition. A few consequences of this definition are:

  * •

Payments have (are drawn from) a delay probability distribution.

  * •

Borrowers who have not yet defaulted may default at any period, with constant
probability. Once they fail to make a payment, no further installments are
paid. In this sense, this default probability can be interpreted as a
bankruptcy probability.

These definitions are important because they determine the computation of
anticipation offers, as we shall discuss now.

If we ignore delays, $p_{d,i}$, the probability that a borrower does default
at time $t_{i}$, is given by the geometric probability distribution,

$p_{d,i}=(1-p)^{(i-1)}p$ (3)

We can interpret this probability as being composed by two terms: _i)_
$(1-p)^{(i-1)}$ is the probability that the borrower does not default on the
first $(i-1)$ periods; and _ii)_ $p$ the (constant over time) probability that
the borrower ends up defaulting at i. The probability $p_{\bar{d},i}$ that the
borrower does not default at time $t_{i}$ is,

$p_{\bar{d},i}=(1-p)^{(i-1)}(1-p)=(1-p)^{i}$ (4)

One important consequence of this formula is that the default probability
decreases as a function of the time period, not because defaults become less
likely, but rather due to the fact that borrowers’ payments may cease in
earlier periods: the further in time, the smaller the number of borrowers that
have not yet defaulted.

We need these probabilities in order to compute the expected losses/payments
associated to a set of receivables to be paid by a borrower for which we
attribute a default probability p. The expected payment for each installment
at $t_{i}$, $R’_{i}$, is the probability that the borrower does not default at
time $t_{i}$ times the installment amount $R_{i}$,

$R’_{i}=(1-p)^{i}R_{i}$ (5)

If we use the expected payment in the anticipation price formula, then _final_
anticipation formula (not yet including guarantors) becomes,

$A=\sum_{i}^{N}\frac{R^{\prime}_{i}}{(1+r+s)^{i}}=\sum_{i}^{N}\frac{(1-p)^{i}R_{i}}{(1+r+s)^{i}}$
(6)

###  A.2 Guarantors

The interaction/negotiation between the platform and a guarantor can be
modeled in different ways. Here, we consider a situation where guarantors have
to stake an amount $V_{c}$ (a collateral that is lost in case of borrower
default) in return of a gain $G$. A simple approach, which is advantageous
from a computational perspective, is to consider that the guarantor sets its
desired gain $G$ and communicates it to the platform. The platform then
decides (computes) if it considers it advantageous, and makes the anticipation
offer (to the borrower) including or excluding the guarantor. The guarantor
computes its desired gain as follows.

The guarantor has an amount $V_{c}$ to stake as a collateral, an estimate of
the default probability $p_{g}$, knows the base rate is $r$ and has an
expected spread $s_{g}$. The platform (in principle) does not know the
guarantor’s default estimate nor $s_{g}$. Since the guarantor looses the
collateral in case of default, its expected gain will be estimated as
(considering an arbitrary number of $N$ installments),

$E[G]=(1-p_{g})^{N}\left(V_{c}(1+r)^{N}+G_{s}\right)$ (7)

where $G_{s}$ is the extra gain to be paid by the platform. Given the
guarantor’s desired spread is $s_{g}$, the guarantor will stipulate its
(expected) gain to be,

$E[G]=V_{c}(1+r+s_{g})^{N}$ (8)

These relations define $G_{s}$ to be,

$G_{s}=V_{c}(1+r+s_{g})^{N}/(1-p_{g})^{N}-V_{c}(1+r)^{N}$ (9)

Note that the formula above incorporates the fact that for higher (estimated)
risks $p_{g}$, guarantors ask for higher returns (Figure 14). Considering this
expected gain, the platform computes the anticipation offer and checks if it
is feasible – in the sense of being advantageous for all the players. We now
show how the platform computes the anticipation offer considering the
guarantor’s stake and requested gain.

Figure 14: Asked gain $G_{s}$ as a function of $p_{g}$ and $s_{g}$, with
$r=1\%$ (annualized).

The platform must consider these three cash flows: (i) the borrower’s
receivables/installments; (ii) the gain $G_{s}$ to be paid to the guarantor
once the last installment arrives; and (iii) the collateral, that the platform
gets to keep in case of default and that must be adjusted by the risk free
rate $r$. If, for a moment, we ignore the base rate and the platform’s spread
(set both to zero), and write the anticipation value as a sum these cash flows
expected values: (i) $E[R]$, the receivables expected value; (ii) $E[G_{s}]$
the expected value to be paid to the guarantor – this amount is discounted
from the anticipation, thus, it is paid by the borrower; and (iii) $E[L_{c}]$
the guarantor’s collateral expected loss; we have, calling it the _no spread_
anticipation $A_{g}^{no-spread}$,

$A_{g}^{no-spread}=E[R]-E[G_{s}]+E[L_{c}]$ (10)

where,

$E[R]=\sum_{i}^{N}(1-p)^{i}R_{i}$ (11)

$E[G_{s}]=(1-p)^{N}G_{s}$ (12)

$E[L_{c}]=\sum_{i}^{N}(1-p)^{(i-1)}pV_{c}(1+r)^{i}$ (13)

It is important to note the while the guarantor computes expected values using
its default estimate $p_{g}$, the platform considers its own estimate $p$.

The above anticipation $A_{g}^{no-spread}$ corresponds to the value the
platform should anticipate in order to, on average, cover the default losses,
with no profitability – and when $r=0,s=0$. However, since the base rate will
not be zero, and, to deliver a higher return, we must add a spread $s$, we
have to insert back the discounts $(1+r+s)$ to each of these cash fluxes, and
the anticipation offer formula becomes,

$A_{g}=\sum_{i}^{N}\frac{(1-p)^{i}\left(R_{i}-\delta_{i,N}G_{s}\right)+(1-p)^{(i-1)}pV_{c,i}}{(1+r+s)^{i}}$
(14)

where we used the notation,

$V_{c,i}=V_{c}(1+r)^{i}$ (15) $\delta_{i,N}=\begin{cases}\ 1,&\text{if }i=N\\\
\ 0,&\text{otherwise}\end{cases}$ (16)

From equation (14), we can see that:

  * •

The larger the collateral $V_{c}$, the better the anticipation, which, at
least indirectly, is an incentive for guarantors to stake bigger amounts –
since it increases the borrowers’ acceptance probability. As shown in Figure
15 (left), as $V_{c}$ becomes smaller the anticipation tends to become the
same as without guarantors.

  * •

As the guarantor’s estimated default probability $p_{g}$ decreases, so does
its asked gain $G_{s}$ – which increases the anticipation value. At the same
time, if the platform’s estimated default $p$ increases, the discount to the
anticipation coming from $G_{s}$ gets smaller – since the the gain is only
paid in the borrower does not default, and the anticipation considers expected
values. These two factors combined lead to the guarantor’s involvement being
advantageous when $p_{g}<p$ (Figure 15, right).

Figure 15: Anticipation, where the receivables sum to 100: as a function of
$V_{c}$, with $p=0.1$,$p_{g}=0.05$, $s_{g}=0.01$ and $N=3$ (left); and as a
function of $p_{g}$, with $p=0.1$, $V_{c}=20$, $s_{g}=0.01$ and $N=3$ (right)

Finally, although, in principle, guarantors are better informed agents, thus
having a better risk assessment ($p_{g}$ more accurate than $p$), the true
default probability $p_{T}$ is not known. Figure 16 shows the results of a
simulation with the payments received by _i)_ the platform (with guarantors);
_ii)_ the platform without guarantors; and _iii)_ the guarantors. The dashed
lines correspond to: _i)_ the anticipation value with guarantors (blue line);
_ii)_ the anticipation value without guarantors (red line); and _iii)_ the
guarantors expected payment (yellow line).

As expected, whenever the true probability is bigger than the estimated by the
agent (platform or guarantor), the received payments are less than the
expected amounts: the platform expects to receive $\sim 87.5$ when guarantors
are involved, $\sim 81.3$ when they are not involved, and the guarantors
expect a payment of $\sim 51.5$. However, guarantors also have a _hedging_
effect for the platform: the difference between the expected payment (blue
dashed line) and the actual received amounts (blue boxes) are considerably
smaller than when guarantors are not involved (red line/boxes). This effect
is, of course, dependent on the amount $V_{c}$ staked by the guarantor, since,
as this amount decreases, the results would converge to the situation without
guarantors.

Figure 16: Simulation of received payments where $N=3$ (three installments
that sum 100), $p=0.1$, $V_{c}=50$, $p_{g}=0.05$, and $s_{g}=0.02$, as a
function of the true default probability $p_{T}$ (here, again, $r=0$ and
$s=0$). The data represented by the boxplots was generated considering 100
borrowers, and their payment behaviour was repeated 100 times. At each
iteration the average payment was computed. These average payments are
represented by the boxplots. Note that the blue and red lines coincide with
the received payments when $p_{T}=0.1$, which is the platform’s default
probability estimate, and the yellow line coincide with the guarantor’s
received payment when $p_{T}=0.05$, the guarantor’s default probability
estimate. Figure 17: Simulation of average one period returns, where the true
default probability if 0.15. As for the platform and guarantors’ estimates,
they are measured with respect to the true default probability, by $\delta p$
and $\delta p_{g}$, respectively – for example, $\delta p=0.1$ means the
platform’s estimated probability is $p=0.16$. The dashed dashed black line
represents the expected return $r+s$. The situation where guarantors are not
considered are also included (labeled as _no g._ , in blue). We can see that:
(i) returns are much more sensitive to errors on the platform’s probability
estimate; and (ii) as already noted above, guarantors also constitute a
hedging mechanism for the platform.

###  A.3 Python implementation and simulator _unit tests_

Since agent-based simulations is a well established approach, employed in a
wide variety of situations, many existing frameworks exist and can be used to
leverage the development of a code to address a particular problem. We have
used the Mesa framework, given its adoption, stability and functionalities.

The purpose of this section is to introduce the different components and
agents in simplified examples, and these examples also are meant to validate
the simulator (kind of _unit tests_ for the simulator).

Any dynamics involving loans/anticipations can only begin once there are
resources on the liquidity pool. One of the main input parameters (of the
simulations) sets the base rate $r$, that affects how much the available
resources (at the liquidity pool) are adjusted at each time period. Figure 18
(left) shows the evolution of the funds: the liquidity pool (available
borrowing funds); the loan fund; and their sum. Since there are no loans, the
loan fund remains empty in this case.

In order to validate whether the funds evolve as expected, we compute the one
period returns for the total assets. Later, once investors are introduced,
we’ll consider quota returns instead. Figure 18 (right) shows that in this
case the one period return (blue line) is exactly the base rate $r$ (green,
dashed line) – the red dashed line corresponding to $r+s$, which is the
targeted return, but without borrowers it is not achieved.

Figure 18: Liquidity Pool, Loan Fund and Total assets time evolution, with no
borrowers. Here, the blue and red curves overlap, since there are no loans
(left). Time evolution of one period return (Av. Funds + Debts) with no
borrowers. The red line corresponds to $r=0.797\%$, $10\%$ per year (right).

Next, borrowers are introduced, at first with 0 default probability. The total
assets returns must now be $r+s$, with (very close to) optimal allocation of
the liquidity pool (resources continuously consumed by loans), and this is
what we obtain (Figures 19 and 20).

Figure 19: Liquidity pool assets time evolution with (almost) full allocation
and no default. At the end of 36 periods, Av. Funds + PV Debts = 176.1,
whereas $(1+r+s)^{36}=1.768$. This (small) difference is due to the not 100%
allocation of the liquidity pool over time. Note that time $t=0$ corresponds
to the initial configuration, prior to any borrowing. Figure 20: Time
evolution of one period returns (Av. Funds + Debts) with (almost) full
allocation and no default. The red line corresponds to $r+s=1.59\%$ ($10\%$
per year each). Initially, there is a transient phase but then the one period
return tends to converge to $r+s$ – as mentioned above, since the Liquidity
Pool’s allocation is never 100%, the return is slightly smaller.

It is reasonable to assume a market much bigger than the platform’s lending
resources, in the sense that we would never reach a _saturated market_
situation, with loan demand entirely fulfilled161616Fulfilled in the sense
that they are either accepted, or rejected by the borrower or the platform –
and not unfulfilled due to unavailable resources.. However, we do want to test
this scenario, of saturated market, and validate that the simulations
reproduce the expected results.

In case the excess resources of the liquidity pool are neither consumed by
loans/anticipations nor by withdrawals, once the loans reach a maximum
constant volume (borrowing demand totally fulfilled), the total assets returns
start to converge to the base rate $r$, as the liquidity pool’s stalled
resources increase, as shown in Figures 21 and 22.

Figure 21: Liquidity pool assets time evolution with a limited number of
borrowers. At some point, there is enough credit to fulfill the _market_
demand – the borrowed amount/debt becomes constant. At this point, the return
starts to decrease, since the liquidity pool’s allocation becomes more and
more inefficient (see Figure 22). Figure 22: Time evolution of one period
return (Av. Funds + Debts) with a limited number of borrowers. The red line
corresponds to $r+s=1.59\%$ ($10\%$ per year each) and the green line
corresponds to $r=0.797\%$, the base rate. As the Liquidity’s Pool allocation
becomes more inefficient, the return starts to converge to the base rate.

For the previous example, we have set the parameters such that borrowers
always accepted the platform’s anticipation offers. However, we can expect
them to be price (discount) sensitive, in the sense that as the anticipation
offers discounts become bigger (more expensive), the fraction of borrowers
willing to accept the offer decreases. As discussed in section 2.3, we have
modeled this behavior via a function $f(A)$ that assigns an acceptance
probability as a function of the anticipation offer $A$. Figure 23 shows the
time evolution of the loan fund (right plot), for a particular
parameterization of the $f(A)$ function (left plot).

Figure 23: Left, example of an acceptance rate function $f(A)$, and the time
evolution of the loan fund over multiple runs (right).

The acceptance rate function (a.k.a price sensitivity curve) is defined as
follows,

$f(A)=\frac{1}{1+e^{\phi(A-A_{0})/A_{0}}}$ (17)

where $A_{0}$ is the anticipation offer without guarantors and considering a
_reference_ spread $s_{0}$: this function is thus parameterized by two
parameters, $\phi$ and $s_{0}$, where the first determines the _spread_ of the
price sensitivity and the latter the _reference level_ (_position_). As
$s_{0}$ decreases, smaller fractions of the borrowers’ population accept the
anticipation offers (while keeping all other factors constant), and, as a
consequence, the platform’s capability to obtain funds decreases (Figure 24).

Figure 24: Liquidity Pool + Loan fund (mean) performance for different levels
of borrowers acceptance rates (left). (Mean) One period returns for each of
the borrowers’ threshold spread (right).

An important element of the simulations is the borrowers’ default probability
distribution. We sample, for each borrower, a default probability from a Beta
distribution, $p\sim\mathcal{B}(a,b)$, where, for each simulation, we set the
values of $a$ and $b$ – as usual, it is not only a matter of the average
value, but also of variance. Figure 25 compares the outcomes of two different
choices for $a$ and $b$. The average outcome is the same, but the variance is
different.

Figure 25: One period returns (100 simulations) for defaults sampled from a
Beta(2, 400) (left); and from a Beta (2, 150) (right). The red lines are the
averages, and both are very close to the targeted $(r+s)$ return. As expected,
the bigger the default, the bigger the variance.

Given a perfect _rating_ engine, the platform would, on average, obtain the
targeted returns. Unfortunately, such an engine does not exist, and we must
try to obtain the best balance between bias and variance given the (training)
data available. In order to emulate different _qualities_ for the rating
engine, in a simple way, we have implemented a linear relation between the
true default probability and the platform’s estimate. Considering $p$ to be
the platform’s estimate, and $p_{T}$ to be the true default probability, we
have

$p=ap_{T}+b+\sigma,$ (18)

where $a$ and $b$ are parameters we define on the input for each simulation,
and $\sigma$ is sampled from a Gaussian distribution with zero mean and a
standard deviation also defined as an input parameter – a _perfect_ engine
means $p=p_{T}$.

As example, we have simulated (Figure 26) the impact on the returns using
different values for $a$ (from 0.8 until 1.2), while keeping $b$ and $\sigma$
equal to zero, for two different default distributions, one emulating a
scenario of relatively low default rates (Beta(10, 1000)), and one of
relatively high default rates (Beta(10,100)). While for the low default rates
scenario, a less accurate rating engine may still be tolerable, as the default
rates increase, without having a good rating, the results quickly start to
deviate significantly from the targets – see Figure 26, in particular the case
where $a=0.8$ when defaults are high, where the returns are negative, since
the engine is systematically (significantly) underestimating the true default
probabilities. Even though the goal will always be to have a proper rating
engine, there may be situations where where we cannot. For example, when
starting in a new market, with limited to no data, it will be wiser to be more
conservative with the ratings, assuming _high(er)_ default probabilities. This
would ensure safer loans, but would also limit the volume of borrowers willing
to accept the offers. This is one scenario where guarantors may play an
important role, by being able to better assess the borrowers risks.

Figure 26: One period returns as a function of different biases of the rating
engine (different values for $a$, see equation 18), and for defaults sampled
from a Beta(2, 200) (left), and from a Beta(2, 80) (right). Note the
difference in scales between the two plots: the bigger the default rates, the
bigger the impact a not well calibrated rating will have – potentially
becoming negative.

As discussed in section 2.2.2, guarantors may play different roles, but
considering the type we have considered so far, they will only be relevant
when there is a significant asymmetry between their default probability
assessments ($p_{g}$) and the platform’s assessment ($p$): (i) when $p_{g}\sim
p$ or $p_{g}>p$ the anticipation offer when considering guarantors will be
worse than without guarantors – the platform may still consider making an
offer involving guarantors due to the _hedging_ effect shown in Figure 16;
(ii) it’s when $p_{g}<p$ that involving the guarantor will tend to become
advantageous for all players (the bigger the difference in probabilities, the
better, in this sense), since the anticipation offer with guarantors will tend
to be better than without involving them – which makes sense, since the
platform would be _overpricing_ due to its overestimation of the borrower’s
default probability.

In order to test the guarantors agents, we have first considered a situation
where borrowers do not default ($p_{T}=0$), with a perfect rating model. In
this case, the anticipation offers involving guarantors will actually be lower
that without guarantors (but we can make the platform consider this option via
input parameters). An important input parameter is the fraction of borrowers
that have a guarantor, and in this case we have set it to one. As expected, in
this case the system evolves in the same way as if guarantors had not been
involved (Figure 27).

Figure 27: Liquidity Pool + Loan fund performance, where all loans involved a
guarantor, with no defaults (left). After a transient initial phase, the
average returns converge to the expected values of $r+s$, red dashed line, the
green line being the base rate $r$ (right).

Whenever guarantors are involved, the cash flow management is different
(section 2.2.2): stakes must be either re-paid with interests or kept in case
of default, and gains must be paid when loans are honored. When there is no
asymmetry between $p$ and $p_{g}$ (the platform’s and the guarantor’s default
estimates, respectively), the platform should obtain the same returns as it
would without involving guarantors. This is what we validated (Figure 28) by
considering borrowers with default probabilities sampled from a Beta(2, 200)
($p\sim 1\%$).

Figure 28: Liquidity Pool + Loan fund performance (100 simulations), where all
loans involved a guarantor, for defaults sampled from a Beta(2, 200). After a
transient initial phase, the average returns converge to the expected values
of $r+s$, red dashed line, the green line being the base rate $r$ (right).

The last agent we’ll introduce are investors. Their relevance is obvious: they
provide more resources to the system. A set of parameters are used to
characterize them – as with the other agents, most parameters are sampled from
distributions specified by input options, in such a way that each investor
will have different characteristics/behavior. Amongst the most relevant
parameters are: (i) Expected return: the minimum performance in order to
invest; (ii) Investment amount: how much to invest; (iii) Profit withdrawal
rate: rate that might lead to a withdraw (may be random); (iv) Loss withdrawal
rate (again, may be random).

So far we could compute profits directly from the assets (Liquidity Pool +
Loan Fund), however, once we have a flux of investors investing and
withdrawing, we need to work with quotas, in order to compute the returns, so
from now on, that is how we compute returns. Figure 29 exemplifies the
difference between the quota and the assets. In this simplified example,
without borrowers, the return should be the base rate $r$.

Figure 29: Outcome of a simulation that starts with a seed investor (in this
case, the seed investor does not withdraw), followed by a constant flux of
investors (one new investor per period) that withdraw after 3 periods, thus
stabilizing at a total of 4 investors (top, right) – for simplicity we did not
include borrowers. Once we have this flux of investors, it is necessary to
work with quotas (bottom, right), to compute the returns. The bottom left plot
shows that the quota returns are indeed the base rate $r$, the dashed green
line.


# Evaluation of Latent Space Disentanglement
in the Presence of Interdependent Attributes

###### Abstract

Controllable music generation with deep generative models has become
increasingly reliant on disentanglement learning techniques. However, current
disentanglement metrics, such as mutual information gap (MIG), are often
inadequate and misleading when used for evaluating latent representations in
the presence of interdependent semantic attributes often encountered in real-
world music datasets. In this work, we propose a dependency-aware information
metric as a drop-in replacement for MIG that accounts for the inherent
relationship between semantic attributes.

Figure 1: Plots of (a) SCC against MIG, (b) SCC against DMIG, and (c) DMIG
against MIG, on the validation set.

##  1 Introduction

Disentanglement learning has been an influential field of studies for
controllable music generation with variational autoencoders (VAEs). A number
of previous studies have attempted supervised disentanglement learning
techniques on several semantic attributes such as rhythm, pitch range [1],
note density, contour [2], arousal [3], style [4], and genre [5] to varying
degrees of success. However, learning to simultaneously manipulate multiple
attributes, in particular, remains a difficult task to both achieve and
objectively evaluate [6] due to the limitation of current metrics.

One major issue with popular disentanglement metrics [7], such as mutual
information gap (MIG) [8], separate attribute predictability (SAP) [9], and
modularity [10], is that they were designed for independent generative
factors, rather than real-world semantic attributes. As semantic attributes
related to music are often highly interdependent, these metrics do not provide
an accurate reflection of the ‘quality’ of learnt latent representation
regularized for multiple interdependent attributes. Information inherently
shared between attributes is penalized in the same way as that due to
undesired entanglement issues.

In this work, we propose a dependency-aware metric based on mutual information
(MI) to act as a drop-in replacement for MIG. Preliminary experiments were
carried out to demonstrate the benefits of the proposed metrics over MIG.

##  2 Proposed Metrics

Consider a set of attributes $\\{a_{i}\\}_{i=1}^{M}$ and a latent vector
$\bm{z}\in\mathbb{R}^{D}$ with $M\leq D$. Without loss of generality, for
$i\leq M$, we assume $z_{i}$ is regularized for $a_{i}$. The remaining
dimensions are unregularized. $\mathcal{H}(\cdot)$ denotes entropy while
$\mathcal{I}(\cdot,\cdot)$ denotes mutual information.

MIG was proposed in [8] to measure the degree of disentanglement in a latent
space. The idea behind MIG can be said to measure: for each attribute, the
normalized difference between the mutual information between the attribute and
its most informative latent dimension, and that between the attribute the
second-most informative latent dimension. Mathematically, MIG is given by

$\text{MIG}(a_{i})=\left(\mathcal{I}(a_{i},z_{i})-\mathcal{I}(a_{i},z_{j})\right)/\mathcal{H}(a_{i}),$
(1)

where $j=\arg\max_{k\neq i}\mathcal{I}(a_{i},z_{k})$. It is reasonable to
assume $i=\arg\max_{k}\mathcal{I}(a_{i},z_{k})$ in a supervised setting;
otherwise MIG takes negative values to indicate regularization failure. The
normalization is given by $\mathcal{H}(a_{i})$, which would be the maximum
possible difference in MI between a latent dimension $z_{i}$ coding perfectly
for $a_{i}$, i.e., $\mathcal{I}(a_{i},z_{i})=\mathcal{H}(a_{i})$ and the
second-most containing no information about $a_{i}$, i.e.,
$\mathcal{I}(a_{i},z_{j})=0$. As such, MIG is bounded above by one.

However, given the interdependence of semantic attributes, if $j\leq M$, the
ideal value of the difference
$\mathcal{I}(a_{i},z_{i})-\mathcal{I}(a_{i},z_{j})$ is no longer
$\mathcal{H}(a_{i})$ since

$\mathcal{I}(z_{j},a_{j})>0\wedge\mathcal{I}(a_{i},a_{j})>0\implies\mathcal{I}(a_{i},z_{j})>0.$
(2)

For regularized latent dimensions, we consider a pair of inherently entangled
attributes $(a_{i},a_{j})$, i.e., $\mathcal{I}(a_{i},a_{j})>0$. Under the
ideal case where $z_{i}$ is fully informative [7] about $a_{i}$, i.e.,
$\mathcal{H}(a_{i}|z_{i})=0$, we have

$\displaystyle\mathcal{I}(a_{i},z_{i})-\mathcal{I}(a_{i},z_{j})$
$\displaystyle\qquad=\left[\mathcal{H}(a_{i})-\mathcal{H}(a_{i}|z_{i})\right]-\left[\mathcal{H}(a_{i})-\mathcal{H}(a_{i}|z_{j})\right]$
(3)
$\displaystyle\qquad=\mathcal{H}(a_{i}|z_{j})\qquad\because\mathcal{H}(a_{i}|z_{i})=0.\endlinenomath$
(4)

Moreover, in the ideal case, $z_{j}$ and $a_{j}$ also have an invertible
mapping between each other, this means that
$\mathcal{H}(a_{i}|z_{j})=\mathcal{H}(a_{i}|a_{j})$. Hence, in the ideal case,
the difference is given by

$\mathcal{I}(a_{i},z_{i})-\mathcal{I}(a_{i},z_{j})=\mathcal{H}(a_{i}|a_{j}).$
(5)

As such, we extend the definition of mutual information gap to the dependency-
aware mutual information gap (DMIG) as follows

$\text{DMIG}(a_{i})=\begin{cases}\left(\mathcal{I}(a_{i},z_{i})-\mathcal{I}(a_{i},z_{j})\right)/\mathcal{H}(a_{i}|a_{j})&j\leq
M\\\
\left(\mathcal{I}(a_{i},z_{i})-\mathcal{I}(a_{i},z_{j})\right)/\mathcal{H}(a_{i})&j>M,\end{cases}$
(6)

where $j=\arg\max_{k\neq i}\mathcal{I}(a_{i},z_{k})$. DMIG remains faithful to
the core idea of MIG but modifies the normalization to properly account for
inter-attribute dependencies. When $a_{i}$ and $a_{j}$ are independent,
$\mathcal{H}(a_{i})-\mathcal{I}(a_{i},a_{j})=\mathcal{H}(a_{i})$ and the DMIG
reduces to vanilla MIG.

Note that in the case of continuous random variables, differential entropy can
be negative, unlike discrete Shannon entropy. This is particularly evident
with conditional differential entropy and may result in DMIG values above
unity whenever $\mathcal{H}(a_{i}|z_{i})/\mathcal{H}(a_{i}|z_{j})$ is
negative.

##  3 Experiments

To illustrate the key features of the dependency-aware metrics, we evaluate
the latent space of a VAE model trained to reconstruct raw musical audio while
being regularized for two highly correlated attributes111See the supplementary
materials for full experimental details at
https://github.com/karnwatcharasupat/dependency-aware-mi-metrics..

###  3.1 Data and model

We use the NSynth dataset [11], which is a large-scale dataset of musical
notes played by various instruments with diverse timbral qualities. The
dataset provides 4-second snippets sampled at $16\text{\,}\mathrm{kHz}$. From
the raw audio provided by NSynth, we extract two semantic attributes, namely,
brightness and depth using the AudioCommons Timbral Model [12]. Since both the
brightness and depth features are heavily influenced by the spectral
distribution of the sound [13], they are strongly correlated.

We trained a convolutional VAE model to reconstruct the log-magnitude
spectrogram of the audio and obtain reconstructed time-domain audio using a
phase-bypass reconstruction. The models are trained using the attribute-
regularized $\beta$-VAE loss function [14, 15, 2]

$\mathcal{L}=\mathcal{R}(\hat{\mathbf{x}};\mathbf{x})+\beta\mathcal{D}\left(\mathbf{z}\right)+\gamma\textstyle\sum_{i}\mathcal{A}(z_{i};a_{i}),$
(7)

where $\mathcal{R}(\cdot)$ is the reconstruction loss implemented via the mean
square error on the log-magnitude spectrograms, $\mathcal{D}(\cdot)$ is the KL
divergence term with a standard normal prior, and $\mathcal{A}(\cdot)$ is the
AR-VAE regularization from [2]. We used $D=$512$$, $\beta=$1$$, and
$\gamma=$10$$.

###  3.2 Results

Figure 1 plots the MIG, DMIG, and Spearman correlation coefficient (SCC) of
the attributes (brightness and depth) with respect to their respective
regularized latent dimensions on the validation set over the course of the
training. Due to the high correlation between brightness and depth, for most
of the training, the most and second-most informative latent dimensions in
MIG/DMIG are the regularized ones that encode for the attributes.

As seen from Figure 1(a), the MIG values are generally very low (in the order
of ${10}^{-2}$, out of maximum 1) despite the SCC indicating successful
encoding of the attribute information into the latent dimension. This is due
to the high mutual information between brightness and depth, resulting in a
very low true bound for MIG. On the other hand, we can observe from Figure
1(b) that DMIG reflects more clearly the quality of the latent space as it
encodes the attribute; the rapid improvement in SCC mostly occurred before
DMIG reaches one (dotted line). In Figure 1(c), the highly linear relationship
between MIG and DMIG further demonstrates the idea that DMIG is simply MIG
renormalized to better reflect the dependencies between semantic attributes
coded by the model. Admittedly, the peculiarities of differential conditional
entropy and the practical computation of mutual information and entropy
estimates [16] have contributed to a DMIG range that is much larger than
vanilla MIG. We will be working to resolve this limitation in future work.

##  4 Conclusion

In this work, we propose a dependency-aware extension to a popular
disentanglement metrics, mutual information gap (MIG), to better account for
inter-attribute dependencies often observed in real-world datasets. Key
features of the proposed dependency-aware MIG were demonstrated via an
experiment on an audio dataset with highly correlated timbral attributes.

##  5 Acknowledgement

K. N. Watcharasupat acknowledges the support from the CN Yang Scholars
Programme, Nanyang Technological University, Singapore.

## References

  * [1] A. Pati and A. Lerch, “Latent Space Regularization for Explicit Control of Musical Attributes,” in _Extended Abstracts for ML4MD, ICML_ , 2019.
  * [2] ——, “Attribute-based regularization of latent spaces for variational auto-encoders,” _Neural Computing Applications_ , vol. 33, no. 9, pp. 4429–4444, 2020.
  * [3] H. H. Tan and D. Herremans, “Music fadernets: Controllable music generation based on High-Level features via Low-Level feature modelling,” in _Proc. ISMIR_ , 2020.
  * [4] Y. N. Hung, I. T. Chiang, Y. A. Chen, and Y. H. Yang, “Musical composition style transfer via disentangled timbre representations,” in _Proc. IJCAI_ , 2019, pp. 4697–4703.
  * [5] G. Brunner, A. Konrad, Y. Wang, and R. Wattenhofer, “MIDI-VAE: Modeling dynamics and instrumentation of music with applications to style transfer,” _Proc. ISMIR_ , pp. 747–754, 2018.
  * [6] A. Pati and A. Lerch, “Is Disentanglement enough? On Latent Representations for Controllable Music Generation,” in _Proc. ISMIR_ , 2021.
  * [7] K. Do and T. Tran, “Theory and Evaluation Metrics for Learning Disentangled Representations,” in _Proc. ICLR_ , 2020.
  * [8] T. Q. Chen, X. Li, R. Grosse, and D. Duvenaud, “Isolating sources of disentanglement in variational autoencoders,” in _Proc. NeurIPS_ , 2018.
  * [9] A. Kumar, P. Sattigeri, and A. Balakrishnan, “Variational inference of disentangled latent concepts from unlabeled observations,” in _Proc. ICLR_ , 2018.
  * [10] K. Ridgeway and M. C. Mozer, “Learning deep disentangled embeddings with the F-statistic loss,” in _Proc. NeurIPS_ , 2018, pp. 185–194.
  * [11] J. Engel, C. Resnick, A. Roberts, S. Dieleman, M. Norouzi, D. Eck, and K. Simonyan, “Neural audio synthesis of musical notes with WaveNet autoencoders,” in _Proc. ICML_ , 2017, pp. 1771–1780.
  * [12] A. Pearce, S. Safavi, T. Brookes, R. Mason, W. Wang, and M. Plumbley, “Deliverable D5.8 - Release of timbral characterisation tools for semantically annotating non-musical content,” Audio Commons Initiative, Tech. Rep., 2019.
  * [13] ——, “Deliverable D5.2 - First prototype of timbral characterisation tools for semantically annotating non-musical content,” Audio Commons Initiative, Tech. Rep., 2017.
  * [14] D. P. Kingma and M. Welling, “Auto-encoding variational bayes,” in _Proc. ICLR_ , 2014.
  * [15] I. Higgins, L. Matthey, A. Pal, C. Burgess, X. Glorot, M. Botvinick, S. Mohamed, and A. Lerchner, “$\beta$-VAE: Learning basic visual concepts with a constrained variational framework,” in _Proc. ICLR_ , 2017.
  * [16] F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau, M. Brucher, M. Perrot, and E. Duchesnay, “Scikit-learn: Machine Learning in Python,” _J. Machine Learning Research_ , vol. 12, pp. 2825–2830, 2011.