如何計算 JMP 11 中超過 100 億個條目的列的移動平均值?我正在嘗試在具有 1 億行的列上運行以下公式來計算移動平均值。您能否建議一個 JMP11 替代方案上校移動平均線
JMP11 不支持 Col Moving Average( :x, 1, 9999999, 0 )。</CODE></P><P><CODE class=" language-jsl">請在下面找到我嘗試過的代碼:
NamesDefaultToHere(1);
// Use a function to open a .CSV file: Given the path to such a file, returns a reference to the resulting table
openMyCSV =
function({path2File}, {Default Local},
dt = Open(
path2File,
columns(
New Column( "column 1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "items", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
dt = New Table( "My data file");
dt << New Column( "cc", Character, width( 40 ) );
dt << New Column( "MovAvgMean", Numeric );
dt << New Column( "MovAvgMax", Numeric );
// Put all the .csv files to process into a list
dir = Pick Directory(
"Directory containing your csv files",
"C:\Users\xxx\Documents\test\"
);
files = Files In Directory( dir );
For( f = N Items( files ), f >= 1, f--,
If( !Ends With( Uppercase( files[f] ), ".CSV" ),
Remove From( files, f )
)
);
// Process each file - Incomplete!
For( f = 1, f <= N Items( files ), f++,
thisTable = openMyCSV( dir || files[f] );
thisTable << New Column( "x",
Numeric,
Continuous,
Formula( (87 *:items)-(0.03998113) ));
thisTable << New Column( "av", Numeric, Continuous, Formula( Col Moving Average( :x, 1, 9999999, 0 ) ) );
// This will insure that all formula processing is complet before the next statement is run
thisTable << run formulas;
FileName = files[f];
// Add the summary statistics to the summary table
dt << Add Rows( 1 );
dt:cc[N Rows( dt )] = FileName;
dt:MovAvgMean[N Rows( dt )] = Col Mean( thisTable:x );
dt:MovAvgMax[N Rows( dt )] = Col Max( thisTable:x );
Close( thisTable, nosave );
);
9
回复:如何計算 JMP 11 中具有 1 億個條目的列的移動平均值?@jojmp ,
鑑於您的原始腳本甚至沒有保存您的表格並且您引用了一個從未創建的列,並且考慮到大量值的平均值通過刪除一行並添加另一行而發生非常小的變化,您的問題非常奇怪的。
下面是一個腳本,它創建一個包含 nr 行的表,而不是讀取 nr = nrow(dt) 的文件。 如果你有 1 億行,內存管理非常重要,計算應該盡量按 n 階,O(n) 而不是 O(n*rng)
如果您顯示嵌入式日誌,將打印出進行計算的時間。還開始數據更新()和結束數據更新()用於節省 IO(渲染)時間。在我的電腦上,這是我的一些結果:
| 天然橡膠 |
nrg |
秒 |
| 100,000 |
100 |
0.34 |
| 10,000,000 |
1,000,000 |
10.66 |
| 100,000,000 |
100,000,000 |
85.74 |
| 100,000,000 |
10,000,000 |
104.50 |
請注意,此腳本假定沒有缺失值.該腳本將需要修改,性能將大大降低以適應缺失值。 更改 nr 和 nrg 的值以測試您的 PC 的性能。
Names Default to Here(1);
nr = 100000;
dt = new table("test", new column("x"), Add rows(nr));
dt:x << set each value(Random Integer(100,200));
nrg = 100;
dt << begin data update();
t0 = hp time();
mvcol = dt << new column("MV");
mvcol[1] = :x[1];
for(j=2, j<=nrg, j++,
mvcol[j] = (:x[j] + (j-1)*mvcol[j-1])/j; //assumes no missing values
);
if(nrg < nr,
for(j=nrg+1, j<=nr, j++,
mvcol[j] = (:x[j] + (nrg)*mvcol[j-1] - :x[j - nrg])/ (nrg)
);
); //end if,
wait(0);
dt << end data update();
t1= hp time();
show((t1-t0)*1e-6);
鑑於這一切,我仍然覺得你所描述的不是你所需要的。
回复:如何計算 JMP 11 中具有 1 億個條目的列的移動平均值?抱歉不清楚我已經將問題更改為超過 100 億個條目並且條目數量不固定它可以增加到任何數量。 尋找一個通用公式來計算任意數量項目的移動平均值。回复:如何計算 JMP 11 中具有 1 億個條目的列的移動平均值?@jojmp ,
要么我不理解您的要求,要么您不理解 Col Moving Avg()。您聲明您有 1 億行,您在腳本中指定的跨度為 99,999,999。因此,最後一行將是整列的平均值,而前幾行將是直到並包括當前行的所有值。 下面是一張Big Class的圖片和一個跨度為5(n之前)的列移動平均線。請注意,少於 6 的行僅使用所有行,並且會根據少於 6 個值得出平均值。從第 6 行開始,使用當前行和前 5 行計算平均值。
所以請提供更多細節。 現在,如果您的文件有超過 1 億行,則需要修改自定義公式。

回复:如何計算 JMP 11 中具有 1 億個條目的列的移動平均值?在這個自定義公式中,我們如何知道它是 9999 項的移動平均數?
回复:如何計算 JMP 11 中具有 1 億個條目的列的移動平均值?@jojmp ,你的移動平均線公式有點外國
thisTable << New Column( "av", Numeric, Continuous, Formula( Col Moving Average( :x, 1, 9999999, 0 ) ) );
第三個參數 99999999 是通過序列(行)創建某種類型的(歷史)平均值。第三個參數是平均值的跨度。 更常見的跨度是 5 或 10 或 ??為時間附近的值提供平均值,不包括整個歷史。
假設這就是您想要的,替代公式可以做同樣的事情
If( Row() == 1,
:x,
(:x + (Row() - 1) * Lag( :av, 1 )) / Row()
)
附件是樣本數據 Big Class.jmp 的一個版本,其中包含兩列帶公式
Col Moving Average( :weight, 1, 9999, 0 )
和可比較的自定義公式
If( Row() == 1,
:weight,
(:weight + (Row() - 1) * Lag( :Custom Formula, 1 )) / Row()
)