如何根据距离将数据从一个表添加到另一个表我有两张数据表,用于对晶圆进行两组测量。每张表有四列,X、Y 代表测量位置,每张表有两列测量数据。测量结果并非从晶圆的完全相同的位置 (X,Y) 收集。我想根据测量位置的接近度来更新(添加另一个表的额外列)任一表。更清楚一点,我想有一个组合表(共 8 列),基于 X1、Y1 与 X2 和 Y2 上最近点的匹配。请看我上传的图片。我知道距离函数可能可用于从给定的 X、Y 生成所有距离的矩阵,但不确定如何编写 jsl 代码来为我计算更新后的表格。
自动化和脚本数据混合和清理视窗回复:如何根据距离将数据从一个表添加到另一个表除了距离之外,还请查看以下函数
然后将基于行的索引添加到您的“主”表中,利用其中一个找到最接近的索引(基本上是行),将其添加到您的第二个表中,然后最后使用更新/连接来合并表。
回复:如何根据距离将数据从一个表添加到另一个表根据@jthi链接我相信这会满足你的要求
dt1=New Table( "Table 1",
Add Rows( 20 ),
New Column( "x",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Random Normal() )
),
New Column( "y",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Random Normal() )
),
Set Row States( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] )
);
dt2=New Table( "Table 2",
Add Rows( 20 ),
New Column( "x",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Random Normal() ),
Set Display Width( 120 )
),
New Column( "y",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Random Normal() ),
Set Selected,
Set Display Width( 118 )
),
Set Row States( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] )
);
M1 = dt1 << GetAsMatrix();
MD1=vptree(M1);
M2 = dt2 << GetAsMatrix();
MD2=kdtable(M2);
//returns the nearest point of Table 1 to a point in table 2
//to reverse the look up, make MD1-> MD2 and M2->M1
{rows, dist} = MD1 << K nearest rows( 1, M2);
dt1<<NEW column=""></NEW>Steve
回复:如何根据距离将数据从一个表添加到另一个表嗨,Steve,还有 Jarmo,
感谢您的建议。该脚本也很有用。但是,当我运行时,我认为它找不到最近的距离。例如,表 1 的第一行与表 2 的第 8 行(距离约为 1.37)匹配,但有许多更近的点,例如行号 1(距离为 0.69)(让距离为 sqrt[(x-x0)^2+(y-y0)^2])

