如何根據距離將一個表中的資料添加到另一個表中我有兩個數據表,用於晶圓上的兩組測量。每個表有四列,X、Y 代表測量位置,每個表有兩列測量資料。測量值不是從晶圓的完全相同的位置 (X,Y) 收集的。我想根據測量位置的接近程度更新(添加另一個表的額外列)任一表。更清楚地說,我想要一個基於 X1、Y1 與 X2 和 Y2 上最近點的匹配的組合表(總共 8 列)。請參閱我上傳的圖片。我知道距離函數可能可用於製作與給定 X,Y 的所有距離的矩陣,但不確定如何編寫 jsl 程式碼來為我計算更新的表。
自動化和腳本編寫資料混合與清理視窗回覆:如何根據距離將一個表格中的資料加入到另一個表格中除了距離之外,還可以查看以下功能
然後將基於行的索引添加到您的“主”表中,利用其中之一來查找最接近的索引(基本上是行),將其添加到您的第二個表中,然後最後使用update/ join 來合併表格。
回覆:如何根據距離將一個表格中的資料加入到另一個表格中基於@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
回覆:如何根據距離將一個表格中的資料加入到另一個表格中嗨,史蒂夫和賈莫,
感謝您的建議。該腳本也很有用。然而,當我跑步時,我認為它找不到最近的距離。例如,表 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 最近的行可能會方向錯誤
回覆:如何根據距離將一個表格中的資料加入到另一個表格中要取得帶有座標的矩陣,您可以使用資料表下標,就像 Jarmo 在他的範例中所做的那樣:
行 = 0 -> 所有行
列:x 和 y
coordinates as matrix = dt1[0, {"x", "y"}];回覆:如何根據距離將一個表格中的資料加入到另一個表格中VPTree的文件可以優化。
KD表:

KDTable << K 最近行有兩種模式:
- 預設:以輸入位置為起點。
-> 不適合我們。
- 可選:使用單一位置作為起點。
-> 是的!
我將每一行的這一點計算為pos = Matrix ({:x,:y})並將其作為K 個最近行的第二個參數提供
傳回值是行和距離的向量。使用[1][1] ,我可以先取得rows ,然後取得第一個(也是唯一的)條目。
不幸的是,沒有任何模式可以提供一組起點作為輸入。
VP樹:
對於K 最近行,腳本索引中沒有真正的文檔,但 VPTree 的定義中有一個範例:

線上幫助中有一些文件:


聽起來與 KDTable 的 2 個選項相同。
從@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。 VPTree 和groupBy將是合乎邏輯的下一步。
- 另一方面,使用者可能更喜歡對輸入資料進行插值以獲得更有意義的值,而不是僅使用相鄰值。 分組依據 - 非常有用!插值怎麼樣?