[SER222] Empirical Analysis (1/8): The Empirical Process

Ruben Acuna
25 Aug 201709:05

Summary

TLDREste video ofrece una visión general del proceso para construir empíricamente la función de crecimiento de un algoritmo. Se explican los pasos clave: establecer una serie de pruebas con diferentes entradas, medir el tiempo de ejecución, realizar un análisis de regresión para construir un modelo matemático y, finalmente, validar la precisión del modelo con nuevos datos. Se destacan las ventajas y desventajas de este enfoque, incluyendo su independencia de la implementación y la rapidez del proceso, pero también su inexactitud y dependencia del entorno de evaluación.

Takeaways

  • 🔍 La meta es analizar un algoritmo como un 'caja negra' observando su comportamiento con diferentes entradas.
  • 📊 Para construir una función de crecimiento empírica, se requiere de un conjunto de pruebas con diferentes entradas y sus tamaños asociados.
  • ⏱ Se debe medir el tiempo que toma el algoritmo para procesar cada entrada y crear un mapa de tamaño de problema a tiempo de ejecución.
  • 📈 Se utiliza análisis de regresión para construir un modelo que relacione el tamaño de entrada con el tiempo de ejecución.
  • 🔍 Se busca un modelo empírico que sea una aproximación de la función de crecimiento del algoritmo.
  • 🔄 Es necesario validar el modelo con entradas de tamaño no utilizados en la creación del modelo para asegurar su precisión.
  • 🔄 Si el modelo no es preciso, se debe regresar a la fase de benchmarking y ajustar el conjunto de pruebas.
  • 🌐 La ventaja del enfoque empírico es que no se requiere el código fuente del algoritmo, lo cual es útil para bibliotecas de terceros.
  • ⏱ Este método es más rápido que el análisis analítico, ya que no se examina cada línea de código.
  • ⚠️ Los desafíos incluyen la inexactitud inherente al modelo, la posibilidad de no capturar casos extremos y la dependencia del entorno de evaluación.
  • 🔄 El proceso iterativo de prueba, modelado y validación es similar al método científico de hipótesis y verificación.

Q & A

  • ¿Cuál es el objetivo principal de analizar un algoritmo como si fuera una caja negra?

    -El objetivo principal es observar cómo actúa el algoritmo con diferentes entradas para modelar o predecir su comportamiento en función del tamaño de las entradas.

  • ¿Qué significa el enfoque empírico para el análisis de un algoritmo?

    -El enfoque empírico implica realizar pruebas observacionales para modelar el comportamiento del algoritmo basándose en los datos obtenidos, sin necesidad de analizar el código fuente.

  • ¿Cómo se inicia el proceso de análisis empírico de un algoritmo?

    -Se inicia definiendo un conjunto de entradas diferentes, ejecutando el algoritmo con esas entradas y midiendo el tiempo que toma cada ejecución.

  • ¿Por qué es importante asociar un tamaño de entrada a cada prueba realizada?

    -Es necesario para crear un mapa del tamaño de la entrada al tiempo de ejecución, lo cual es esencial para construir una función de crecimiento empírica.

  • ¿Qué es la análisis de regresión y cómo se relaciona con el análisis de un algoritmo?

    -El análisis de regresión es una técnica estadística utilizada para construir un modelo que predice el tiempo de ejecución del algoritmo a partir del tamaño de la entrada.

  • ¿Qué es una función de crecimiento empírica y cómo se obtiene?

    -Una función de crecimiento empírica es un modelo matemático aproximado que relaciona el tamaño de la entrada con el tiempo de ejecución del algoritmo, obtenida a partir de los datos de pruebas.

  • ¿Por qué es necesario probar el modelo con un tamaño de entrada que no se haya utilizado en la creación del modelo?

    -Es necesario para evaluar la precisión del modelo y asegurarse de que pueda predecir adecuadamente el tiempo de ejecución para nuevos tamaños de entrada.

  • ¿Cuáles son las ventajas de utilizar el enfoque empírico para analizar un algoritmo?

    -Las ventajas incluyen no necesitar el código fuente, ser más rápido que el análisis analítico y ser útil para bibliotecas de terceros sin acceso al código fuente.

  • ¿Cuáles son las desventajas del enfoque empírico en el análisis de algoritmos?

    -Las desventajas incluyen la imprecisión de las predicciones, la dependencia del entorno de evaluación y la posibilidad de no capturar todos los comportamientos del algoritmo debido a casos extremos no probados.

  • ¿Cómo se relaciona el proceso de análisis empírico con el método científico?

    -El proceso de análisis empírico sigue el método científico al hacer predicciones basadas en pruebas, evaluar esas predicciones y actualizar el modelo en base a los resultados.

  • ¿Qué sucede si el modelo no es capaz de predecir adecuadamente el tiempo de ejecución para una nueva entrada?

    -Si el modelo no predice adecuadamente, se debe volver a la fase de benchmarking para incluir más entradas en el conjunto de pruebas y construir un nuevo modelo.

