Interlude 1 - the definition of sum1 #27
Replies: 5 comments 7 replies
-
Peter,
Use www.thelittlelearner.com as can be found in the preface.
Then click on Code.
Follow instructions from then on.
…On Wed, May 17, 2023 at 3:42 PM Peter ***@***.***> wrote:
Hi,
I need some help. I'm really enjoying the book and I'm working through the
examples using DrRacket.
I have tried to code sum1 and summed following the outline detailed at the
top of page 53 of the book but I'm not getting the results expected.
Could you please help me by highlighting where I am going wrong? (code as
per below).
Thanks, much appreciated.
Peter
(define sum-1
(lambda (t)
(summed t (sub1 (tlen t)) 0.0)))
(define summed
(lambda (t i a)
(cond
((zero? i) (+ (tref t 0) a))
(else
(summed t (sub1 i) (+ (tref t i) a))))))
—
Reply to this email directly, view it on GitHub
<#27>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIMRM3XDBZFZAUKFP22GJDXGUSZTANCNFSM6AAAAAAYFROUAQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
That code looks correct. What error/difference are you seeing? Could you post your output here? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Also, please make sure you have the latest copy of malt (I don't know when you pulled the repository), and you have your tensor implementation set to learner. |
Beta Was this translation helpful? Give feedback.
-
The sum-1 means its data must be a flat tensor (i.e. like a vector).
When you look at frame 26, where we define sum, you can see the
progression down to a sum-1, and there the tensor is again flat.
Then, on frames 22 and 23, it clarifies that point.
…On Thu, May 18, 2023 at 4:47 AM Peter ***@***.***> wrote:
Hi,
Thanks for taking a look at the code.
Here are my test cases and results:
Test Case 1 (Using Malted 'sum'): Input = (sum (tensor 10.0 12.0 14.0)),
result = 36.0
Test Case 2 (Using my version): Input = (sum-1 (tensor 10.0 12.0 14.0)),
result = 36.0
For test cases 1 and 2 my version seems to work as expected.
However, for test cases 3 and 4, I get different results as follows:
Test Case 3 ( (Using Malted 'sum'): Input = (sum (tensor (tensor (tensor
5.0 8.0) (tensor 12.00 6.00)) (tensor (tensor 7.0 4.0) (tensor 6.0 5.0)))),
result = (tensor (tensor 13.0 18.0) (tensor 11.0 11.0))
Test Case 4 ((Using my version): Input = (sum-1 (tensor (tensor (tensor
5.0 8.0) (tensor 12.00 6.00)) (tensor (tensor 7.0 4.0) (tensor 6.0 5.0)))),
result = (tensor (tensor 12.0 12.0) (tensor 18.0 11.0))
Kind regards, Peter
—
Reply to this email directly, view it on GitHub
<#27 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIMRMZKKW3BYCHKXXTUZG3XGXOZRANCNFSM6AAAAAAYFROUAQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Peter,
Did everything work?
... Dan
…On Thu, May 18, 2023 at 3:32 PM Peter ***@***.***> wrote:
Hi,
As suggested, I have applied the following:
*racket -e "(require malt/set-impl) (set-impl 'learner)"*
Kind regards, Peter
—
Reply to this email directly, view it on GitHub
<#27 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIMRM4JRVOBNLKKYTMXR3DXGZ2M7ANCNFSM6AAAAAAYFROUAQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I need some help. I'm really enjoying the book and I'm working through the examples using DrRacket.
I have tried to code sum1 and summed following the outline detailed at the top of page 53 of the book but I'm not getting the results expected.
Could you please help me by highlighting where I am going wrong? (code as per below).
Thanks, much appreciated.
Peter
(define sum-1
(lambda (t)
(summed t (sub1 (tlen t)) 0.0)))
(define summed
(lambda (t i a)
(cond
((zero? i) (+ (tref t 0) a))
(else
(summed t (sub1 i) (+ (tref t i) a))))))
Beta Was this translation helpful? Give feedback.
All reactions