回复:如何根据距离将数据从一个表添加到另一个表我认为我混淆了脚本末尾的数据表,请尝试以下操作:
dt1=New Table( "Table 1",
Add Rows( 20 ),
New Column( "x",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Random Normal() )
),
New Column( "y",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Random Normal() )
),
Set Row States( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] )
);
wait(0.0);
dt1:x << suppress eval( true );
dt1:y << suppress eval( true );
dt2=New Table( "Table 2",
Add Rows( 20 ),
New Column( "x",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Random Normal() ),
Set Display Width( 120 )
),
New Column( "y",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Random Normal() ),
Set Selected,
Set Display Width( 118 )
),
Set Row States( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] )
);
wait(0.0);
dt2:x << suppress eval( true );
dt2:y << suppress eval( true );
M1 = dt1 << GetAsMatrix();
MD1=vptree(M1);
M2 = dt2 << GetAsMatrix();
MD2=kdtable(M2);
//returns the nearest point of Table 1 to a point in table 2
//to reverse the look up, make MD1-> MD2 and M2->M1
{rows, dist} = MD1 << K nearest rows( 1, M2);
dt2<<NEW column=""></NEW>I virtual linked them and did some visual checks so I believe we are good now
<SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><span class="lia-inline-image-display-wrapper" image-alt="shampton82_0-1724013813741.png" style="width: 400px;"><img src="https://us.v-cdn.net/6038925/uploads/images/67225i8663690D9A1ED800/shampton82_0-1724013813741.png" role="button" title="shampton82_0-1724013813741.png" alt="shampton82_0-1724013813741.png" /></span></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN>
回复:如何根据距离将数据从一个表添加到另一个表I still see it is not picking up the closest points: <BR />Names Default To Here( 1 );
Close All(data tables);
Clear Log();
Clear Symbols();
dt1= Open(
"C:\Users\Table 1.jmp");
wait(0.0);
dt1:X1 << suppress eval( true );
dt1:Y1 << suppress eval( true );
dt2= Open(
"C:\Users\Table 2.jmp");
wait(0.0);
dt2:X2 << suppress eval( true );
dt2:Y2 << suppress eval( true );
M1 = dt1 << GetAsMatrix();
MD1=vptree(M1);
M2 = dt2 << GetAsMatrix();
MD2=kdtable(M2);
//returns the nearest point of Table 1 to a point in table 2
//to reverse the look up, make MD1-> MD2 and M2->M1
{rows, dist} = MD1 << K nearest rows( 1, M2);
dt1<<NEW column=""></NEW>回复:如何根据距离将数据从一个表添加到另一个表dt1=New Table( "Table 1",
Add Rows( 20 ),
New Column( "x",
Formula( Random Uniform(0,10) )
),
New Column( "y",
Formula( Random Uniform(0,10) )
)
);
dt2=New Table( "Table 2",
Add Rows( 64 ),
New Column( "x2",
Formula( floor(row()/8)+1 )
),
New Column( "y2",
Formula( mod(row(),8)+1 )
)
);
// M2 = dt2 << GetAsMatrix();
// better - see below
M2 = dt2[0, {"x2", "y2"}];
MD2=kdtable(M2);
dt1 << New Column( "row_orig",Nominal, Formula( Row() ));
dt2 << New Column( "row_2",Nominal,Formula( Row() ));
dt1 << New Column( "table",Nominal, set each value(1));
dt2 << New Column( "table",Nominal, set each value(2));
wait(0);
// step by step, for each row in dt1, use MD2 to find the closest position in dt2
dt1 << new column("row_2",Nominal, set each value(
pos = Matrix({:x, :y});
(MD2 << K nearest rows( 1, pos))[1][1]));
// concatenate the tables to generate a combined plot
dt2:x2 << set name("x");
dt2:y2 << set name("y");
check = dt1 << Concatenate(dt2);
check << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :x ), Y( :y ), Overlay( :row_2 ), Color( :table ) ),
Elements(
Line( X, Y, Row order( 1 ) ),
Points( X, Y, Overlay( 0 ), Legend( 2 ) )
),
SendToReport(
Dispatch( {}, "400", ScaleBox,
{Legend Model(
2,
Properties( 0, {Marker( "FilledSquare" )}, Item ID( "1", 1 ) ),
Properties( 1, {Marker( "Circle" )}, Item ID( "2", 1 ) )
)}
)
)
);

回复:如何根据距离将数据从一个表添加到另一个表感谢@hogi帮我清理这个!
问题是,您能告诉我这行代码的作用是什么吗?
dt1 << new column("row_2",Nominal, set each value(pos = Matrix({:x, :y});(MD2 << K nearest rows( 1, pos))[1][1]));
感谢!
回复:如何根据距离将数据从一个表添加到另一个表谢谢霍吉,
一切都进行得很顺利,然而,我和史蒂夫有同样的疑问:
你能解释一下这句话吗
dt1 << new column("row_2",Nominal, set each value(pos = Matrix({:x, :y});(MD2 << K nearest rows( 1, pos))[1][1]));此外,当我运行我的版本(读取表 1 上有四列(x、y、数据 1、数据 2)和(x2、y2、数据 3、数据 4)的表格)时,我收到以下警报。我认为这是不正常的,因为表 1 和表 2 有两列以上(x、y)不在矩阵中。但如果你解释这一行,我想我可以弄清楚剩下的部分!谢谢你的帮助