Outlines

00:00

🔍 Análisis empírico del crecimiento de un algoritmo

El video ofrece una visión general del proceso para construir de manera empírica la función de crecimiento de un algoritmo. Se destacan cuatro pasos principales para analizar un algoritmo como si fuera un cuadro negro, observando su comportamiento con diferentes entradas. Se menciona la necesidad de realizar un conjunto de pruebas para diferentes tamaños de entrada y calcular el tiempo que toma el algoritmo para ejecutarse. A partir de estos datos, se realiza un análisis de regresión para construir un modelo que relacione el tamaño de la entrada con el tiempo de ejecución. Finalmente, se sugiere probar el modelo con nuevos tamaños de entrada para evaluar su precisión y, si es necesario, ajustar el modelo con más pruebas.

05:02

🔧 Ventajas y desventajas del análisis empírico

El video también discute las ventajas y desventajas del enfoque empírico. Entre las ventajas, se destaca la independencia de la implementación y la rapidez del proceso, lo cual es especialmente útil para bibliotecas de terceros que no proporcionan el código fuente. Sin embargo, los desafíos incluyen la imprecisión inherente al enfoque empírico, ya que siempre hay un margen de error en las predicciones. Además, existe la posibilidad de que ciertos casos extremos no sean capturados por el conjunto de pruebas y, por lo tanto, no se tomen en cuenta al construir el modelo. También se señala que los resultados pueden variar según el entorno de evaluación, aunque los patrones generales, como la relación N o N cuadrado, son consistentes entre diferentes computadoras.

Mindmap

Keywords

💡Algoritmo

Un algoritmo es una serie de instrucciones claras y ordenadas que se utilizan para resolver un problema o ejecutar una tarea. En el vídeo, el algoritmo es el objeto de estudio, donde se busca entender cómo se comporta al aplicarle diferentes entradas, sin necesidad de conocer los detalles de su implementación.

💡Función de crecimiento

La función de crecimiento de un algoritmo describe cómo el tiempo de ejecución o la cantidad de recursos necesarios crece a medida que aumenta la entrada. En el vídeo, esta función es el objetivo principal de estudio, ya que se busca modelar cómo se comporta el algoritmo en función del tamaño de la entrada.

💡Enfoque empírico

El enfoque empírico es una técnica de análisis donde se observa y se mide el comportamiento de un algoritmo sin analizar su código fuente. En el vídeo, este método se utiliza para construir una función de crecimiento basada en la observación de cómo el algoritmo maneja diferentes entradas.

💡Benchmarking

Benchmarking es el proceso de evaluar el rendimiento de un sistema a través de pruebas estándar. En el contexto del vídeo, se utiliza para medir el tiempo que toma un algoritmo para procesar diferentes conjuntos de entradas, proporcionando datos para construir la función de crecimiento.

💡Entrada

