• No se han encontrado resultados

Supuesta vulneración al principio de legalidad en materia penal

Año 1. Servicio de publicidad

7. Supuesta vulneración al principio de legalidad en materia penal

As introduced in section 3.2.1, the PCM uses so called stochastic expressions to charac- terise random variables. This section describes how the simulation deals with stochastic

expressions as this is used in all other parts of the simulation.

Basically, at any location where stochastic expressions are used in the PCM, the simu- lation transformation simply copies the stochastic expression’s string representation into the generated code and leaves it to SimuCom’s platform to parse and evaluate the expres- sions. As an enhancement, the simulation’s transformation can be improved in future work to generate code which represents the stochastic expressions semantics directly and hence, makes the additional parsing superfluous. However, the basic concepts stay the same.

In the current implementation, the SimuCom platform generates the stochastic ex- pression’s abstract syntax tree and uses a visitor to evaluate the expression thus acting the same as an interpreter. The following differentiates five basic classes of nodes where nodes of the same class are realised similar. The five classes are: Literals, probability function literals, functions, operators, and variable nodes. For each class the following paragraphs introduce how the visitor evaluates the respective nodes.

Literals Literals are the most basic type of node and their evaluation is easy as the value

of the node is simply the literal’s value. For example, the value of the stochastic expres- sion ”5” is simply 5.

Probability Function Literals Probability function literals are used to characterise ran-

dom variables, i.e., their value is determined by drawing samples in the simulation. The simulation uses the so called inversion method to evaluate probability function literals

(Law and Kelton,2000). The basic idea of this method is to derive the inverse function of

the cumulative distribution function of the probability function literal F−1(p) : [0..1] → D

which maps probabilities to values of the sample space D. D depends on the type of the random variable, e.g., BYTESIZE characterisations yield Integers while STRUCTURE characterisations yield enumeration types. A uniform distributed random variable is gen- erated by a pseudo-random number generator u ∼ U(0, 1) and X = min{x|F (x) ≥ u} is returned as result. It can be shown, that X’s distribution follows the given probability function literal (Law and Kelton,2000).

The evaluation differentiates two cases: Discrete and continuous probability function literals. For discrete random variables, F−1is a stepwise function which can be computed

efficiently by comparing the drawn uniform value u to the upper limits of the steps. For BoxedPDFs, which approximate continuous random variables in the PCM, F−1 is

defined in intervals, where each interval represents a box. As the PCM assumes a uniform distribution inside each box, the inverse of each section is a linear function. This allows efficient calculation of random samples of BoxedPDFs.

For example, consider a probability function literal DoublePDF[(4;0.3)(8;0.7)]. This specification defines a continuous random variable whose values fall in the interval [0..4) with probability 0.3 and in the interval [4..8) with probability 0.7. The cumulative distribution function is F (x) = x ∗ 0.3/4 for x ∈ [0, 4) and F (x) = 0.3 + (x − 4) ∗ 0.7/4 for x ∈ [4, 8). The inverse cumulative distribution function F−1(y) is F−1(y) = y ∗ 4/0.3for

y ∈ [0, 0.3)and F−1(y) = (y − 0.3) ∗ 4/0.7 + 4for y ∈ [0.3, 1).

Functions The SimuCom platform is able to deal with a set of standard functions devel-

opers can use in stochastic expressions. Currently, the SimuCom platform supports two types of functions; mathematical functions and random number generators for standard distributions. A visitor evaluates mathematical functions, like Truncate or Round, by applying the respective Java methods to the function’s parameters. For random number generators, like Norm for normal distributed samples or Exp for exponential distributed samples it uses the SSJ Java library (L’Ecuyer and Buist, 2005). The result of visiting the stochastic expression’s AST nodes corresponds to the result of the respective SSJ function (see (L’Ecuyer and Buist,2005) for details).

Operators For operators, such as +,-,*,/,<,>,==, etc., the visitor again uses the

standard operators provided by Java. Their precedence order is respected when con- structing the stochastic expression’s AST. As random variable evaluation is always based on drawing samples of the random variable, the results of visiting stochastic expression AST nodes are always primitive values, which can be used in operations directly.

Variables In stochastic expressions, variables are used to express parameterisations of

random variables. They allow to characterise the usage profile in a parametric way (cf. section3.5.1). From the viewpoint of simulating PCM instances, variables normally (i.e., besides INNER variables) contain a sample of a random variable because when the vari- able is first used, the stochastic expression defining the variable is evaluated and the re- sulting sample is stored in the variable. The case-based analysis performed in the simu- lation leads to the use of samples for all random variables.

