[Cs254f11] subst

Lee Spector lspector at hampshire.edu
Fri Nov 18 17:08:54 EST 2011


Doesn't it feel breezy clean? :-)

And I think you're now ready to go multicore pretty easily, maybe just by judiciously changing a map to a pmap or something along those lines (the details of which will take a little thought about what you want to run concurrently, but in any event it should be quick and safe).

 -Lee

On Nov 18, 2011, at 4:45 PM, Wm. Josiah Erikson wrote:

> Yep, now my error function is just (note this is 1/4 the size it was before, I think):
> 
> (reduce + (map #(Math/abs (- (int (eval (postwalk-replace % individual))) %2)) terminal-map scores)))
> 
> That postwalk-replace just pulls out my placeholder function names that were created by calls to random-code, and replaces them with the appropriate numbers for the song, and since it's inside a function that's being mapped down my terminal-map and scores, two lists that correspond to each other, it does it appropriately for each song.
> 
> terminal-map is a list of maps where the keys are function names and the values are what they evaluate to when passed the corresponding song.
> 
> So I now am free of any global re-defing. Yay!
>    -Josiah
> 
> 
> On 11/18/11 2:37 PM, Lee Spector wrote:
>> Fabulous!
>> 
>>  -Lee
>> 
>> 
>> 
>> On Nov 18, 2011, at 2:30 PM, Wm. Josiah Erikson wrote:
>> 
>>> Yeah, it's perfect (this isn't exactly what I'm going end up doing, but it shows the concept).  This will actually be really easy! Check it out:
>>> 
>>> critic_evolution.core=>
>>> (use 'clojure.walk)
>>> nil
>>> 
>>> critic_evolution.core=>
>>> (zipmap list-of-retrieval-functions list-of-analysis-functions)
>>> {(p_i_m) percent_in_mixolydian,
>>> (a_v) average_velocity,
>>> (l_c_r_n) least_common_real_note,
>>> (p_i_l) percent_in_lydian,
>>> (a_n) average_note,
>>> (l_n) low_note,
>>> (p_o_pb) percentage_of_pitchbend,
>>> (p_i_b) percent_in_blues,
>>> (m_c_r_n) most_common_real_note,
>>> (n_o_d_r_n) number_of_different_real_notes,
>>> (h_n) high_note,
>>> (a_r_n) average_real_note,
>>> (s_d_m) std_dev_mostcom,
>>> (p_o_p) percentage_of_percussion,
>>> (p_i_p) percent_in_pentatonic}
>>> 
>>> critic_evolution.core=>
>>> (def function-lookup (zipmap list-of-retrieval-functions list-of-analysis-functions))
>>> #'critic_evolution.core/function-lookup
>>> critic_evolution.core=>
>>> (def mark (random-code 5))
>>> #'critic_evolution.core/mark
>>> critic_evolution.core=>
>>> mark
>>> (max
>>> (-
>>>  (min (* (p_i_p) (- (l_n) (s_d_m))) (l_c_r_n))
>>>  (pmod
>>>   (n_o_d_r_n)
>>>   (pquot (* (p_i_m) (n_o_d_r_n)) (min (p_i_p) (p_o_pb)))))
>>> (pd
>>>  (pquot
>>>   (pd (- (h_n) (p_i_l)) (- (a_v) (p_i_p)))
>>>   (pmod (pmod (l_n) (n_o_d_r_n)) (pmod (p_o_pb) (p_o_pb))))
>>>  (pmod (+ (pmod (p_i_b) 78) (pd (n_o_d_r_n) (p_o_pb))) 32)))
>>> 
>>> critic_evolution.core=>
>>> (postwalk-replace function-lookup mark)
>>> (max
>>> (-
>>>  (min
>>>   (* percent_in_pentatonic (- low_note std_dev_mostcom))
>>>   least_common_real_note)
>>>  (pmod
>>>   number_of_different_real_notes
>>>   (pquot
>>>    (* percent_in_mixolydian number_of_different_real_notes)
>>>    (min percent_in_pentatonic percentage_of_pitchbend))))
>>> (pd
>>>  (pquot
>>>   (pd
>>>    (- high_note percent_in_lydian)
>>>    (- average_velocity percent_in_pentatonic))
>>>   (pmod
>>>    (pmod low_note number_of_different_real_notes)
>>>    (pmod percentage_of_pitchbend percentage_of_pitchbend)))
>>>  (pmod
>>>   (+
>>>    (pmod percent_in_blues 78)
>>>    (pd number_of_different_real_notes percentage_of_pitchbend))
>>>   32)))
>>> 
>>> critic_evolution.core=>
>>> 
>>> On 11/18/11 2:26 PM, Wm. Josiah Erikson wrote:
>>>> ..and if I'm reading postwalk-replace's documentation correctly, I can create a map of things to look for and things to replace and it will do all of them. From the documentation:
>>>> 
>>>> Recursively transforms form by replacing keys in smap with their
>>>>  values.  Like clojure/replace but works on any data structure.  Does
>>>>  replacement at the leaves of the tree first.
>>>> 
>>>> Source:
>>>> (defn postwalk-replace
>>>>  "...docs..."
>>>>  {:added "1.1"}
>>>>  [smap form]
>>>>  (postwalk (fn [x] (if (contains? smap x) (smap x) x)) form))
>>>> 
>>>> So actually postwalk-replace will do all of my work for me. Yes?
>>>> 
>>>>    -Josiah
>>>> 
>>>> 
>>>> 
>>>> On 11/18/11 12:29 PM, Lee Spector wrote:
>>>>> Josiah and I discussed this in person, as a way to do what he's doing more simply, and I won't repeat all of our discussion here, but others might find it useful for similar or different purposes.
>>>>> 
>>>>>  -Lee
>>>>> 
>>>>> (use 'clojure.walk)
>>>>> 
>>>>> (defn subst
>>>>>   "Returns the given list but with all instances of that (at any depth)
>>>>>    replaced with this. Read as 'subst this for that in list'. "
>>>>>   [this that lst]
>>>>>   (postwalk-replace {that this} lst))
>>>>> 
>>>>> (subst 0 1 '(0 1 2 3 (0 1 2 3 (0 1 2 3) 0 1 2 3) 0 1 2 3))
>>>>> 
>>>>> ; (0 0 2 3 (0 0 2 3 (0 0 2 3) 0 0 2 3) 0 0 2 3)
>>>>> 
>>>>> 
>>>>> -- 
>>>>> Lee Spector, Professor of Computer Science
>>>>> Cognitive Science, Hampshire College
>>>>> 893 West Street, Amherst, MA 01002-3359
>>>>> lspector at hampshire.edu, http://hampshire.edu/lspector/
>>>>> Phone: 413-559-5352, Fax: 413-559-5438
>>>>> 
>>>>> _______________________________________________
>>>>> Cs254f11 mailing list
>>>>> Cs254f11 at lists.hampshire.edu
>>>>> https://lists.hampshire.edu/mailman/listinfo/cs254f11
>>> -- 
>>> Wm. Josiah Erikson
>>> Network Engineer
>>> Hampshire College
>>> Amherst, MA 01002
>>> (413) 559-6091
>>> 
>>> _______________________________________________
>>> Cs254f11 mailing list
>>> Cs254f11 at lists.hampshire.edu
>>> https://lists.hampshire.edu/mailman/listinfo/cs254f11
>> --
>> Lee Spector, Professor of Computer Science
>> Cognitive Science, Hampshire College
>> 893 West Street, Amherst, MA 01002-3359
>> lspector at hampshire.edu, http://hampshire.edu/lspector/
>> Phone: 413-559-5352, Fax: 413-559-5438
>> 
> 
> -- 
> Wm. Josiah Erikson
> Network Engineer
> Hampshire College
> Amherst, MA 01002
> (413) 559-6091
> 

--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438



More information about the Cs254f11 mailing list