PatrickT

Dr. Patrick T

2163 Reputation

18 Badges

16 years, 338 days

MaplePrimes Activity


These are replies submitted by PatrickT

@Robert Israel 

Thanks Robert, I have followed up on your links, very useful info.

Patrick.

Can types be combined as optional argument? e.g. RNN(M,1,{real, positive});

and how about something like this RNN(M,1,RealRange(0,10));

thanks!

Can types be combined as optional argument? e.g. RNN(M,1,{real, positive});

and how about something like this RNN(M,1,RealRange(0,10));

thanks!

Thanks Robert, that's a great proc to have, coming as it does after Preben's explanations I am now just about equipped to follow each step. (dk need not be declared local). I note that you did not use the built-in RemoveNonNumeric.

One advantage of your approach is that I do not need to be explicit about HFloat(undefined) and Float(undefined). And I can get rid of a lot of ugliness in one stroke, e.g.

M := Matrix([ 
  [HFloat(undefined),HFloat(undefined),HFloat(undefined)]
  , [1,2,3]
  , [Float(undefined),Float(undefined),Float(undefined)]
  , [-1,-2,-3]
  , [HFloat(undefined),Float(undefined),Float(undefined)*I]
  , [Float(infinity),Float(-infinity),Float(infinity)*I]
  , [1+I*1,2+I*2,3+I*3]
]);
RNN(M,1,real);
                          [ 1   2   3]
                          [          ]
                          [-1  -2  -3]

Thanks Robert, that's a great proc to have, coming as it does after Preben's explanations I am now just about equipped to follow each step. (dk need not be declared local). I note that you did not use the built-in RemoveNonNumeric.

One advantage of your approach is that I do not need to be explicit about HFloat(undefined) and Float(undefined). And I can get rid of a lot of ugliness in one stroke, e.g.

M := Matrix([ 
  [HFloat(undefined),HFloat(undefined),HFloat(undefined)]
  , [1,2,3]
  , [Float(undefined),Float(undefined),Float(undefined)]
  , [-1,-2,-3]
  , [HFloat(undefined),Float(undefined),Float(undefined)*I]
  , [Float(infinity),Float(-infinity),Float(infinity)*I]
  , [1+I*1,2+I*2,3+I*3]
]);
RNN(M,1,real);
                          [ 1   2   3]
                          [          ]
                          [-1  -2  -3]

I have just come across Statistics:-RemoveNonNumeric, which seems to be designed precisely for this. However, it takes only 1-dimensional rtables, and does not seem to work on a Matrix. I wonder how hard would it be to extend the capabilities of this built-in procedure to allow it to deal with Matrices or n-dimensional rtables? This would be a great tool to have. Much data in statistics/econometrics comes in the form of panels and if you're going to remove a non-numeric row (e.g. along the time dimension) you want to do it for every variable.

I have just come across Statistics:-RemoveNonNumeric, which seems to be designed precisely for this. However, it takes only 1-dimensional rtables, and does not seem to work on a Matrix. I wonder how hard would it be to extend the capabilities of this built-in procedure to allow it to deal with Matrices or n-dimensional rtables? This would be a great tool to have. Much data in statistics/econometrics comes in the form of panels and if you're going to remove a non-numeric row (e.g. along the time dimension) you want to do it for every variable.

pagan, Robert, thanks a lot for your suggestions.

I like it when I understand what the code does right away, that's why I like Preben's approach, where I can follow each step; Robert's code is likewise very transparent, and as it is very short I should be able to remember it off the top of my head (I'm not very familiar with the use of the dollar sign, I understand it as a sort of shortcut for seq(this, i=that), I've noticed Robert uses it quite often), so that's great.

I find the syntax seq(`if`(this and that)) not easy to remember and use (I got it the wrong way around earlier), so I'm happy to have found an alternative. pagan you tell me keep2 doesn't seem to perform too poorly relative to keep1, so that's great news and I'll "adopt" keep2.

In terms of legibility, LinearAlgebra:-RowDimension(M); is more transparent than op([1,1],M); so unless there are reasons not to I think I would prefer it.

