/* -*- mode: C++ -*- */ ////////////////////////////////////////////////////////////////////////////// // FILE : ModelC2.tol // PURPOSE: Defines Class @ModelC2 ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// Text _.autodoc.member.IndexedGrid = ""; ////////////////////////////////////////////////////////////////////////////// Class @IndexedGrid ////////////////////////////////////////////////////////////////////////////// { VMatrix _.X; Real _.edge.length; Real _.n = ?; Real _.m = ?; Set _.key.dim =Copy(Empty); Matrix _.key.factor = Rand(0,0,0,0); Matrix _.Y.key = Rand(0,0,0,0); Matrix _.Y.h = Rand(0,0,0,0); VMatrix _.Y = Rand(0,0,0,0); Real _.H = 0; Set _.Y.neighbourhood.point = Copy(Empty); VMatrix _.Y.neighbourhood.index = Rand(0,0,0,0); //////////////////////////////////////////////////////////////////////////// Static @IndexedGrid None(Real void) //////////////////////////////////////////////////////////////////////////// { @IndexedGrid new = [[ VMatrix _.X = Rand(0,0,0,0); Real _.edge.length = ? ]]; new }; //////////////////////////////////////////////////////////////////////////// Static @IndexedGrid New( VMatrix X, Real edge.length, Real do.build.neighbourhood) //////////////////////////////////////////////////////////////////////////// { @IndexedGrid new = [[ VMatrix _.X = X; Real _.edge.length = edge.length ]]; Real new::build.index(0); Real If(do.build.neighbourhood, new::build.neighbourhood(0)); new }; //////////////////////////////////////////////////////////////////////////// Static NameBlock MatModule(Matrix A, Matrix B) //////////////////////////////////////////////////////////////////////////// {[[ Matrix quotient = Round(A $/ B); Matrix rest = A - quotient $* B ]]}; //////////////////////////////////////////////////////////////////////////// Static NameBlock MatModuleR(Matrix A, Real b) //////////////////////////////////////////////////////////////////////////// {[[ Matrix quotient = Floor(A *(1/b)); Matrix rest = A - quotient * b ]]}; //////////////////////////////////////////////////////////////////////////// Matrix point2key(VMatrix A) //////////////////////////////////////////////////////////////////////////// { Matrix zero = Rand(VRows(A),1,0,0); Matrix A.key.dim = Group("ConcatColumns", For(1,_.n, Matrix(Real i) { -Min(zero, MatReplace( Round(VMat2Mat(SubCol(A,[[i]]))*(1/_.edge.length)), SubCol(_.key.dim[i],[[2]]), -SubCol(_.key.dim[i],[[1]]))) })); A.key.dim * _.key.factor }; //////////////////////////////////////////////////////////////////////////// VMatrix key2point(Matrix key) //////////////////////////////////////////////////////////////////////////// { Group("ConcatColumns", { Matrix aux = Copy(key); Set reverse = EvalSet(Range(_.n,1,-1), VMatrix(Real i) { NameBlock mod=@IndexedGrid::MatModuleR(aux,MatDat(_.key.factor,i,1)); Matrix aux := Copy(mod::rest); Mat2VMat(MatReplace( mod::quotient, SubCol(_.key.dim[i],[[1]]), SubCol(_.key.dim[i],[[2]])))*_.edge.length }); EvalSet(Range(_.n,1,-1), VMatrix(Real i) { reverse[i] }) }) }; ///////////////////////////////////////////////////////////////////////////// Matrix index2key(Matrix idx) ///////////////////////////////////////////////////////////////////////////// { -Min(Rand(Rows(idx),1,0,0), MatReplace(idx, _.Y.h, -_.Y.key)) }; //////////////////////////////////////////////////////////////////////////// Matrix key2index(Matrix key) //////////////////////////////////////////////////////////////////////////// { -Min(Rand(Rows(key),1,0,0), MatReplace(key, _.Y.key, -_.Y.h)) }; //////////////////////////////////////////////////////////////////////////// VMatrix index2point(Matrix idx) //////////////////////////////////////////////////////////////////////////// { key2point(index2key(idx)) }; //////////////////////////////////////////////////////////////////////////// Matrix point2index(VMatrix A) //////////////////////////////////////////////////////////////////////////// { key2index(point2key(A)) }; //////////////////////////////////////////////////////////////////////////// Real build.index(Real void) //////////////////////////////////////////////////////////////////////////// { Real _.n := VColumns(_.X); Real _.m := VRows(_.X); VMatrix X.round = Round(_.X/_.edge.length); Set _.key.dim := For(1,_.n, Matrix(Real i) { Matrix key = SetCol(Sort(Unique(VCol2Set(SubCol(X.round,[[i]]))),Compare)); Matrix idx = DifEq(1/(1-B),Rand(Rows(key),1,1,1)); idx|key }); Matrix _.key.factor := { Matrix aux.1 = SetCol(EvalSet(_.key.dim,Rows)); Matrix aux.2 = Floor(Log10(aux.1))+1; Matrix aux.3 = DifEq(1/(1-B),Col(0)<