<div dir="ltr">Yes, thank you!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Nov 10, 2013 at 2:39 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I think this is the program you want:<br>
<br>
#lang racket<br>
<br>
(module+ test<br>
  (require rackunit))<br>
<br>
;; [List-of Real] -> [List-of Real]<br>
<br>
(module+ test<br>
  (check-equal? (roulette-wheel-ratio '(1 2 3)) '(1/6 2/6 3/6)))<br>
<br>
(define (roulette-wheel-ratio generation-fitness)<br>
  (define total-population-fitness (foldl + 0 generation-fitness))<br>
  (map (lambda (fitness) (/ fitness total-population-fitness)) generation-fitness))<br>
<div><div class="h5"><br>
<br>
<br>
<br>
On Nov 10, 2013, at 2:28 PM, Rian Shams wrote:<br>
<br>
> Hello All,<br>
><br>
> As part of the design for a simple genetic algorithm I have this function:<br>
><br>
> (define (roulette-wheel-ratio generation-fitness )<br>
>   (cond [(empty? generation-fitness) empty]<br>
>            [else (cons (/ (first generation-fitness)<br>
>                                (total-population-fitness generation-fitness))<br>
>                     (roulette-wheel-ratio (rest generation-fitness)))]))<br>
><br>
> where generation-fitness is a list of values that correspond to the fitness of each individual in a population. For example, in a generation with population size 12, generation fitness may look like:<br>
><br>
> '(7.8807275269175125<br>
>   6.78896220864992<br>
>   6.52572681075793<br>
>   3.208263473483078<br>
>   9.970710802683316<br>
>   10.400703374724888<br>
>   7.434703353949041<br>
>   6.009574612909729<br>
>   2.9503066173989634<br>
>   6.07124467626777<br>
>   2.1893449585751754<br>
>   1.0741024515301607)<br>
><br>
> Here is how I have defined the auxiliary function, total-population-fitness:<br>
><br>
> (define (total-population-fitness generation-fitness)<br>
>   (foldl + 0 generation-fitness))<br>
><br>
> I was wondering how can I modify the above function, roulette-wheel-ratio so that when it evaluates the helper function, total-population-fitness it only does so for the initial list of generation-fitness. Otherwise the total population fitness decreases for each recursive call which is what I don't want, it should remain constant throughout the entire function call.<br>

><br>
> Basically, is it possible to modify this function so that the auxiliary function call (total-population-fitness generation-fitness) remains unaffected by the natural recursion imposed by roulette-wheel-ratio?<br>
><br>
> Any help would be appreciated as I am still learning the Racket basics.<br>
><br>
> Kind Regards,<br>
> --<br>
> Rian Shams<br>
</div></div>> ____________________<br>
>  Racket Users list:<br>
>  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</blockquote></div><br></div>