问题标签 [cost-based-optimizer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
284 浏览

apache-spark - spark收集特定分区的列统计信息

如何告诉 spark 只收集特定分区的列统计信息?

似乎忽略了我的过滤器:

0 投票
0 回答
790 浏览

python-3.x - 寻找最优路径

我试图找到从给定
initial_state(形式为 list[row,col,orientation])到给定目标(形式为 list[row,col])的汽车的最佳路径。

汽车可以沿方向(上、左、下、右)自由前进。

它可以执行 3 个动作,分别是:
右转前进(2)、前进(1)、左转前进(20)
注意:括号中的数字是执行相应动作所涉及的成本

转向发生在同一个单元格中。
由 0 和 1 组成的2D 列表(称为grid)作为输入(2D 非循环世界)。
0 --- 可导航单元格
1 --- 不可导航单元格

任务是从多个可能的路径中找到一条路径(成本最低)。

这是我的代码。

我在不可导航的单元格处创建了一个具有任意高值 999(高于所涉及的最大成本)的 2D 列表值。

接下来我创建一个空列表(称为 Routes),它将存储不同的路由。每条路线将采用以下形式 - [成本、路线中的单元格列表、汽车的最终方向]。在进入 while-Loop 之前,Route 被初始化为初始状态(因为它将成为任何 Route 的一部分)。

一个 for 循环检查有效邻居(邻居的有效性 - 应该在网格中,应该是可导航的)。

对于一个有效的邻居——
在 thisRoute 中创建 presentRoute 的副本。
将新的单元格坐标附加到路线中的单元格列表中。
根据执行的操作更新成本。
根据动作更新最终方向。
*最后将此新路由附加到 Routes。
(对于每个有效的邻居,一个新的路由被附加到 Routes 中)

Routes[0] 现已删除。在对路线进行排序时,列表中的第一条路线将是成本最低的路线。变量 'r' 和 'c' 用 min-cost Route 的最后一个单元格更新。

一旦 [r,c] 等于目标,我们就找到了成本最低的路线。

输出与我的信念不同。我查找此代码中的错误。

0 投票
1 回答
66 浏览

sql - 为什么相同类型的查询的查询成本如此不同?

这是我在 SQL Server 2008 中的 SQL 查询。

三个相同的查询,使用不同的方法

以下是查询费用:

在此处输入图像描述

(1)第一个查询Case和两个When条件只占查询成本的 4%

(2)无条件第二次查询Case占总查询成本的48%

(3)第三次查询Case和一个When条件也占总查询成本的 48%

为什么第二个和第三个查询占用了总查询成本这么多?

0 投票
1 回答
113 浏览

tensorflow - 如何打印成本函数?

我想问一下模型中有两个步骤时如何打印成本值。这是我的代码。

所以我想知道的是cost_SE和cost_STOI的值,我可以设置lamda来最大化模型的效率。我尝试了几种方法,但没有奏效。

上面的代码只显示了两个成本值的太阳,但我想知道的是每个成本值。它有什么解决办法吗?

0 投票
0 回答
328 浏览

apache-spark - Spark CBO 未显示查询中具有分区列的查询的行数

我正在使用基于成本的优化器(CBO)的 Spark 2.3.0 来计算在外部表上完成的查询的统计信息。

我在 spark 中创建了一个外部表:

我使用以下命令计算了列的统计信息:

现在,当我尝试获取查询的统计信息时:

它只给我 size 而不是 rowCount :

我在这里错过任何步骤吗?如何获取查询的行数。

Spark-version : 2.3.0 表中的文件为 parquet 格式。

更新 我能够获取 csv 文件的统计信息。无法为镶木地板文件获得相同的结果。

parquet 和 csv 的执行计划之间的区别在于格式,在 csv 中HiveTableRelation,parquet 的Relation.

知道为什么会这样吗?

0 投票
1 回答
100 浏览

apache-spark - Spark SQL 以不同方式读取 parquet 表和 csv 表

我在 spark-sql 中创建了两个外部表。一种文件格式为parquet,另一种文件格式为textfile.

当我们在这两个表上提取查询计划时,spark 会以不同的方式处理这两个表。

parquet 表上查询计划的输出为:

对 csv 表的查询计划的输出是:

为什么差别如此之大?火花版本:2.2.1

0 投票
1 回答
79 浏览

oracle - Oracle 中的估算器

在 Oracle 的文档中,对于优化器中的估计器,有这样的架构: https ://docs.oracle.com/database/121/TGSQL/img/GUID-22630970-B584-41C9-B104-200CEA2F4707-default.gif

通常,据我所知,计划生成器会生成计划并将这些计划连续处理给估算器,以估算其成本。但是,在此模式中,在查询转换器之后,查询直接传递给估计器。但目前还没有任何计划。

我的问题是,当查询首先从查询转换器处理到估计器时会发生什么?因为还没有计划。那么它是如何计算成本的呢?还是在第一时间没有任何成本直接传递给计划生成器?

提前致谢。

0 投票
0 回答
86 浏览

python - Python中具有数量约束的分配最低成本

我正在尝试解决分配问题:

  • 我有 350 000 个大小为 S_i 的包裹,每个包裹只能有一个状态,并且对于每个包裹我都有一组概率
  • 对于每个州,我都有数量要达到

我找到了 Vogel 近似方法,但是有 350 000 行(包裹)和 15 列(可能的状态),计算时间应该太长。

您知道可以解决此类问题的最低成本分配算法吗?

0 投票
0 回答
48 浏览

arrays - 在给定成本下最大化数组子集的总和

我有一个 n 个对象的数组,其中一个 int 'value' 和另一个 int 'cost'。我想获得该数组的大小为 k (k < n) 的子集,它使值的总和最大化。例如...

价值 - 成本

32 - 24

25 - 17

39 - 40

10 - 10

47 - 44

0 - 10

18 - 10

例如,我需要选择 5 个在保持低于某个总成本(例如 100 个)的同时实现价值最大化的产品。我不会因为成本最低而获得奖励积分,只是因为价值最高。我不希望获得最大的收益,我希望获得最大的收益,同时保持低于给定的成本。

我正在寻找的算法是否只有一个名称?我不想强迫它。

0 投票
0 回答
330 浏览

r - How do I tune a posterior probability threshold value for a binary classifier using more than one performance measure with the mlr package in R?

The following link provided me with a greater understanding of incorporating ordinary cost in my binary classification model: https://mlr.mlr-org.com/articles/tutorial/cost_sensitive_classif.html

With a standard classifier, the default threshold is usually 0.5, and the aim is to minimize the total number of misclassification errors as much as possible (obtain the maximum accuracy). However, all misclassification errors are treated equally. This is not typically the case in a real-world setting since the cost of a false negative may be much greater than that of a false negative.

Using empirical thresholding, I was able to obtain the optimal threshold value for classifying the instance into good or bad while minimizing the average cost. On the other hand, this comes at the price of reducing the accuracy and other performance measures. This is illustrated in the following figure:

In the figure above, the red line denotes the standard threshold of 0.5 which maximizes accuracy but gives a sub-optimal average credit cost. The blue line denotes the desired threshold that minimizes the cost, but now the accuracy is drastically reduced.

Generally, I would not be concerned about the reduced accuracy. Suppose however there is also an incentive to not only minimize the cost but also to maximize the precision as well. Note that the precision is the positive predictive value or ppv = TP/(TP+FP)). Then the green line might be a good trade-off that gives a relatively low cost and a relatively high ppv. Here, I plotted the green line as the average of the red and blue lines (both credit cost and ppv functions seem to have about the same gradient between these regions so calculating the optimal threshold this way probably provides a good estimate), but is there a way to calculate this threshold exactly?

My thoughts are to create a new performance measure as a function of both the costs and the ppv, and then minimize this performance measure. Example: measure = credit.costs*(-ppv)

But I'm not sure how to code this in R. Any advice on what should be done would be greatly appreciated.

My R code is as follows:

Finally, I'm also a bit confused that about my ppv value. When I observe my confusion matrix, I am calculating my ppv as 442/(442+289) = 0.6046512 but the reported value is slightly different (0.6053531). Is there something wrong with my calculation?