对缓慢布尔函数的惰性求值(优化) [英] Lazy evaluation on slow boolean functions (optimization)

查看:106
本文介绍了对缓慢布尔函数的惰性求值(优化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

短路评估是对布尔表达式进行惰性评估的直接主题,我注意到两个因素可用于排序布尔函数以获得运行时。但这适用于一个特定的假设:



知道一个函数的正(因此为负)结果的百分比。以下是一个假设,后面是一个例子。

知道函数对数据的执行运行时间(知道数据的大小可以是一个暗示)

我的情况很简单要理解,这里有一个描述:



假设F是一个布尔函数,它对情绪进行评分并返回-1或1.我一直在做一些改进来预测大数据文本的情绪分数,我可以计算一个函数返回1的可能性(具有容忍误差范围的概率)让我们称之为P(f)= Pf(正数的概率)



我们还估算了执行时间,因为要分析的数据是可测量的。我们称之为T(f)= Tf我们定义正面速度如下:



Short-circuit evaluation is a straight forward subject for lazy evaluation on Boolean expressions, I noted that two factors could be useful for ordering Boolean functions to gain run-time. But this is applicable in a particular hypothesis:

Knowing a percentage of positive (hence negative) result of a function. the following is a hypothesis followed be an example.
Knowing execution run-time of the function on data (knowing size of data can be a hint)
My case is easy to understand, here is a description:

Let's say F is a Boolean function that scores sentiment and returns -1 or 1. I've been doing some improvements to predict sentiment scores on big arrays of text, and I can calculate how is likely a function will return 1 (probability withing a tolerated error range) lets call it P(f) = Pf (probability of being positive)

We have also an estimation of execution time since data to be analysed is measurable. lets call it T(f) = Tf we define positiveness speed as follows:

PS (f) =  Pf  / Tf



让Lazy成为一个带有布尔表达式的函数,并为运行时提供最佳的函数排序。




Let Lazy be a function which takes a Boolean expression, and gives the best ordering of functions for run-time.

Lazy (and, f1, f2, …, fn) = and_Order (f1, f2, …, fn)



其中 and_Order 正在以正向速度递增。




Where and_Order is ascending of positiveness speed.

Lazy (or, f1, f2, …, fn) = or_Order(f1, f2, …, fn)



如果正面速度, or_Order 正在下降。



显然这是一个高级优化,而不是编译器任务。这是一项既定的研究吗?在情绪分析之外的情况下,这是如何实用的? PS(F)是否正确表示它应该代表什么?



编辑以回应ppolymorphe答案:


Where or_Order is descending if positiveness speed.

Obviously this is a high level optimization and not a compiler task. Is this an established study? How is this practical in cases other than sentiment analysis? Is the PS(F) even correctly representing what it should be representing?

Edit in response to ppolymorphe answer:

引用:

引用:

首先,布尔值为0表示False,1表示True。在计算机中,使用0表示False而非0表示True。

First of all, Boolean values are 0 for False and 1 for True. In computers, the usage to use 0 for False and non 0 for True.



没有任何东西可以使用布尔类型来表示两种值类型。即使它不具有真理含义。在我的情况下确实如此。这是一个场景:

在一个名为创新周的活动之后,我们想看看访客是否满意于多个层面:组织,主题,建议的解决方案......


让我们说组织,主题,提议的解决方案是三个主题,最能代表人们对创新周活动的反应(情绪)。 组织和主体处于同一水平,一个足以满足另一个(逻辑OR),而两个分组在建议的解决方案(逻辑AND)处于同一水平。



可能的模型化:




There is nothing that holds usage of Boolean type for representing two values types. Even if it doesn't hold truth meaning. In my case It does. Here is a scenario:
After an event called "Innovation week", We wants to see if visitors were satisfied at many levels: "organization", "subjects", "proposed solutions"…

Let’s say that "organization", "subjects", "proposed solutions" are three topics that the most represent people's reaction (sentiment) on "Innovation week event". "Organization" and "subjects" are on the same level and one is sufficient to satisfy the other (logical OR), while both grouped are in the same level at "proposed solutions" (logical AND).

Possible modelization:

Sent ("Innovation week") = (Sent("organization") || Sent("subjects")) && Sent("proposed solutions")







引用:

短路评估是对布尔表达式进行延迟评估的直接主题,

Short-circuit evaluation is a straight forward subject for lazy evaluation on Boolean expressions,







发送的是极地情绪函数(布尔值)




Where Sent is polar sentiment function (Boolean)

Quote:

不,这是布尔表达式评估的有效说法。

No, it is the efficient say to Boolean expression evaluation.





这是真的。我没有注意。



That's True. I didn't give attention to.

引用:

你的重新排序必须更快,不幸的是,这是不可能的。

在运行时重新排序意味着在重新排序之前评估所有慢速函数,那里没有任何好处。

your reordering must be faster, unfortunately, it is impossible.
Reordering at runtime imply evaluating all your slow functions before reordering, there is no gain there.



这是真的。

但是,我将评估一个样本(比如输入大数组的1/10),因此我将接受误差范围。这就是为什么


That's True.
But, I will be evaluating a sample (say 1/10 of the input big array), therfore I will accept error range. That's why

Quote:

其中and_Order在正面速度上升。

Where and_Order is ascending on positiveness speed.



其中正面速度是概率(基于抽样)。



谢谢。



我的尝试:



这是我想到的优化,但我不确定它的可行性也不正确


Where positiveness speed is a probability (based on sampling).

Thank you.

What I have tried:

This is an optimization I thought about, but I'm not sure about it's feasibility neither it's correctness

推荐答案

Quote:

假设F是一个布尔函数,它对情绪进行评分并返回-1或1.

Let's say F is a Boolean function that scores sentiment and returns -1 or 1.



首先,布尔值对于False为0,对于True为1。在计算机中,使用0表示False,非0表示True表示。


First of all, Boolean values are 0 for False and 1 for True. In computers, the usage to use 0 for False and non 0 for True.

引用:

短路评估是一个对布尔表达式进行惰性求值的直接主题,

Short-circuit evaluation is a straight forward subject for lazy evaluation on Boolean expressions,



不,它是对布尔表达式求值的有效说法。


No, it is the efficient say to Boolean expression evaluation.

Quote:

让Lazy成为一个带有布尔表达式的函数,并为运行时提供最佳的函数排序。

Let Lazy be a function which takes a Boolean expression, and gives the best ordering of functions for run-time.



在2个布尔值之间评估逻辑运算,如需要1个CPU时钟周期。为了感兴趣,你的重新排序必须更快,不幸的是,这是不可能的。

在运行时重新排序意味着在重新排序之前评估所有慢速函数,那里没有任何收益。

唯一可能的做法是在输入源代码之前对布尔表达式进行排序。


Evaluating a logical operation like and and or between 2 Boolean values takes 1 CPU clock cycle. To be of interest, your reordering must be faster, unfortunately, it is impossible.
Reordering at runtime imply evaluating all your slow functions before reordering, there is no gain there.
The only possible thing to do is ordering your Boolean expressions before hand in source code.


这篇关于对缓慢布尔函数的惰性求值(优化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