I played around a bit with the math/matrix library. Actually, my first idea 
for a Racket learning project was to rewrite the code in the R popbio 
package (https://cran.r-project.org/web/packages/popbio/popbio.pdf) in 
Racket. But I bailed on that when I saw that eigendecomposition was still 
on the list of unimplemented but useful algorithms for math/matrix.

Performance is not important for this example but this math/array warning 
gave me the impression that perhaps it was not the best place to start for 
me. 

Performance Warning: Indexing the elements of arrays created in untyped 
> Racket is currently 25-50 times slower than doing the same in Typed Racket, 
> due to the overhead of checking higher-order contracts. We are working on 
> it.


I also thought it would be good to stick to racket/base for my early forays 
with Racket but I would not give that same advice to someone learning R 
(i.e., some R packages greatly ease the introduction to R).


On Sunday, February 10, 2019 at 12:47:52 AM UTC-8, Philip McGrath wrote:
>
> You may also want to look into the math/array 
> <https://docs.racket-lang.org/math/array.html> and math/matrix 
> <https://docs.racket-lang.org/math/matrices.html> libraries.
> -Philip
>
>
> On Sun, Feb 10, 2019 at 3:42 AM Alex Harsanyi <alexha...@gmail.com 
> <javascript:>> wrote:
>
>> This line looks suspicious:
>>
>>      (define results (make-vector years (make-vector (vector-length 
>> fecundity) 0)))
>>
>> The "(make-vector (vector-length fecundity) 0)" expression will create a 
>> single vector, than it creates the outer vector will all elements pointing 
>> to it.  It is not a matrix, but a "column" vector where each element is 
>> referencing the same row vector.  This means that if you update an element 
>> in one of the rows, the same value will "appear" in all other rows. The 
>> only row that is different is the first one which you initialize in the 
>> line:
>>
>>     (vector-set! results 0 (make-vector (vector-length fecundity) 10))
>>
>> What you probably want is a vector of vectors, which can be built like 
>> this
>>
>>     (define results (for/vector ([index (in-range years)]) (make-vector 
>> (vector-length fecundity) 0)))
>>
>> Alex.
>>
>>
>>
>> On Sunday, February 10, 2019 at 3:40:42 PM UTC+8, travis.h...@gmail.com 
>> wrote:
>>>
>>> Hi All,
>>>
>>> I'm an R programmer that has recently started learning Racket. I decided 
>>> to start by trying to create a simple age-structured population model. In 
>>> R, I would initialize a matrix and use nested for loops to move through the 
>>> elements of the matrix and propagate the population forward through time. 
>>> For my first attempt in Racket (
>>> https://gist.github.com/hinkelman/3ee6115cdd7f0a4c8f1672b7d8df5c27), I 
>>> used for* to loop through a vector of vectors. The code in that gist 
>>> doesn't quite work. There is apparently something wrong with how I'm using 
>>> vector-set! such that "rows" in my vector of vectors are being updated 
>>> prematurely. I would greatly appreciate it if someone could point out what 
>>> I'm doing wrong there. I'm also interested in suggestions for alternative 
>>> approaches because it seems unlikely that I have written this code in 
>>> idiomatic Racket.
>>>
>>> Thanks,
>>>
>>> Travis
>>>
>>> P.S. If it is helpful, here is a gist (
>>> https://gist.github.com/hinkelman/d5b8414b0c6383057d7846509a724bbf) 
>>> with the R code that I was trying to write in Racket.
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to