La entrada es la información que se proporciona a un programa o algoritmo para su procesamiento. En el vídeo, las entradas son usadas para evaluar el comportamiento del algoritmo y para generar datos que se utilizan en el análisis empírico.

💡Tamaño de la entrada

El tamaño de la entrada hace referencia a la cantidad o complejidad de la información que se introduce en un algoritmo. Es un factor clave en el análisis de funciones de crecimiento, ya que se relaciona directamente con el tiempo de ejecución y la cantidad de recursos utilizados, como se discute en el vídeo.

💡Regresión

La regresión es una técnica estadística utilizada para modelar la relación entre una variable dependiente y una o más variables independientes. En el vídeo, se menciona el uso de regresión para construir un modelo que relacione el tamaño de la entrada con el tiempo de ejecución del algoritmo.

💡Modelo

Un modelo es una representación simplificada de una situación real que se utiliza para entender o predecir comportamientos. En el vídeo, el modelo se refiere a la función de crecimiento que se construye a partir de los datos de benchmarking y que se usa para predecir el comportamiento del algoritmo.

💡Predicción

Una predicción es una estimación o proyección basada en información disponible. En el vídeo, las predicciones se hacen usando el modelo de crecimiento empírico para estimar el tiempo de ejecución del algoritmo para entradas de tamaño no testeadas.

💡Validación

La validación es el proceso de confirmar la precisión y la fiabilidad de un modelo o hipótesis. En el vídeo, la validación implica comparar los tiempos de ejecución predichos por el modelo con los tiempos reales medidos para entradas no testeadas, para asegurar que el modelo es preciso.

💡Método científico

El método científico es un enfoque para investigar y comprender el mundo natural a través de la observación y la experimentación. En el vídeo, el proceso de análisis empírico del algoritmo se compara con el método científico, ya que implica hacer predicciones, testear hipótesis y actualizar el modelo basado en los resultados.

Highlights

Empirical approach to constructing an algorithm's growth function

Four main steps for empirical analysis of an algorithm

Analyzing algorithms as a black box to observe behavior with different inputs

Benchmarking an algorithm with a set of different inputs

Importance of associating input size with each test

Timing the algorithm's execution for each input size

Using regression analysis to build a model of the algorithm's runtime

Creating an empirical growth function from the model

The necessity of testing the model with new, unseen input sizes

Evaluating the model's prediction against actual runtime

Iterating the process to improve model accuracy

Advantages of the empirical approach over analytical methods

Disadvantages such as in-exact predictions and dependence on the evaluation environment

The empirical process resembling the scientific method

How the empirical approach can be applied to benchmark a sample program

The impact of different hardware on the empirical results

The generalizability of variables in empirical growth functions across different computers

Transcripts

play00:05

- In this video, I'm going to give an overview

play00:06

of the process for constructing

play00:08

an algorithm's growth function empirically.

play00:11

So, on the left here, I have four main steps,

play00:13

and we'll go through those one by one.

play00:15

As kind of a reminder, our goal is the following.

play00:18

We're in the section, right, talking

play00:19

about different ways to analyze an algorithm

play00:21

and one way you can have, right, instead

play00:23

of looking at every single line of code

play00:24

in a program is to actually take a look at that algorithm

play00:28

out of that program in terms of a black box.

play00:30

Basically, you just observe how it acts

play00:32

when put in different inputs.

play00:33

From that, we can basically try to model, right,

play00:35

or guess, how that algorithm will act, right,

play00:38

when I give it different size inputs

play00:39

or I can do it purely based on observation

play00:41

and that's what called the Empirical Approach.

play00:43

So how do I do that?

play00:44

Well, let's assume for a moment

play00:46

that we already have an algorithm

play00:47

or a method, let's say I'll be listing a method

play00:49

that I want to analyze, right,

play00:51

I wanna find out it's growth function.

play00:54

First thing I need to do is I need to benchmark it.

play00:56

So what I'll do is I'll come up

play00:58

with an entire set of different inputs, right,

play01:00

