Reputation: 1390
I'm pretty familiar with Racket, and many in the Scheme and Lisp family, but I have no idea what is up with this error, or what is causing it:
network-biases: contract violation;
given value instantiates a different structure type with the same name
expected: network?
given: (network ...) <-- I omitted this because its useless.
Heres the function where the error is (I have a gist of the rest):
(define (update-mini-batch net mini-batch eta)
(define nabla-b (map (lambda (b)
(apply grid (shape b))) (network-biases net)))
(define nabla-w (map (lambda (w)
(apply grid (shape w))) (network-weights net)))
(define-values (nabla-b-new nabla-w-new)
(foldl (lambda (lst bw)
(define x (first lst))
(define y (second lst))
(define-values (nabla-b nabla-w) bw)
(define-values (delta-nabla-b delta-nabla-w) (backprop net x y))
(define nabla-b-new (+/ nabla-b delta-nabla-b))
(define nabla-w-new (+/ nabla-w delta-nabla-w))
(values nabla-b-new nabla-w-new)) (values nabla-b nabla-w) mini-batch))
(struct-copy network net
[biases (map (lambda (b nb)
(- b (* nb (/ eta (length mini-batch)))))
(network-biases net) nabla-b-new)]
[weights (map (lambda (w nw)
(- w (* nw (/ eta (length mini-batch)))))
(network-weights net) nabla-w-new)]))
I couldn't get an MCVE that actually threw an error, so I don't have one to give.
The distilled basics of what I'm trying to do in the above function is this:
- Thanks!!
Upvotes: 1
Views: 213
Reputation: 31145
Structures in Racket are generative. This means that each time
(struct network (num-layers sizes biases weights) #:transparent)
is run, a new type of structure is created. These are all named network.
The error message you see is usually due to evaluating the structure definition twice (and it is a bit confusing since the two types have the same name).
I can't see anywhere in your code that could lead to (struct network ...)
being run twice. Are you using DrRacket or an alternative environment that doesn't reset namespace?
If I open "nn.rkt" and run it, will I see the error?
Upvotes: 1