回复:如何根据距离将数据从一个表添加到另一个表嘿@spinup
我认为问题在于我的代码假设表中只有 x 和 Y 值。如果您从具有额外数字列的表开始,则 k 最近邻会尝试找到 X、Y、A、B 与 X、Y、C、D 的最近点。
我认为这就是为什么@hogi代码在只看X和Y时效果如此好的原因。
如果您制作了非 X/Y 列字符并运行我的第二个代码,它就会起作用,您只需要在加入它们后将它们更改回数字。
回复:如何根据距离将数据从一个表添加到另一个表我通常会得到这样的结果
Names Default To Here(1);
dt1 = New Table("Table 1",
Add Rows(20),
New Column("x", Numeric, "Continuous", Formula(Random Normal())),
New Column("y", Numeric, "Continuous", Formula(Random Normal()))
);
dt2 = New Table("Table 2",
Add Rows(20),
New Column("x", Numeric, "Continuous", Formula(Random Normal())),
New Column("y", Numeric, "Continuous", Formula(Random Normal())),
New Column("Val", Numeric, Continuous, Formula(Random Normal(2, 100)))
);
m1 = dt1[0, {"x", "y"}];
m2 = dt2[0, {"x", "y"}];
tree = VPTree(m2);
{rows, distances} = tree << K Nearest Rows(1, m1);
dt1 << New Column("Nearest", Numeric, Ordinal, Values(rows));
dt1 << New Column("Distance", Numeric, Ordinal, Values(distances));
dt2 << New Column("Row", Numeric, Ordinal, Values(1::N Rows(dt2)));
/* Depending on the wanted result, using Update might be better */
dt_result = dt1 << Join(
With(dt2),
By Matching Columns(:Nearest = :Row),
Drop multiples(0, 0),
Include Nonmatches(0, 0),
Preserve main table order(1),
Output Table("Result")
);
/*
Close(dt1, no save);
Close(dt2, no save);
*/
由于我没有验证结果,因此 Join/K Nearest Rows 可能执行的方向错误
回复:如何根据距离将数据从一个表添加到另一个表要获取带有坐标的矩阵,可以使用数据表下标,就像 Jarmo 在他的示例中所做的那样:
row = 0 -> 所有行
列:x 和 y
coordinates as matrix = dt1[0, {"x", "y"}];回复:如何根据距离将数据从一个表添加到另一个表VPTree的文档可以优化。
KD 表:

KDTable <有两种模式:
- 默认:以输入位置作为起点。
-> 不适合我们。
- 可选:使用单一位置作为起点。
-> 是的!
我将此点计算为每一行的pos = Matrix ({:x,:y}) ,并将其作为K 个最近行的第二个参数
返回值是行和距离的向量。使用[1][1] ,我可以先获取行,然后获取第一个(也是唯一一个)条目。
不幸的是,没有模式可以提供一组起点作为输入。
VP树:
对于K 最近行,脚本索引中没有实际文档,但在 VPTree 定义中有一个例子:

在线帮助中有一些文档:


听起来和 KDTable 相同的两个选项。
从@jthi的示例中,您可以看到 VPTree 允许第三种模式,其中一组位置以矩阵的形式提供。
这有点令人惊讶,但非常方便:)
tree = VPTree(m2);
{rows, distances} = tree << K Nearest Rows(1, m1);
dt1 << New Column("Nearest", Numeric, Ordinal, Values(rows));
回复:如何根据距离将数据从一个表添加到另一个表VPtree << K Nearest Rows(1, matrix of coordinates);
好的 : ):)
回复:如何根据距离将数据从一个表添加到另一个表进一步的想法:
- 与 1D 相关的需求: 添加模糊连接 / asof 合并 / 按不完全匹配的列连接
我刚刚添加了一条评论来考虑更高的维度。
- 在实际应用案例中,还有额外的名义坐标,如批次、晶圆、变体。用户必须相应地拆分数据并为每个“变体”设置单独的 VPTree。带有groupBy的 VPTree 将是合乎逻辑的下一步。
- 另一方面,用户可能更喜欢对输入数据进行插值,以获得更有意义的值,而不仅仅是使用邻近值。 分组 - 非常有用!!!插值怎么样?