and sometimes, right, maybe you run it

play01:02

on two different inputs, sometimes you run it

play01:03

on a hundred different inputs.

play01:04

Whatever you think is appropriate

play01:06

for determining how the thing grows, right, how that thing,

play01:10

how much time or how much work it takes

play01:12

for that algorithm to run or that method to run.

play01:14

All right, so if it's something really simple,

play01:15

maybe you can get away with just a few inputs,

play01:17

but if you're looking at a thousand lines of code

play01:18

and their's all sorts of different variations

play01:20

of the inputs you could probably put into that thing,

play01:22

well, then that means you just have a bunch

play01:23

of different tests for it, right,

play01:24

and so all this little suite here,

play01:27

basically you have a suite of tests, right?

play01:28

Maybe, so let's say you have a dozen

play01:29

just for sake of argument.

play01:31

Take all those different possible inputs,

play01:33

they all should have associated

play01:34

with them an input size, right?

play01:35

So there's always the size N, right,

play01:37

am I gonna test my certain algorithm

play01:38

I'll assume it has a hundred elements in it.

play01:40

Of course then it has one element in it,

play01:42

ten elements in it, whatever, right?

play01:43

Every single one of my tests has

play01:44

to have a problem size associated with it.

play01:47

The reason, is that, at the end of the day, we want a map

play01:49

from problem size to how long it takes to run.

play01:52

All right, so we have all our different inputs.

play01:54

Feed them all into the method one by one,

play01:56

and time how long it takes, right?

play01:58

So all of a sudden we have is these parings,

play02:00

is they say, "okay, for this size input,

play02:02

this is how long it took, for this size input,

play02:03

this is how long it took" and so on and so forth.

play02:06

Given that we have all those different pairs of data,

play02:08

what we can next think about doing is some sort

play02:10

of regression analysis, right?

play02:11

We can build a model that somehow calculates the run time,

play02:16

from the size of the input, right?

play02:18

So we can picture, go back to basic algebra,

play02:20

you have maybe a graph, right,

play02:22

and you have your scatter plot of the different pairs

play02:24

of how long something took to run based

play02:26

on what its input size is, and we have that, right,

play02:29

and we could think about doing something like a regression,

play02:31

and it usually won't be that simple, but, you know,

play02:32

for sake of argument, we could say it's a regression,

play02:34

right, and you found, you know,

play02:35

a linear function for a quadratic function.

play02:37

Whatever it is, right, we can discover that for that input

play02:39

and so what that gives us is a potential mathematical model

play02:43

that relates the size of the input

play02:45

to how long it takes to run.

play02:47

Basically what we have is an empirical growth function.

play02:50

Keep it mind that it will be an approximate.

play02:53

Now, at that point, we're not done

play02:54

and it might seem that we are,

play02:55

because we have a growth function for us,

play02:57

but that's not really good enough for us.

play03:00

What we wanna do is the following.

play03:01

What we wanna do is you wanna pick a problem size,

play03:03

that's not in one of our input tests, right?

play03:06

Not something we use to create the model,

play03:08

we wanna pick something new.

play03:09

So if we use sizes a hundred, ten,

play03:10

I want to check how well my sort algorithm works,

play03:13

or maybe I'll try something else, like two hundred,

play03:15

I don't know.

play03:16

It can just be something that's outside of the input set,

play03:18

and we want to take that input size, feed it

play03:20

to our mathematical model, right,

play03:21

our approximate growth function, and figure out how long

play03:25

that growth function thinks our algorithm will run for

play03:27

or our method will run for, right?

play03:29

So we have basically a prediction being made from our model.

play03:31

Then we can evaluate that prediction, right?

play03:33

We can go to our basic code, and we can feed it

play03:35

this new test input or the new size, right?

play03:37

Size two hundred, or whatever,

play03:39

and then see how closely the run time

play03:42

that it actually gives us in practice is to the input,

play03:45

well, is to the result that was calculated

play03:47

by our potential growth function, right?

