acer

32490 Reputation

29 Badges

20 years, 7 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Someone asked me what makes the final color red, since changing the color=red to color=green in the line of code which creates the initial plot (and assigns it to `p`) does not affect the final result of a point-plot with a red color gradient.

The color=red in the initial call,

    p:=plots:-pointplot(xy,color=red,symbolsize=4):

is only there so that the PLOT structure has a COLOR section which can be replaced. I probably ought to have chosen some other color and mentioned that the particular choice -- at this stage -- is irrelevent as far as the goal goes.

The actual coloring of the result was determined by the originally posted bit of code,

   (i)->`if`(irem(i,3)=1,xy[(i+2)/3,2],0)

in the Array constructor call which creates Array `c`. And n the ArrayTools:-Copy example, the final color was determined by choosing a stride which only copied every third entry, starting with the first (ie. the "red" parts of each triple).

This post is just an exposition, to show that the float[8] Array can be used to set a coloring scheme. It allows for all kinds of schemes, where rgb or hue can change gradually in any direction, or even along a conceptualized curve in space.

If someone were to turn the process into a robust procedure, which could be applied after the fact to any pointplot PLOT strucure, then it would test for the presence of a COLOR section. If it already existed then it would be replaced, and if it did not already exist then it would get added.

In much older Maple releases the location data itself of a 2D plot could not be supplied as  float[8] rtables. Then, for some release(s), such rtables (eg. Matrix, Array) were used internally but not acceptable as arguments to the plot commands. That's around the time frame at which Robert Israel noticed that a PLOT/PLOT3D structure could be manually formed with such rtables, and his fast plotters in his Maple Advisor database ensued. And in recent Maple versions many plot commands have been changed to accept their data argument as such float[8] rtables. But that's just the point location data. It's a natural progression that the color-specification data -- which has become float[8] internally -- would finally be acceptable as input as well. That's my opinion, anyway.

acer

@Jimmy First thing: please don't repost this as a duplicate question. We've all seen it here, and it won't help to ask it over again.

When I asked you earlier whether variable `i` was supposed to be dependent or independent I had in mind that it might be considered as independent. (I realize that you answered the opposite.)

That is, suppose you took your equation i = i0*(exp((1000*(v-i*rs))/(25.9*n))-1) and got from that form i0*(exp((1000*(v-i*rs))/(25.9*n))-1) - i = 0.

