안녕하세요, JMP 커뮤니티 여러분!
제 JSL 스크립트에서는 종종 다음과 같이 새 열을 하나씩 순차적으로 생성합니다.
...
DT << New Column( "Some Name1", Numeric, "Continuous", Formula( Some Formula1 ) );
DT << New Column( "Some Name2", Numeric, "Continuous", Formula( Some Formula2 ) );
DT << New Column( "Some Name3", Numeric, "Continuous", Formula( Some Formula3 ) );
...
일반적으로 제 데이터 테이블은 매우 커서 1억 행에 달하기도 합니다. 제가 사용하는 수식에는 열 평균(Col Mean()) , 열 최대값(Col Maximum()) 등의 통계 함수가 자주 포함되는데, 행 수가 많아질수록 계산 속도가 점점 느려집니다. 몇몇 새 열이 서로 종속적인 관계일 수도 있지만, 현재로서는 그렇지 않다고 가정해 주시기 바랍니다.
스크립트가 실행될 때 JMP 19.1이 제 CPU(16코어, 32스레드)의 3~4% 정도만 사용하는 것을 확인했습니다.
부분집합을 만들고 그 결과를 다시 병합하는 과정 없이 병렬화를 통해 계산 속도를 높이는 것이 가능할까요? JMP에서 JSL을 사용하여 동일한 데이터 테이블을 병렬로 처리할 수 있을까요?
그렇지 않다면, "부분집합 공식 계산 후 병합" 방식을 시도해 볼 가치가 있다고 생각하시나요?
건배
롭
계산 방식(및 수식 필요 여부)에 따라 요약 테이블을 만들고, 거기서 계산을 수행한 후 결과를 다시 테이블에 업데이트할 수 있습니다.
행렬의 병렬 처리를 관리하는 도구로 Parallel Assign이 있습니다.
입력 열의 수가 적고 사용할 수 있는 함수가 매우 제한적인 경우가 아니라면, 이 방법이 실제로 속도를 향상시킬지는 확신할 수 없습니다.
다음은 예시입니다.
Names default to here(1);
dt = Open("$Sample_data/Pollen.jmp");
//first a simple demo of parallel assign to calculate column means
moutmeans = J(n col(dt), 1, .); //blank matrix that will be populated
mdata = dt << get as matrix; //input data as a matrix
Parallel Assign(
{ mdata = mdata }, //variables needed in the 'worker thread'
moutmeans[a, b] = mean(mdata[0,a]); //this fills in one cell
);
show(moutmeans); //col means are here
// Now for new columns
//mdata = mdata[1::2,0]; //a way to start small if you add show()
nrows = nrow(mdata);
cnames = dt << get column names(); //used to find position of columns in matrix
// Write formulas for each columns using column names as placeholders
// to be replaced by matrix values later, this would work for pretty simple logic
formulas = Eval List({
Expr(edge + nub + 10),
Eval Expr(nub - Expr( col mean(dt:nub) ) ) //note this col mean evaluates now
});
newcnames = {"a","b"}; //new column names used later
mout = J(nrows, length(formulas), .); //empty matrix to populate
Parallel Assign(
{
mdata = mdata,
formulas = formulas,
cnames = cnames
},
mout[a, b] = (
f = formulas[b];
//assign values to all potential variables used in matricies
//(bad idea if lots of unused columns)
for(i=1, i<= n items(cnames), i++,
//Make a list with the variable to assign and value to assign it to,
// then replace the list with assign
Eval( Substitute(
Eval List( {as name( name expr( cnames[i] ) ), mdata[a,i]} ),
Expr({}),
Expr( assign() )
) );
);
eval(f);
);
);
//put new columns in table
for each({c,i}, newcnames, dt << New Column(c,Numeric,Continuous, << Set Values(mout[0,i])));
//add columns to double check it worked
dt << New Column("a-check", Numeric, "Continuous", Format("Best", 12), Formula(:edge + :nub + 10));
dt << New Column("b-check", Numeric, "Continuous", Format("Best", 12), Formula(:nub - Col Mean(:nub)));
모든 열이 생성될 때까지 수식 평가를 억제한 다음 '수식 실행'을 시도해 볼 수 있습니다.
( @Ryan_Gilmore , @Robbbb ) dt<
투표하실 위시리스트 항목을 소개합니다.
배경 공식 평가