play03:48

What we wanna do is you wanna check

play03:50

that our model is accurate, right,

play03:52

or we wanna basically assess the accuracy

play03:54

of our model, right?

play03:55

If our model is not able to predict

play03:58

how long it takes for this new input to run,

play04:00

well then it's worthless, right?

play04:01

We want a model that, when I give it an input size,

play04:03

has a decent shot at computing

play04:05

for me how long that method will take.

play04:08

Now, if I run into a situation where,

play04:10

maybe I get a good result, right,

play04:11

it looks pretty close, I'm not done yet.

play04:13

Probably, I'm gonna check in on a couple more results,

play04:15

maybe I check on three hundred,

play04:16

maybe I take on five, now if those also look good,

play04:19

well, then I'm good to go, right?

play04:20

That first function that I got from my regression,

play04:24

that first model, right, that I got

play04:25

from my regression stuff is good to go.

play04:27

I can use that.

play04:28

Otherwise, what I have to think about is, "Oh, hey,

play04:31

this, you know, maybe there's something not being captured

play04:34

by the set of input I have to that regression test."

play04:37

So I'm gonna return to my benchmarking faze, right?

play04:39

Maybe come up with a different, a couple more inputs,

play04:41

right, that have different sizes, feed that to that,

play04:45

you know, that method that benchmark,

play04:46

figure how long it takes to run,

play04:48

and then, right, build a new model

play04:50

that's now inclusive of that data.

play04:51

Right, so I've basically updated my tests,

play04:53

say, I get a new model, now I can repeat the process, right?

play04:56

So then I make a new prediction

play04:57

from my new model, and then I check that prediction again,

play04:59

see what the method actually does, right, and I'll need

play05:02

to repeat this until my model is accurately

play05:04

predicting my sample inputs to it, right?

play05:08

Once I have that, then I'm pretty sure

play05:10

that I have a decent level of accuracy.

play05:12

I mean, there will always be the case

play05:13

that there was something that's not really captured

play05:15

in our inputs sets, but that's basically just one

play05:18

of the risks we run with doing this.

play05:21

Now I'm gonna talk about advantages,

play05:22

disadvantages in a second, but just to draw your attention

play05:24

to this little note in the right-hand side,

play05:26

there's a note that says "seem familiar?"

play05:29

Hopefully, this does seem familiar.

play05:30

Basically, what this is is the scientific method,

play05:32

right, of making predictions, of hypothesis,

play05:35

and checking them, right?

play05:36

Maybe using those to update our views,

play05:39

our understanding of the situation,

play05:40

making a new prediction, right, a new hypothesis.

play05:43

So this is very much a scientific approach in my opinion.

play05:46

So let's talk a little more of the advantages

play05:47

and disadvantages of doing analysis this way.

play05:50

So, advantages.

play05:51

First big thing, right, is that we don't really have

play05:53

to worry about the implementation.

play05:55

In fact, I don't even need the code

play05:56

for that function because I don't care.

play05:58

All I care about is that I can invoke

play06:00

that function or that method, right,

play06:01

because I need to give it some input,

play06:02

time how long it takes, right, and then, you know,

play06:04

make a note of that somewhere,

play06:05

but what happens inside is none of my business.

play06:07

I don't need to worry about the different operations

play06:08

that are in there; I don't need to have the source code.

play06:10

So this is great for something like a third party library.

play06:13

Third party library typically don't give you source code,

play06:15

so, well, you can still benchmark it, right?

play06:16

In that case, right, the analytical approach,

play06:18

looking line by line, doesn't even apply,

play06:20

because we don't have the original code.

play06:21

Here, if we're just doing it as a black box,

play06:23

well, then, we're good to go, right?

play06:24

We can take a look of their function

play06:25

that they gave us in the library,

play06:27

run a DLL, run it, see how long it takes.

play06:29

No problem for us.

play06:32

It's fast, right, this is another advantage.

play06:34

We already said there was issues in analytical