Then suppose that the dependent variable (we don't even have to name it...) has value zero for every measured pair of values of `v` and `i` the independent variables.

In this view, the independent data can be taken as the m-by-2 Matrix formed by concatenating the column Vectors `V` and `idata`. In Maple syntax, something like,

dim := LinearAlgebra:-Dimension(V);

NonlinearFit( i0*(exp((1000*(v-i*rs))/(25.9*n))-1) - i, 
              < V | idata >,
              Vector(dim),
              [v,i],
              parameterranges=[...]
              output=[...] );

But I then ran into the problem that your stated parameter-range for `rs` could not be right. For your "shortened" version of the equation the parameter rs might have to be quite different than 1..500.

And since the variables and parameters can vary by a factor of about 1e6 then raising the working precision (in Maple, the environment setting `Digits`) to about 20 or 30 seems like not a bad idea.

So, how about using the full equation, with this approach? By full equation I mean use all of the terms of the right-hand-side equation that you showed at the very beginning of this post.

There may have some more constant parameter there, whose value you haven't yet given us, like R_SH, n_R, and I_SR. Perhaps by using the proper full formula the discrepancy with your stated range for parameter `rs` would be resolved.

@Jimmy First thing: please don't repost this as a duplicate question. We've all seen it here, and it won't help to ask it over again.

When I asked you earlier whether variable `i` was supposed to be dependent or independent I had in mind that it might be considered as independent. (I realize that you answered the opposite.)

That is, suppose you took your equation i = i0*(exp((1000*(v-i*rs))/(25.9*n))-1) and got from that form i0*(exp((1000*(v-i*rs))/(25.9*n))-1) - i = 0.

Then suppose that the dependent variable (we don't even have to name it...) has value zero for every measured pair of values of `v` and `i` the independent variables.

In this view, the independent data can be taken as the m-by-2 Matrix formed by concatenating the column Vectors `V` and `idata`. In Maple syntax, something like,

dim := LinearAlgebra:-Dimension(V);

NonlinearFit( i0*(exp((1000*(v-i*rs))/(25.9*n))-1) - i, 
              < V | idata >,
              Vector(dim),
              [v,i],
              parameterranges=[...]
              output=[...] );

But I then ran into the problem that your stated parameter-range for `rs` could not be right. For your "shortened" version of the equation the parameter rs might have to be quite different than 1..500.

And since the variables and parameters can vary by a factor of about 1e6 then raising the working precision (in Maple, the environment setting `Digits`) to about 20 or 30 seems like not a bad idea.

So, how about using the full equation, with this approach? By full equation I mean use all of the terms of the right-hand-side equation that you showed at the very beginning of this post.

There may have some more constant parameter there, whose value you haven't yet given us, like R_SH, n_R, and I_SR. Perhaps by using the proper full formula the discrepancy with your stated range for parameter `rs` would be resolved.

To be honest I did not give optimizing this as much consideration as I might have.

Partly that is because it should be utterly clear by this date in time that a float[8] Array will soundly beat a list (or sequence) of floats at these sizes, both in terms of speed and memory.

But there is so much more the the float[8] Array brings with it. It allows the color data to be held in a truly mutable data structure, which means it can be used and re-used with minimal penalty of memory managment. (...animation comes to mind.) There are a wealth of Library and kernel routines which have themselves been optimized for handling float[8]. And it will always take proportionally less memory allocation. (The only single thing that could take less memory while offering the color depth is float[4], and there are less routines optimized speedwise for that.)

Let's compare the two previous suggestions (both faster than my original) with one more faster way, which is to use ArrayTools:-Copy.

I have suppressed display of the plot, in the timing runs below, because I found that repeatedly rerunning the whole set of code would produce somewhat random timings. In general, however, I thought that I saw timings like what follows below, but on average with a constant addition of the time it takes for the GUI to display the plot. Hence, timings are without the plots being rendered on the worksheet.  (32bit Windows below. In 64bit the memory size of Herclau's method rises to abotu 47.0 MB, and of the other to about 3.3 MB.)

restart:
N:=25000:
xy:=LinearAlgebra:-RandomMatrix(N,2,generator=0.0..1.0,
                                outputoptions=[datatype=float[8]]):
str:=time[real]():
plots:-pointplot(xy,
                    color=[seq(RGB(xy[i, 2], 0., 0.), i = 1 .. N)],
                    symbolsize=4):
time[real]()-str;

                             0.327

kernelopts(bytesalloc);

                            18150148

restart:
N:=25000:
xy:=LinearAlgebra:-RandomMatrix(N,2,generator=0.0..1.0,
                                outputoptions=[datatype=float[8]]):
str:=time[real]():
f:=proc(A::Array(datatype=float[8],order=C_order),
        xy::Matrix(datatype=float[8]), n)
 local i;
 for i from 1 to n*3 do
  A[i]:=`if`(irem(i,3)=1,xy[(i+2.0)/3.0,2],0);
 end do:
 NULL:
end proc:
p:=plots:-pointplot(xy,color=red,symbolsize=4):
c:=Array(1..N*3, datatype=float[8],order=C_order):
evalhf(f(c,xy,N)):
subsindets(p,specfunc(anything,COLOUR),z->'COLOUR'('RGB',c)):
time[real]()-str;

                             0.046

kernelopts(bytesalloc);

                            2293340

restart:
N:=25000:
xy:=LinearAlgebra:-RandomMatrix(N,2,generator=0.0..1.0,
                                outputoptions=[datatype=float[8]]):
str:=time[real]():
p:=plots:-pointplot(xy,color=red,symbolsize=4):
c:=Array(1..N*3, datatype=float[8],order=C_order):
ArrayTools:-Copy(N,xy,N,1,c,0,3);
subsindets(p,specfunc(anything,COLOUR),z->'COLOUR'('RGB',c)):
time[real]()-str;

                             0.016

kernelopts(bytesalloc);

                            2293340

acer

@PatrickT The 2D Math in the uploaded worksheet (mirrored in 1D by Patrick) does not look right for initial conditions that specify derivatives evaluated at particular points.

Eg, diff(t1(0), y) = -(diff(t2(0),y)) becomes 0=0.

What's likely intended is D(t1)(0) = - D(t2)(0) or some equivalent using eval and diff.

But when I try such revisions, Maple 16 issues an error message, stating that it cannot convert to an explicit 1st order system. Maybe someone else could check that.

@Jimmy I didn't notice before, that you had too many variables in your call, sorry.

Is idata suppose to be the dependent data, and V the independent data? If so, then what is `i`?

It's clear that `v` is an independent variable. But either `i` is some other parameter of the formula, or else your original formula was something implicit like i=f(v,i,i0,rs,n) and `i` is supposed to be your dependent variable. Is either of those your situation?

Also, your range for i0 goes from larger value to smaller value, and you'd want to fix that or else it would complain. And you could pass an extra (4th) argument to specify the variables, in this case the [v] say.

@Jimmy I didn't notice before, that you had too many variables in your call, sorry.

Is idata suppose to be the dependent data, and V the independent data? If so, then what is `i`?

It's clear that `v` is an independent variable. But either `i` is some other parameter of the formula, or else your original formula was something implicit like i=f(v,i,i0,rs,n) and `i` is supposed to be your dependent variable. Is either of those your situation?

Also, your range for i0 goes from larger value to smaller value, and you'd want to fix that or else it would complain. And you could pass an extra (4th) argument to specify the variables, in this case the [v] say.

@Jimmy Be careful and keep in mind why the change.

The key is that the first argument to NonlinearFit should be a formula, and the variables names in it should not be assigned (in particular, should not be assigned any Vector as value).

Next, the names which are assigned Vectors are the ones to use in the later 2nd and 3rd arguments to NonlinearFit.

So, if V and idata are the Vectors of data then the call to NonlinearFit might look something like,

NonlinearFit( i0*exp(1000*(v-i*rs))/(25.9*n)-1,
              V, idata, parameterranges = [i0 = 10^(-6) .. 10^(-8),
              rs = 1 .. 500, n = 1 .. 5],
              output = [residualsumofsquares, 
                        leastsquaresfunction]);

So, above the 1st argument (formula) has unassigned names `v` and `i` for the variables, and the 2nd and 3rd arguments are `V` and `idata` which are your data Vectors.

I think you'll find that your earlier attempts has some of that mixed up.

Make sure that you either restart after your earlier attempt, or unassign 'v' and 'i', or else you'll just have the same problem with Maple trying to stuff the Vectors into the formula (which is where your error came from).

nb. You can't easily assign to `I`, so I used `idata` instead.

@Jimmy Be careful and keep in mind why the change.

The key is that the first argument to NonlinearFit should be a formula, and the variables names in it should not be assigned (in particular, should not be assigned any Vector as value).

Next, the names which are assigned Vectors are the ones to use in the later 2nd and 3rd arguments to NonlinearFit.

So, if V and idata are the Vectors of data then the call to NonlinearFit might look something like,

NonlinearFit( i0*exp(1000*(v-i*rs))/(25.9*n)-1,
              V, idata, parameterranges = [i0 = 10^(-6) .. 10^(-8),
              rs = 1 .. 500, n = 1 .. 5],
              output = [residualsumofsquares, 
                        leastsquaresfunction]);

So, above the 1st argument (formula) has unassigned names `v` and `i` for the variables, and the 2nd and 3rd arguments are `V` and `idata` which are your data Vectors.

I think you'll find that your earlier attempts has some of that mixed up.

Make sure that you either restart after your earlier attempt, or unassign 'v' and 'i', or else you'll just have the same problem with Maple trying to stuff the Vectors into the formula (which is where your error came from).

nb. You can't easily assign to `I`, so I used `idata` instead.

Yes, that's what is meant by mutable in this context: that the value of an entry can be changed inplace, without a whole new structure being created.

The problem with faking mutability of lists is that code which alters entries many times (or code which does it, and which itself is intended on being called many times) will cause Maple to spend a great deal of resources doing unnecessary memory management. And that can wreck efficiency and the ability of the code to scale as well.

Maple fakes `list` mutability like this:

restart:

L:=[a,b,c,d,e];

                        [a, b, c, d, e]

addressof(L);

                           449181536

L[3]:=Q:

L;

                        [a, b, Q, d, e]

addressof(L); # ahah, it is not the same list!

                           449181776

One could also fake that by crude modification and reassignment to the same name,

restart:

L:=[a,b,c,d,e];

                        [a, b, c, d, e]

L:=subsop(3=Q,L);

                        [a, b, Q, d, e]
There is even a cut-off size for the mechanism.
restart:

L:=[seq(i,i=1..100)]:

L[3]:=Q:

L:=[seq(i,i=1..101)]:

L[3]:=Q:
Error, assigning to a long list, please use Arrays

But of course one can find texts and advice to just use something like the subsop trick, when the length is greater than 100. As if that were a good idea. Which it isn't. Just as allowing it for lengths less than 100 wasn't a terribly good idea either.

So, if you have to change the values of entries many times (or a few times in code which you expect to re-use many times) then you would probably be better off using a mutable structure such as a Vector/Matrix/Array.

acer

Yes, that's what is meant by mutable in this context: that the value of an entry can be changed inplace, without a whole new structure being created.

The problem with faking mutability of lists is that code which alters entries many times (or code which does it, and which itself is intended on being called many times) will cause Maple to spend a great deal of resources doing unnecessary memory management. And that can wreck efficiency and the ability of the code to scale as well.

Maple fakes `list` mutability like this:

restart:

L:=[a,b,c,d,e];

                        [a, b, c, d, e]

addressof(L);

                           449181536

L[3]:=Q:

L;

                        [a, b, Q, d, e]

addressof(L); # ahah, it is not the same list!

                           449181776

One could also fake that by crude modification and reassignment to the same name,

restart:

L:=[a,b,c,d,e];

                        [a, b, c, d, e]

L:=subsop(3=Q,L);

                        [a, b, Q, d, e]
There is even a cut-off size for the mechanism.
restart:

L:=[seq(i,i=1..100)]:

L[3]:=Q:

L:=[seq(i,i=1..101)]:

L[3]:=Q:
Error, assigning to a long list, please use Arrays

But of course one can find texts and advice to just use something like the subsop trick, when the length is greater than 100. As if that were a good idea. Which it isn't. Just as allowing it for lengths less than 100 wasn't a terribly good idea either.

So, if you have to change the values of entries many times (or a few times in code which you expect to re-use many times) then you would probably be better off using a mutable structure such as a Vector/Matrix/Array.

acer

@Jimmy You cannot use `v` for the assigned data Vector name as well as the independent variable name in the fitting formula.

Try using `V` for the data Vector, and `v` in the formula as the first argument to NonlinearFit. Or the other way around. Just not the same name for both.

@Jimmy You cannot use `v` for the assigned data Vector name as well as the independent variable name in the fitting formula.

Try using `V` for the data Vector, and `v` in the formula as the first argument to NonlinearFit. Or the other way around. Just not the same name for both.

@marram Well, you could also look at those module locals. See here for tips.

I don't have your archive, so can only guess as to the exact contents. Maybe something like,

showstat(Involutive::`Involutive/InvolutiveBasis`)

kernelopts(opaquemodules=false):
print(Involutive:-`Involutive/InvolutiveBasis`);

@marram Well, you could also look at those module locals. See here for tips.

I don't have your archive, so can only guess as to the exact contents. Maybe something like,

showstat(Involutive::`Involutive/InvolutiveBasis`)

kernelopts(opaquemodules=false):
print(Involutive:-`Involutive/InvolutiveBasis`);
First 404 405 406 407 408 409 410 Last Page 406 of 594