The simulation uses a process oriented view for users, i.e., users and their requests are simulated using threads. This lets a simulation run look similar to the execution of the real application (however, based on abstract models instead of real application logic). Because of this, an adjusted variant of the concept how variables are organised in real programs can be used to realise variables in SimuCom.

When a compiler generates code for a program, it uses stack frames to implement variable scopes in the program (Muchnick, 1997). A scope is a range in the program in

which a certain variable can be accessed. For example, a method is a scope for method lo- cal variables, a loop declaration forms a scope for the loop’s body, etc. Whenever a scope is entered by the control flow, a new stack frame is put on the stack. Such a stack frame can optionally have a parent frame depending on whether variables of the surrounding scope should be visible. The semantics of a stack frame when looking for the value of a variable is to first look in the topmost stack frame. If the variable is contained in this frame its value is returned. If not, the parent frame is searched for the variable and so on. The SimuCom platform uses this concept for managing variables in stochastic expres- sions. Each simulated thread representing a simulated user or one of its requests has a simulated stack on which stack frames can be pushed or popped. When pushing a new stack frame to the stack, the simulated thread additionally has to specify whether the stack frame currently on the top of the stack becomes a parent stack frame or not. When looking for a variable, the semantics as described above is applied: If the variable is in the topmost frame its value is returned, if not, the parent stack frame is queried, and so on. If none of the searched stack frames contains the variable, an exception is raised. By this, the parent relationship defines the scope of the search for variables. It is important for different types of scopes: When executing a call to another component a new stack frame is pushed on the stack without a parent frame. This prevents the access to variables defined in the stack frame of the calling service.

param1.BYTESIZE 25 kB param2.VALUE 5 param3.NUMBER_OF_ELEMENTS 100 param4.BYTESIZE 300 Byte Stackframe 1 Stackframe 2 Stackframe 3 p a re n t ... ...

Figure 4.9: An example for a Simulated Stack

For example, consider the simulated stack in figure 4.9 (Notice, that the stacks in this section grow downwards as usual in compiler construction literature). The stack’s topmost frame is stack frame 1. It contains two variables, param1.BYTESIZE and param2.VALUE. Its parent stack frame is stack frame 2 which contains param3.NUMBER OF ELEMENTS and has no parent frame. On top of stack frame 2 is stack frame 3 which contains the variable param4.BYTESIZE. However, this stack frame is currently unavailable. It becomes available again if stack frame 1 and stack frame 2 get popped from the stack.

In this context, the stochastic expression ”param1.BYTESIZE” evaluates to 25 kilo- byte. The expression ”param3.NUMBER OF ELEMENTS” is also allowed as it is contained in the parent stackframe and results in 100. The expression ”param4.BYTESIZE” is not allowed in this context and would lead to an exception if evaluated against this simu- lated stack as it can not be reached when following the parent stack frame relationship. Finally, to give an example of a more complex stochastic expression ”param1.BYTESIZE * param3.NUMBER OF ELEMENTS” evaluates to 2500 kilobytes. The latter expression could be an example for a random variable specifying a parametric resource demand for an InternalAction.

Late Evaluation Some variables need a so called late evaluation. This means, their value

is not determined when they are initially added to their stack frame but later because the evaluation of these variables may result in different samples of their underlying random variable on every access to their value. An example of such a variable is the INNER char- acterisation of collections (cf. section3.5.4). This characterisation describes the elements contained in a collection. For them, it is assumed that every time when they are used, a different element of the collection is used (cf. Koziolek(2008)). Consequently, the value of the variable is re-evaluated on every access.

For variables with late evaluation, the simulated stack frame contains a so called eval- uation proxy. This proxy encapsulates all information needed to re-evaluate the variable. This is the defining stochastic expression and a copy of the state of the topmost stack frame and its parents.

param1.BYTESIZE 25 kB

param2.VALUE 5

param3.INNER.BYTESIZE Proxy(IntPMF[(1;0.5)(2;0.5)]* param1.BYTESIZE)

param1.BYTESIZE 5 kB

Stackcopy Current Stack

Figure 4.10: Stackframe with Proxy for Late Evaluation

Consider the (artificial) example given in figure 4.10. In this example, the current stack frame contains the variables param3.INNER.BYTESIZE and param1.BYTESIZE where param3.INNER.BYTESIZE is a late evaluating variable. According to the intro- duced semantics, the stochastic expression ”param3.INNER.BYTESIZE” evaluates to 25 kByte with a probability of 0.5 and to 50 kByte with a probability of 0.5. Notice, that every evaluation of this stochastic expression can result in a new result with the given

probability distribution.

The sections on mapping user (section4.4.4) and component behaviour (section4.4.6) contain the initialisation and use of the simulated stack and its stack frames. Before pre- senting them, simulated resources are introduced as foundation of the SimuCom plat- form.