Method for generating counterfactual data from real data
Patent Information
- Application Number
- FR2023009754
- Authority / Receiving Office
- FR · FR
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-09-15
- Publication Date
- 2025-03-21
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Title of the invention: Method for generating counterfactual data from real data
[0001] The present document relates to a method for generating counterfactual data from real data, said real data being representative of a technical system State of the art
[0002] Detecting bias in an artificial intelligence system is a crucial issue to ensure its acceptability and reliability. The term "bias" refers to an imbalance in the predictions generated by the system in relation to a variable determined as sensitive. The sensitive variable here separates the observations into two groups, one of the two having potentially less accurate decisions than the second. In this context, it is essential to develop methods to identify, quantify and correct these biases in order to preserve the accuracy or effectiveness of the decisions made by artificial intelligence systems.
[0003] It is common in practice to have training and testing datasets that exhibit imbalances with respect to sensitive variables. More subtly, new forms of bias can emerge both during the training phase and during subsequent decision-making, when new data are integrated. This underlines the need to be able to accurately and reliably assess the presence of bias, with the aim of certifying the conformity of algorithmic decisions.
[0004] It is common practice to have training and testing bases that are unbalanced with respect to sensitive variables. More subtly, new types of bias can appear both in the training bases and in the artificial intelligence decisions based on these bases when new data are used. Being able to quantify a bias and measure it accurately and reliably is then a major problem. Indeed, if the notion of bias can be defined mathematically using the notion of dependence in probability, providing a strategy to certify the presence or absence of bias in the training bases and automatic decisions on test data is fundamental to prove the conformity of algorithmic decisions.
[0005] It therefore appears imperative to develop a new approach to assess biases towards sensitive variables, by integrating robustness characteristics with respect to the data used. This new approach aims in particular to provide more reliable and consistent bias measurements, with a view to guaranteeing certification and the acceptability of artificial intelligence systems in various contexts.
[0006] This document proposes a process that is part of this approach.
[0007] There is thus a need to define a new way of providing bias measurements in relation to a sensitive variable having robustness properties with respect to the data used, in particular with a view to their certification.
[0008] To overcome the instability of bias measurement tools with respect to a sensitive variable, one solution is to generate a counterfactual observation for each observation from which the bias will be measured. Since the sensitive variable divides the set of known observations into two groups, the counterfactual of an observation corresponds to what an equivalent observation would likely be in the other group. As shown in the document “De Lara L., Gonzâlez-Sanz A., Asher N., Risser L. & Loubes JM (2021). Transport-based counterfactual models. https: / / arxiv.org / abs / 2108.13025”, using a bias measurement metric on the set of observations as well as their counterfactual observation makes it possible to stabilize and increase the robustness of the bias measurement.
[0009] Comparing an individual observation to its counterfactual observation also makes it possible to explain what criteria distinguish this observation from an observation in the other group. If this group is the prediction of an automatic classifier on technical data, such as time series from sensors, this makes it possible to explain on what criteria the classifier makes its decisions. If the person comparing the observations and their counterfactual has expertise on the data, this can also make it possible to validate that the decisions are made for good reasons.
[0010] Computing the counterfactual of complex observations, such as those of time series from sensors, remains a complex task because only a part of the data structure can distinguish two groups of observations. Similarly, this discriminating structure may not be represented by a directly observed variable but only be deduced using a non-linear combination of the observed variables. This is called a latent variable.
[0011] The objective of this document is to specifically calculate the counterfactual of complex observations, in the sense that the sensitive variable is not directly expressed by an observed variable. Statement of the invention
[0012] To this end, the present invention relates to a computer-implemented method for generating counterfactual data from real data, said real data being representative of a technical system, said method comprising the steps of: a. train a contrastive autoencoder from real data belonging to respectively to a first group or positive group, and to a second group or negative group, said auto-encoder comprising an encoder capable of generating a representation of data in a latent space and a decoder capable of generating output data from said representation in the latent space, said representation in the latent space comprising at least one so-called mixing dimension or variable representing characteristics extracted from the data which are as independent as possible of the group to which said data belong, and at least one so-called separating dimension or variable, representing characteristics extracted from the data which are as dependent as possible of the group to which said data belong, b. creating counterfactual data representations from the representations of the real data in the latent space, obtained using the encoder of the trained contrastive autoencoder, by modifying all or part of the separating dimensions of said representations of the real data, c. generating counterfactual data from said counterfactual data representations, using the decoder of the trained contrastive autoencoder.
[0013] Real data refers to an observation that was actually collected. It is authentic data from a concrete source and reflects real events, behaviors, or phenomena. This real data can include a variety of data types, such as images, texts, time series, audio recordings, other types of sensor data, etc.
[0014] Counterfactual data of a technical system refers to a hypothetical observation that represents an alternative reality or scenario for that system. In other words, it is data that describes how the system would have reacted or functioned differently if particular conditions had been changed.
[0015] In the context of a technical system, counterfactual data is used to understand how the system would have reacted if key variables or parameters had been adjusted. This can be useful for assessing the impact of different changes on the system's operation, for predicting potential outcomes, or for analyzing cause-and-effect relationships.
[0016] For example, consider an industrial furnace equipped with a temperature control system. Data on furnace temperatures as well as furnace control signals can be collected. A counterfactual in this context could be a hypothetical observation that shows how furnace temperatures would have changed if the control signal had been adjusted in a specific way. This allows for an assessment of how different control strategies can influence the behavior of the system.
[0017] In summary, counterfactual data for a technical system are simulated or hypothetical data that help explore potential outcomes by changing key variables in the system while holding the rest of the environment constant. This can be a useful approach for making informed decisions about adjustments or improvements to the technical system.
[0018] The counterfactual data thus obtained can be used to rebalance data distributions in the event of bias. In particular, in the event of underrepresentation of a particular group, counterfactual examples for this group can be created in order to increase its representation in the dataset.
[0019] A technical system is an interconnected set of components, devices or processes, whether mechanical, electronic, electrical, computer or other, working together to perform a specific function. Said technical system may be equipped with sensors. Said technical system is capable of providing information or a signal capable of providing information on the state of said technical system.
[0020] A non-exhaustive list of physical quantities or properties that can be measured by sensors in technical systems, as well as output information that can be provided by different technical systems, is defined below as examples: - Mechanical Systems: Position (encoders, position sensors), Speed (speed sensors, revolution counters), Acceleration (accelerometers), Force (force sensors, dynamometers), Pressure (pressure gauges, pressure sensors), Strain (strain sensors), Vibration (vibration sensors), Temperature (thermometers), Rotation (rotation sensors), Level (level sensors) - Electronic or Electrical Systems: Voltage (voltmeters), Current (ammeters), Resistance (ohmmeters), Frequency (frequency meters), Power (wattmeters), Power factor (power factor indicators), Frequency response curve (spectrum analyzers), Ripple (oscilloscopes), Threshold voltage (threshold detectors), Light intensity (photometers) - Computer Systems or Software: Data (data flow), Status (system state, errors), Execution Time (timestamps), CPU Usage (performance monitors), Memory Used (memory monitors), Latency (latency measurements), Network Throughput (traffic analyzers), Events (event logs) - Environmental Systems: Ambient temperature (thermometers), Humidity (hygrometers), Atmospheric pressure (barometers), Sound level (sound level meters), Air quality (air quality sensors), Solar radiation (pyranometers), Wind speed (anemometers), Precipitation (rain gauges) - Control and Automation Systems: Commands (control signals), States (system states), Alarms (fault alerts), Errors (error messages), Feedback signals (system returns), Switching states (states of switches, relays), Activation states (states of motors, actuators),
[0021] A contrastive autoencoder, also known as a contrastive pair autoencoder, is a variant of a classic autoencoder that aims to learn useful representations by focusing on the differences and similarities between input data. This type of autoencoder is typically used to learn discriminative features in classification, dimension reduction, or anomaly detection.
[0022] The contrastive approach in a contrastive autoencoder is to encourage the model to capture the relevant information to distinguish different pairs of training samples. Rather than simply minimizing the reconstruction distance between the input and output (as in a traditional autoencoder), the contrastive autoencoder maximizes the similarity between pairs of positive examples (which should be similar) and minimizes the similarity between pairs of negative examples (which should be different).
[0023] In other words, the contrastive autoencoder attempts to project similar examples that are close together into the latent representation space (or latent space), while moving dissimilar examples further apart. This allows the model to learn representations that capture significant variations and differences between examples.
[0024] The contrastive autoencoder is notably known from the document “Contrastive Variational Autoencoder Enhances Salient Features, Abubakar Abid and James Zou, 2019, arXiv 1902.04601”.
[0025] The architecture and / or hyperparameters of the encoder and decoder may be conventional and adapted to the type and dimensions of the input data. Similarly, the number of dimensions of the latent space may be adapted to the use case.
[0026] Said method may comprise, before step (a), a preliminary step of measuring real data using at least one sensor equipping the technical system.
[0027] Said method may comprise a subsequent step of analyzing the real data and the counterfactual data, then a step of correcting operating parameters of the technical system, based on said analysis.
[0028] The autoencoder may be a variational autoencoder. Such an autoencoder is known in particular from the document “Diederik P. Kingma and Max Welling, Auto-Encoding Variational Bayes, arXiv:1312.6114”.
[0029] In step (a), the cost function ltot used can be of the type:
[0030] ED A) = sim(xbXi) + ^( / ^(^)+ / ,^(^, Â()) + A,)) , Or
[0031] - Xj is an input data or observation, E is the encoder function, D and the function of the decoder, is a representation of a data or observation in the latent space, so that = E(Xi), the latent space '■ at the output of the encoder
[0032]
[0033] being subdivided into two parts or two sets of dimensions, noted respectively zm and forming respectively the mixing and separating dimensions or variables, - SÎm (XX) is a Similarity Penalty, - and X are weights, - ( zm ) — _ Sk (é', ' °û Sk ( C r ) is 'a distance from Sinkhorn between two subgroups of the latent observations Ç, these observations £ being subdivided into two sets C2 of similar size, - If — Sk^ÇA® f'0) + CA^ ' °ù CAQ ct are the observations from C and in the groups A = O , namely the second or negative group, and A = 1, namely the first or positive group, where the £A0 are randomly subdivided into two sets {^°, of similar size and where the ^A1 are randomly subdivided into two sets ^A!] of similar size, i„gis,= Sk(çM, CM)-
[0034] When training the autoencoder, the cost function, also called error function or penalty, is conventionally used to measure the difference between the input data and the output data reconstructed by the model, for a training data set.
[0035] The main objective of training is to minimize this cost function, which means that the neural network seeks to adjust its parameters in such a way as to reduce the errors between predictions and target values. Optimization consists of finding the parameter values that minimize the cost function, which leads to more accurate predictions that are more faithful to the training data.
[0036] X' and / can be defined by a user.
[0037] sim^ XX ) can be equal to yyy 2. Other similarity functions classics can be used.
[0038] The lmjf penalty tends to disperse the data. The penalty tends to independently group the data of the first group together, and the data of the second group together. The lregisi penalty tends to mix the data of the two groups.
[0039] The Sinkhorn distance can be calculated as follows.
[0040] Let P,Qe î^R^ be probability measures and let e >0, then the entropy-regularized version of the optimal transport problem is defined as follows: [O041] S^PQ^= min L
[0042] This problem admits a dual formulation
[0043] Se(P,Q) =
[0044] sup [ f(x)dP(x) + i, g(y)dQ(y) - ej, / 'x-^^dP(x)dQ(y) + ef^pygeLyo) RRR xR
[0045] When the probabilities are discrete, there exists an O(n2log(n)) algorithm for computing the Sinkhorn transport plan 77 — and hence the Sinkhorn distance — which is described in the paper “M. Cuturi, Sinkhorn distances: Lightspeed computation of optimal transport, Advances in neural information processing Systems, 26, 2013.”
[0046] During step (b), the latent dimensions or variables of a representation P of a data item or observation in the latent space being separated into two groups z™ and 4, respectively forming the mixing and separating dimensions or variables of P, the corresponding counterfactual data representation 4' can be obtained by concatenation of the groups Z™ and Zj, respectively forming the mixing and separating dimensions or variables of zi, where 4” = Z™ and where — cZ^ being the separating part of the latent space representing an observation j paired with i using the function CA, i.e. minimizing the Sinkhorn distance between two clouds of points from the groups A = 0, namely the second group or negative group, and A = 1, namely the first group or positive group.
[0047] In particular, in order to calculate = c ( - ) ' consider the separating part 4 of 7 A^7 the latent space of a set of observations / = 1, L, obtained using the encoder E. Let us also consider that the category A of each observation / is known. The observations l = 1, ..., L will have been selected so as to contain a sufficiently large number of observations in each class A = 0 and A = 1 (typically > 50 observations per class). The matching of observations of L,ç Ld 1 issues ri' J of the groups A = 0 and A = 1 is then carried out by minimizing the Sinkhorn distance between these two point clouds. Once this matching is done, the Zj will be the LS1 estimated as being the closest by the matching in group A different from that of observation i.
[0048] The invention also relates to a computer program comprising instructions for implementing the method of the aforementioned type, when this program is executed by a processor.
[0049] The invention also relates to a non-transitory computer-readable recording medium on which is recorded a program for implementing the method of the aforementioned type, when this program is executed by a processor.
[0050] The invention also relates to a computer system comprising
[0051] - an input interface for receiving data representative of a system technical,
[0052] - a memory for storing at least the instructions of a computer program of the aforementioned type,
[0053] - a processor accessing the memory to read said instructions and execute then the process of the aforementioned type,
[0054] - an output interface for providing counterfactual data generated during step (c). Description of figures
[0055] Other characteristics, details and advantages will appear on reading the detailed description below, and on analyzing the attached drawing showing various figures, in which:
[0056] [Fig.l] schematically represents an example of a computer system according to the present invention,
[0057] [Fig.2] illustrates the training of the contrastive autoencoder,
[0058] [Fig.3] illustrates the generation of counterfactual data using the trained contrastive autoencoder,
[0059] Detailed description of at least one embodiment
[0060] [Fig.l] schematically represents a computer system (1) comprising
[0061] - an input interface (2) for receiving data representative of a system technical,
[0062] - a memory (3) for storing at least the instructions of a program computer according to this document,
[0063] - a processor (4) accessing the memory (3) to read said instructions and then carry out the process according to this document,
[0064] - an output interface (5) for providing counterfactual data.
[0065] In the remainder of the description, the following notations will be used: - X ; A set of input observations. Each input observation can be, for example, a set of tables, images, or curves. - A e {0,1}: Group of input observations of X. By convention A( = 0 designates that observation i is in a potentially discriminated group, and A; = 1 designates the rest of the observations. - E; Encoder part of the contrastive autoencoder. - D; Decoder part of the contrastive autoencoder. - z: Latent representation of the data in the contrastive autoencoder. We thus have z- E{X) - The latent space output by the encoder D is subdivided into two parts, Zm and Zs. The latent variables of zm represent features extracted from X that are as independent as possible from group A. The latent variables of z? represent features extracted from X that are as dependent as possible from group A. These properties of zm and zs will be favored by the use of penalties or cost functions during learning. - We denote by cA ( z5 ) the counterfactual of zs with respect to the binary variable A. If for an observation i, A, = 0, then cA(zst ) is equal to where j is an observation such that Aj = 1. The matching between the observations of the group A = 0 and A = 1 will be done by optimal transport as described below. - x: Reconstruction of the data by the contrastive autoencoder. We thus have x=D(z)=D(E(xyy - Contrastive Autoencoder (AEC) Learning
[0066] Learning AEC differs from learning a conventional autoencoder by using penalties or cost functions that will give the latent space properties that favor the calculation of counterfactuals. This learning step is illustrated in [Fig.2].
[0067] Note that, during learning, two weights and / can be set by the user.
[0068] During a learning step, let an observation i come from a mini-batch of a training data set, then:
[0069] We first calculate z^ E( Aj. The latent variables of 7 are then separated into two groups zm and z\ We then calculate the predictions AJ
[0070] The total prediction penalty is then determined as follows:
[0071] E,D,A) = sim^ X)+^^1,,,,^ Aj)
[0072] where x X ■ ) is a common Similarity Penalty between Xj and x. (for example 11 y Ÿ112), and the other penalties lunif, lre^sî and lan?n are described below.
[0073] The gradient of lM( X^ E, D, A) with respect to the parameters of E and D is then calculated by back-propagation. The parameters of E and D are finally updated.
[0074] The purpose of the penalties on zm is to mix the latent representation of the observations in the groups A = 0 and A — 1 while promoting a general spread of the data. The purpose of the penalties on A is to independently group the latent representation of the observations in each of the groups A = 0 and A = 1, while promoting a general spread of the data. - Penalties used during learning
[0075] Let ££ ¢ ) be the Sinkhorn distance between two subgroups of the observations latent C
[0076] Based on this distance, it is possible to define three types of penalties that apply to subsets of the latent variables of the autoencoder. - The lunif penalty
[0077] The observations Ç are randomly subdivided into two sets of similar size. Then: [0°78] / ^=-5^5,,5,)
[0079] This penalty tends to disperse the data. - The langn penalty
[0080] Let çAÇ> and £A1 be the observations from C and in the groups A = 0 and A = 1, respectively.
[0081] They are randomly subdivided into two sets of similar size.
[0082] The are randomly subdivided into two sets |£A1 H of similar size.
[0083] So: [°084] Ç)
[0085] This penalty tends to independently group the data of group A — 0 together, and those of group A — 1 together. - The penalty
[0086] We call ^A0 and ^Aî the observations from C and in the groups A = 0 and A = 1, respectively.
[0087] So: [°088] lallsn = S^
[0089] This penalty tends to mix the data of group A = 0 and those of group A = 1. - Estimation of a counterfactual observation
[0090] A matching between the latent observations z' of group A = 0 and group A = 1 is performed as described below. The notation means that z^ and Z^ are different groups, and that Zy is the observation paired with z],
[0091] The different stages of this calculation are illustrated in [Fig.3].
[0092] The calculation of counterfactual observations between groups A — 0 and A = 1 is done by optimal transport on zs which is in low dimension compared to X.
[0093] The calculation of the counterfactual observation Xj to the observation X is carried out in the following manner, from the trained auto-encoder.
[0094] We determine — E^X^. The latent variables of zi are then separated into two groups z"' and z-, cA(zj) is then determined by calculation then z™ and cA(zj) are concatenated. The resulting counterfactual latent observation is noted z[. Finally, we determine X^ — D( Zi ) •
[0095] The notation — C^z^ means that 4 and Zsj are different groups, and that Zsj is the observation paired with zA The pairing is the one that minimizes Sk(zA0, ZAl)- The details of its calculation are described in the document “M. Cuturi, Sinkhorn distances: Lightspeed computation of optimal transport, Advances in neural information Processing Systems, 26, 2013.” - Application to the field of cybersecurity
[0096] In a cybersecurity context for example, consider a set of observations composed of 1^1 time series representing data flows in a ■ ^<=1, telecommunications network. Each of them has a constant number of time steps and has been labeled as either normal (A, = 0) or at risk (Aj = 1). This labeling may correspond to the output of a classifier pre-trained to detect at-risk flows. It may also have been carried out by an expert. The reasons for belonging to the normal or at-risk group are assumed to be unknown. If a classifier was used, it may be based on a model such as a neural network or random forest, for example, whose internal mechanisms are then difficult to explain if we refer to the algorithmic processing of the data. If an expert has labeled the series, he may also no longer be available to explain his choices.
[0097] The purpose of the method described above is to enable a user to be told why a specific time series is at risk. Consider the series X( as being at risk, i.e., such that Ai = 1. We assume that this series is due to a mixture of normal criteria (e.g., traffic variations due to schedules over a day) and risky criteria (e.g., sudden overactivity due to an attack). In order to understand why X{ is at risk, the contrastive autoencoder can be used to generate a counterfactual series X] which is in all respects similar to Xj on criteria not related to risk, but different from Xj on criteria related to this risk. The series Xj can then be interpreted as what Xj would have been if there were no risk. Visually comparing Xj and Xj can then allow a user to interpret the risk detection rules (which are unknown) in this specific case.
[0098] Generating counterfactual data allows the use of classic bias measurement tools from the literature on raw data and counterfactual data.
[0099] Of course, this same process can be used in other technical fields.
Claims
Claims
1. A computer-implemented method for generating counterfactual data s from real data, said real data being representative of a technical system, said method comprising the steps of: (a) training a contrastive autoencoder from real data belonging respectively to a first group or positive group, and to a second group or negative group, said autoencoder comprising an encoder capable of generating a representation of a data item in a latent space and a decoder capable of generating an output data item from said representation in the latent space, said representation in the latent space comprising at least one so-called mixing dimension or variable representing characteristics extracted from the data which are as independent as possible of the group to which said data belong, and at least one so-called separating dimension or variable,representing features extracted from the data that are as dependent as possible on the group to which said data belong, (b) creating counterfactual data representations from the representations of the real data in the latent space, obtained using the encoder of the trained contrastive autoencoder, by modifying all or part of the separating dimensions of said representations of the real data, (c) generating counterfactual data from said counterfactual data representations, using the decoder of the trained contrastive autoencoder.,
2. Method according to the preceding claim, comprising, before step (a), a prior step of measuring the real data using at least one sensor equipping the technical system.
3. Method according to one of the preceding claims, in which, during step (a), the cost function ltot used is of the type: E, D, A-)) , WHERE - Xi is an input data or observation, E is the function of the encoder, D and the function of the decoder, is a representation of a data or observation in the latent space, so that = E(Xj), the latent spacez at the output of the encoder being subdivided into two parts or two sets of dimensions, denoted respectively zm and forming respectively the mixing and separating dimensions or variables, JC j is a similarity penalty, - Xn and X are weights, Q is the Sinkhorn distance between two subgroups of the latent observations these observations C being subdivided into two sets C p C2 of similar size, cf)+sk(^ ^2 y °û and cA' are the observations from Ç and in the groups A = 0 , namely the second group or negative group, and A = 1, namely the first group or positive group, where the ^A0 are randomly subdivided into two sets {£A0. fA0} of similar size and where the £A1 are randomly subdivided into two sets {£A\ ^A1} of similar size, sk^". cA,y
4. Method according to one of the preceding claims, wherein, during step (b), the latent dimensions or variables of a representation of a data item or observation in the latent space being separated into two groups s” and 4, respectively forming the mixing and separating dimensions or variables of \ the corresponding counterfactual data representation zj is obtained by concatenation of the groups Z™ and Zsj, respectively forming the mixing and separating dimensions or variables of z, where Z™ = and where = C^zf), zj being the separating part of the latent space representing an observation j matched to i using the function (X i.e. minimizing the Sinkhorn distance between two clouds of points from the groups A = 0, namely the second group or negative group, and A = 1, namely the first group or positive group.
5. Computer program comprising instructions for implementing the method according to one of the preceding claims, when this program is executed by a processor.
6. A non-transitory computer-readable recording medium on which a program is recorded for implementing the method according to one of claims 1 to 3, when this program is executed by a processor.
7. Computer system (1) comprising - an input interface (2) for receiving data representative of a technical system, - a memory (3) for storing at least the instructions of a computer program according to claim 5, - a processor (4) accessing the memory (3) to read said instructions and then execute the method according to one of claims 1 to 4, - an output interface (5) for providing counterfactual data generated during step (c) of the method according to one of claims 1 to 4.