JMP 11で100億を超えるエントリを持つ列の移動平均を計算するにはどうすればよいですか?移動平均を計算するために、1 億行の列で以下の式を実行しようとしています。列移動平均
Col Moving Average( :x, 1, 9999999, 0 ) は JMP11 ではサポートされていません。</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
Re: JMP 11 で 1 億エントリの列の移動平均を計算するにはどうすればよいですか?@jojmp 、
テーブルを保存しておらず、作成されていない列を参照している元のスクリプトを考えると、1 つの行を削除して別の行を追加することで多数の値の平均が非常にわずかに変化することを考えると、あなたの質問は非常に変。
以下は、nr = nrow(dt) であるファイルの読み取りに対して、nr 行のテーブルを作成するスクリプトです。 1 億行ある場合、メモリ管理は非常に重要であり、計算は O(n*rng) ではなく、n、O(n) の順序で行う必要があります。
埋め込まれたログを表示すると、計算を行う時間が印刷されます。またデータ更新開始()とデータ更新終了() IO (レンダリング) 時間を節約するために使用されます。私の PC での結果の一部を以下に示します。
| 番号 |
なし |
秒 |
| 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);
これらすべてを考えると、あなたが説明したことはあなたが必要としているものではないかもしれないと今でも感じています。
Re: JMP 11 で 1 億エントリの列の移動平均を計算するにはどうすればよいですか?明確でなくて申し訳ありませんが、質問を10000万以上のエントリに変更しました。エントリの数は固定されておらず、任意の数に増やすことができます. 任意の数のアイテムの移動平均を計算するための一般的な数式を探しています。Re: JMP 11 で 1 億エントリの列の移動平均を計算するにはどうすればよいですか?@jojmp 、
私があなたの要求を理解していないか、あなたが Col Moving Avg() を理解していません。1 億行あり、スクリプトで指定したスパンは 99,999,999 であると述べました。したがって、最後の最後の行は列全体の平均になり、前の行は現在の行までのすべての値になります。 以下は、Big Class とスパン 5 (n before) の列移動平均の写真です。6 未満の行はすべての行を使用するだけであり、6 未満の値に基づいて平均が得られることに注意してください。6 行目以降は、現在の行と前の 5 行を使用して平均が計算されます。
ですから、詳細を教えてください。 ファイルに 1 億行を超える行がある場合は、カスタム式を変更する必要があります。

Re: JMP 11 で 1 億エントリの列の移動平均を計算するにはどうすればよいですか?このカスタム数式では、それが 9999 アイテムの移動平均であることをどのように知ることができますか?
Re: JMP 11 で 1 億エントリの列の移動平均を計算するにはどうすればよいですか?@jojmp 、移動平均の式は少し異質です
thisTable << New Column( "av", Numeric, Continuous, Formula( Col Moving Average( :x, 1, 9999999, 0 ) ) );
3 番目の引数 99999999 は、Sequence (行) によって何らかのタイプの (歴史的な) 平均を作成しています。3 番目の引数は、平均のスパンです。 より一般的なのは、5 または 10 または ?? のスパンです。履歴全体を含まない、ほぼ同じ時間の値の平均を提供します。
それがあなたが望むものであると仮定すると、代替式は同じことを行うことができます
If( Row() == 1,
:x,
(:x + (Row() - 1) * Lag( :av, 1 )) / Row()
)
添付されているのは、数式を含む 2 つの列を持つサンプル データ Big Class.jmp のバージョンです。
Col Moving Average( :weight, 1, 9999, 0 )
および同等のカスタム式
If( Row() == 1,
:weight,
(:weight + (Row() - 1) * Lag( :Custom Formula, 1 )) / Row()
)