The problem was fixed by replacing HFloat by Float. I do not know the reason for this. If a full row is displayed inline, HFloat(undefined) is displayed. If only a single cell is displayed inline, Float(undefined) is displayed. See:


M;



M[1];

 

The following proc does just the job, thanks again Preben!

exportCleanData := proc(p::evaln)
  local thedata, thedir, thename, M, U, i, j, m, n :
  thedata := plottools:-getdata~([eval(p)]) :
  thedir := cat(currentdir(),kernelopts(dirsep),data,kernelopts(dirsep)) :
  U := NULL :
  n := nops([eval(p)]) :
  for i from 1 to n do
    thename := cat(convert(p,string),"_",i,".txt"):
    M := op([eval(i),-1],thedata):
    m := LinearAlgebra:-RowDimension(M):
    for j from 1 to m do
      if has(LinearAlgebra:-Row(M,eval(j)), HFloat(undefined))
        or has(LinearAlgebra:-Row(M,eval(j)), Float(undefined))
      then U := U,j :
      end if :
    end do :
    LinearAlgebra:-DeleteRow(M,[U]);
    ExportMatrix(cat(thedir,thename), LinearAlgebra:-DeleteRow(M,[U]), delimiter=",") :
  end do :
end proc :

The problem was fixed by replacing HFloat by Float. I do not know the reason for this. If a full row is displayed inline, HFloat(undefined) is displayed. If only a single cell is displayed inline, Float(undefined) is displayed. See:


M;



M[1];

 

The following proc does just the job, thanks again Preben!

exportCleanData := proc(p::evaln)
  local thedata, thedir, thename, M, U, i, j, m, n :
  thedata := plottools:-getdata~([eval(p)]) :
  thedir := cat(currentdir(),kernelopts(dirsep),data,kernelopts(dirsep)) :
  U := NULL :
  n := nops([eval(p)]) :
  for i from 1 to n do
    thename := cat(convert(p,string),"_",i,".txt"):
    M := op([eval(i),-1],thedata):
    m := LinearAlgebra:-RowDimension(M):
    for j from 1 to m do
      if has(LinearAlgebra:-Row(M,eval(j)), HFloat(undefined))
        or has(LinearAlgebra:-Row(M,eval(j)), Float(undefined))
      then U := U,j :
      end if :
    end do :
    LinearAlgebra:-DeleteRow(M,[U]);
    ExportMatrix(cat(thedir,thename), LinearAlgebra:-DeleteRow(M,[U]), delimiter=",") :
  end do :
end proc :

@Preben Alsholm 

Thanks Preben, this looks promising. For some reason I'm having difficulty combining the loop with getdata inside a procedure (No difficulty reproducing your example). I'll need to check every step more carefully. I will report back once I identify the problem. This could take a few days as I'm going to be travelling over the weekend. Thanks again.

@Preben Alsholm 

Thanks Preben, this looks promising. For some reason I'm having difficulty combining the loop with getdata inside a procedure (No difficulty reproducing your example). I'll need to check every step more carefully. I will report back once I identify the problem. This could take a few days as I'm going to be travelling over the weekend. Thanks again.

With my browser and with my set of eyes, the images appear essentially identical though they differ slightly in size 28,681 / 28,708  / 28,724.

Edit. I wouldn't make much of the size difference because I just notice that numpoints=5000 is the smallest image and numpoints=50 is the largest...

With my browser and with my set of eyes, the images appear essentially identical though they differ slightly in size 28,681 / 28,708  / 28,724.

Edit. I wouldn't make much of the size difference because I just notice that numpoints=5000 is the smallest image and numpoints=50 is the largest...

@acer 

You're right, there's only one image there. I hadn't noticed, thanks a lot acer for pointing this out. I know what happened. My images were named:

127477-Maple-Resolution-Problem_p50.gif
127477-Maple-Resolution-Problem_p500.gif
127477-Maple-Resolution-Problem_p5000.gif

and mapleprimes cannot handle long file names. I can't remember now, but I think the limit is 18 or 20 characters, so it couldn't tell the difference between them and, as a result, would only keep one of them at a time. I experienced this problem a few months ago but had forgotten about it. Thanks.

First 25 26 27 28 29 30 31 Last Page 27 of 93