play06:35

where we have to look at every line, it just takes forever.

play06:37

Here maybe you can hope to do this in an hour, right?

play06:40

It's mostly plug-and-chug, as long as you can

play06:43

have a good way of coming up with your test sets,

play06:44

right, and then collect your data,

play06:46

I mean, regression is really easy.

play06:48

So it's generally a much faster process

play06:49

than doing it the analytical way.

play06:51

So, disadvantages, some of these,

play06:53

right, are a little bit related.

play06:55

First of the disadvantages is in-exact, right?

play06:57

So there's always going to be some margin

play06:59

of error in our prediction.

play07:00

So, even if my model, right, is generally matching,

play07:04

you know, what I expected to give,

play07:06

right, when I do an arbitrary test, you know,

play07:07

the model can correctly predict the run time

play07:10

or how long it takes, right, to run

play07:11

on that particular input.

play07:13

There will always be, right, some sort

play07:14

of little margin of error.

play07:15

Just because you don't really know what's happening, right?

play07:17

There could always be, you know, some little if branch

play07:19

that just gets run, you know, one in a thousand times,

play07:22

you don't really know that and so there will always be

play07:23

these little fluctuations in your data

play07:27

and in your predictions, and that's kind of,

play07:28

really, the second bullet point there

play07:29

which is the black box, right?

play07:31

There's always the chance that there is some code

play07:32

in my function that maybe takes a lot more time

play07:34

than what, you know, how long it typically takes,

play07:36

right, and in my test cases I'm just not seeing it

play07:39

for whatever reason, right?

play07:39

There's some sort of edge case, you know,

play07:40

that changes how this thing acts.

play07:42

Well, with an empirical approach,

play07:44

if there's something that's not seen by that test suite,

play07:46

well, then it's not going to be taken into account

play07:48

when we create our model, right, using regression.

play07:51

So we just have this chance, right,

play07:52

that all of a sudden the function is completely different

play07:54

than what we expect just because

play07:55

we are taking a black box approach

play07:56

and we can't guarantee that we've looked

play07:58

at all the different ways it can behave.

play08:01

Last note here is that it depends on evaluation environment.

play08:03

So if we're writing a function, or if we're trying

play08:05

to determine the growth function, right,

play08:07

in terms of time, right, it's very exact hopefully,

play08:09

well, it's gonna be approximate

play08:11

but maybe it can give us at least down to the second,

play08:12

right, maybe millisecond's off

play08:13

but second's fine, how long something takes,

play08:16

well, there's the issue in that

play08:17

whatever results we get will be specific to the computer

play08:19

that we did the tests on, right?

play08:20

So, if I have different hardware,

play08:21

it's gonna take a different amount of time, right?

play08:23

Obviously.

play08:24

I have different programs running in the background,

play08:25

well, then it's gonna take a different amount of time.

play08:27

There are a thousand factors that influence

play08:28

how long it takes your program or your method to run.

play08:31

So these results we get really only apply

play08:33

to the machine that we run then on.

play08:36

That said, what will generalize is somehow,

play08:39

like the variables in there.

play08:41

So, the part that tends to vary is somehow the constants

play08:44

and the expression recover, maybe are not so useful

play08:47

because they are depending on the machine,

play08:48

but in there they'll be saying like,

play08:49

you know, N or N squared.

play08:50

Generally those things are depending on variables,

play08:52

those will be the same between different computers

play08:56

and so that is going to be valuable for us.

play08:58

All right, so there we have it,

play08:59

that's an overview of The Empirical Process,

play09:01

now we're going to take a look at how we're to apply

play09:02

this to benchmark a sample program.

Rate This

5.0 / 5 (0 votes)

Related Tags
Análisis AlgoritmosCrecimiento EmpíricoBenchmarkingModelos AlgebráticosProceso CientíficoProgramaciónOptimizaciónEvaluación de AlgoritmosTiempo de EjecuciónMétodos de Análisis
Do you need a summary in English?