Stephen Forrest

Mr. Stephen Forrest

466 Reputation

14 Badges

20 years, 302 days
Maplesoft
Software Architect

Social Networks and Content at Maplesoft.com

Maple Application Center

MaplePrimes Activity


These are replies submitted by Stephen Forrest

Ah, now I see. Here is a procedure which does what you wish. It's not the fastest, but should be conceptually clear. It takes two arguments: a matrix and a symbol representing the unknown entries in the matrix.
p := proc(M, x)
    local r, s, i, j, c;
    r := [rtable_dims(M)];
    for j from 1 to rhs(r[2]) do
        # sum entries in column
        s := add( i, i=M[1..-1,j] );
        # determine how many unknowns were present
        c := coeff( s, x );
        # compute mean of known entry values
        s := eval( s, x=0 ) / (rhs(r[1])-c);
        # replace symbols in column with mean
        M[1..-1,j] := eval( M[1..-1,j], x=s )
    end do;
    M
end proc:
Example:
> M := <<1,`?`,2>|<2,2,1>|<3,`?`,6>>;
                      [1    2    3]
                      [           ]
                 M := [?    2    ?]
                      [           ]
                      [2    1    6]

> p( M, `?` );
                  [ 1     2     3 ]
                  [               ]
                  [3/2    2    9/2]
                  [               ]
                  [ 2     1     6 ]
Note that this procedure is destructive: that is, it alters the original matrix. To avoid this, replace the first two lines with:
p := proc(M1, x)
    local M, r, s, i, j, c;
    M := Matrix(M1);
Ah, now I see. Here is a procedure which does what you wish. It's not the fastest, but should be conceptually clear. It takes two arguments: a matrix and a symbol representing the unknown entries in the matrix.
p := proc(M, x)
    local r, s, i, j, c;
    r := [rtable_dims(M)];
    for j from 1 to rhs(r[2]) do
        # sum entries in column
        s := add( i, i=M[1..-1,j] );
        # determine how many unknowns were present
        c := coeff( s, x );
        # compute mean of known entry values
        s := eval( s, x=0 ) / (rhs(r[1])-c);
        # replace symbols in column with mean
        M[1..-1,j] := eval( M[1..-1,j], x=s )
    end do;
    M
end proc:
Example:
> M := <<1,`?`,2>|<2,2,1>|<3,`?`,6>>;
                      [1    2    3]
                      [           ]
                 M := [?    2    ?]
                      [           ]
                      [2    1    6]

> p( M, `?` );
                  [ 1     2     3 ]
                  [               ]
                  [3/2    2    9/2]
                  [               ]
                  [ 2     1     6 ]
Note that this procedure is destructive: that is, it alters the original matrix. To avoid this, replace the first two lines with:
p := proc(M1, x)
    local M, r, s, i, j, c;
    M := Matrix(M1);
There are several ways of plotting just the points. One is:
> L := [seq([i, myproc(i)], i=2..20)]:
> plots[pointplot](L);
There are several ways of plotting just the points. One is:
> L := [seq([i, myproc(i)], i=2..20)]:
> plots[pointplot](L);
Incidentally, if you're mapping stuff over rtables, you might consider using rtable_scanblock (see the help page). A large part of the reason one might want map to have a specified order is to know the index of the entry you're visiting. If this is important for your algorithm, you can just use the 'index' option of rtable_scanblock. As for rtable_scanblock, AFAIK its order is not specified either.
As you might expect, it also depends on shape. (You can disregard the lower triangular part of the matrix below for the purposes of determining the order the indices are visited.)
> enumerate(Matrix([[0$5]$5], order=C_order, shape=symmetric));
                         [15    14    13    12    11]
                         [                          ]
                         [14    10     9     8     7]
                         [                          ]
                         [13     9     6     5     4]
                         [                          ]
                         [12     8     5     3     2]
                         [                          ]
                         [11     7     4     2     1]

I don't know too much about how Windows programs handle .ini files generally, and how Maple does specifically. If I interpret what you are saying correctly, Maple is writing to and reading from the user's 'maple.ini' file directly, rather than making calls to the Windows API to ask the OS to do this. Therefore your setup, which intercepts such calls and redirects them to another file, doesn't work. The information relevant to Maple's use of user profiles is described in the help page ?worksheet,reference,profiles. I notice that the help page states that one can configure the 'maplesys.ini', which resides in the Maple installation, to change the location of the user directory. Might it be possible to customize this value to simply point where you want in the first place, and eliminate the need to intercept-and-redirect?
but it isn't a tag that anyone should be using anyhow. Your prescriptivist tone impugns my worldview. I happen to like loading my websites with frames, javascript marquee displays, animated gifs, blink tags, and flash! Or, not.
I think this problem -- leaving unterminated HTML tags in comments on a threaded discussion site and having it cascade all over everything -- has been "solved" in the past simply everyone used tables, rather than CSS.

If I put this into an HTML page:

<table><tr><td><em>hello</td></tr></table><p>world

and view it in my browser, "hello" is italicized while "world" is not:

hello

world

If I use div, which is the standard divider for CSS and which is conceptually nicer than tables in many ways:

<table><tr><td><em>hello</td></tr></table><p>world

hello

world

then the resulting HTML page has both "hello" and "world" italicized. (I stopped this from spilling all over the site by wrapping it in another table.)

So, a hackish solution for the problem exemplified by Joe's post is to wrap each post in "<table><tr><td>...</td></tr></table>". (It is hackish, so I'm not suggesting it.)

(Curiously, I tried as an experiment adding an unterminated BLINK tag to this post, and on Preview got a blank error message with the strange message "terminated request because of suspicious input data".)

What exactly are you asking for here? Are you looking for a syntactical description of the Maple language, e.g. a grammar?
If you want to measure the correlation between datasets, use the Statistics:-Correlation command. For example:
> with(Statistics):
> X := RandomVariable(Normal(0, 1)):
> Y := RandomVariable(Normal(0, 1)):
> rho:=0.5:
> A := Sample(X, 10^5):
> B := Sample(Y, 10^5):
> C := rho*A + sqrt(1-rho^2)*B:

> Correlation( A, B ); # expected, since they're sampled independently
                               -0.0009926612605

> Correlation( A, C ); # approximately rho, as required
                                 0.4990009116
You say you want to generate 100 correlated datasets. If I guess at what you want correctly, you want 100 datasets X_1, ..., X_100, where the correlation coefficient of each pair (X_i, X_j) is rho. Is that correct?
If you want to measure the correlation between datasets, use the Statistics:-Correlation command. For example:
> with(Statistics):
> X := RandomVariable(Normal(0, 1)):
> Y := RandomVariable(Normal(0, 1)):
> rho:=0.5:
> A := Sample(X, 10^5):
> B := Sample(Y, 10^5):
> C := rho*A + sqrt(1-rho^2)*B:

> Correlation( A, B ); # expected, since they're sampled independently
                               -0.0009926612605

> Correlation( A, C ); # approximately rho, as required
                                 0.4990009116
You say you want to generate 100 correlated datasets. If I guess at what you want correctly, you want 100 datasets X_1, ..., X_100, where the correlation coefficient of each pair (X_i, X_j) is rho. Is that correct?
You can do linear algebra (i.e. addition and scalar multiplication) with Vectors and Matrices directly, and thanks to the kernel support for rtables with numeric datatype, this is much, much faster than doing the same job with evalhf and zip. (I should say that I do know that significant work put into improving the speed of rtable operations in the last couple releases, so it's possible that this wasn't quite as fast in past versions.) I increased the size of the dataset to 10^6 to illustrate the point better. Compare, first with evalhf and zip:
> t := time():
> C := evalhf(zip((x,y)->rho*x+sqrt(1-rho^2)*y,A,B)):
> time()-t;
                                 1.244

> Statistics:-Correlation( A, C );
                             0.5006937688
Then the same thing, but done via arithmetic on the rtables:
> t := time():
> C := rho*A + sqrt(1-rho^2)*B:
> time()-t;
                                 0.093

> Statistics:-Correlation( A, C );
                             0.5006937688
You can do linear algebra (i.e. addition and scalar multiplication) with Vectors and Matrices directly, and thanks to the kernel support for rtables with numeric datatype, this is much, much faster than doing the same job with evalhf and zip. (I should say that I do know that significant work put into improving the speed of rtable operations in the last couple releases, so it's possible that this wasn't quite as fast in past versions.) I increased the size of the dataset to 10^6 to illustrate the point better. Compare, first with evalhf and zip:
> t := time():
> C := evalhf(zip((x,y)->rho*x+sqrt(1-rho^2)*y,A,B)):
> time()-t;
                                 1.244

> Statistics:-Correlation( A, C );
                             0.5006937688
Then the same thing, but done via arithmetic on the rtables:
> t := time():
> C := rho*A + sqrt(1-rho^2)*B:
> time()-t;
                                 0.093

> Statistics:-Correlation( A, C );
                             0.5006937688
To have a look at what is there, you could try the following. You'll see a lot which is documented, but a few things that may not be. Another option is to do LibraryTools:-Browse on the whole archive. > L := LibraryTools:-ShowContents( "/opt/maple10/lib/maple.mla" ): > L := map2( op, 1, L ): # remove everything with slashes in it > L := remove( x->StringTools:-Search("/", x) > 0, L); > p := proc(s) if StringTools:-IsSuffix(".m", s) then convert(s[1..-3],'name') else NULL end if; end proc: > L := map( p, L );
3 4 5 6 7 Page 5 of 7