Dear George,

George Rudolph wrote:
I suppose some of the reasons the code may be confusing are the
following:

1. I was creating only one list of domain variables (Histogram), instead
   of using two Lists (Histogram and a shifted copy of Histogram). This
means writing the constraints for the shifted copy in terms of indexes
in the original list.
I thought that doing this would save space, and I wasn't sure that
shifting domain variables in a list, the way you show in the code below,
would work the way I expect. Apparently it does, which is good.

Actually creating a list with the shifted elements is cheap, because that list is used once by List.zip, then it is no longer referenced. This list is not copied when the spaces are cloned by the search engine, for instance.

2. I'm not computing and constraining the shifted dot product just once,
but actually computing/constraining a sequence of shifted dot
products--that is,
the product of Histogram and Histogram shifted once, the product of
Histogram and Histogram shifted twice, and so on, up to
(length-of-Histogram) - 1 shifts.

This version of the code is more like what I want, though it
doesn't seem to work, in that no solutions are found
when I call it with

{Autocorrelate Count (2*T - 1)}

It fails with a red square, as opposed to a light green diamond.


---------- begin code ------------------
proc {Autocorrelate Xs Val}
     NumberOfShifts = {List.length Xs} - 1
 in
    for I in 1..NumberOfShifts do
       %rotate the list Xs by: splitting the list at position I
       %then slicing the list back together with the parts swapped
        CopyOfXsRotatedISlots={Append {List.drop Xs I} {List.take Xs I}}
        Matches={List.zip Xs CopyOfXsRotatedISlots fun {$ X Y} X=:Y end}
     in
        {FD.decl Val}
        {FD.sum Matches '=:' Val}
        {Browse Matches}
        end
end

George, you are constraining *all* the shifted dot products to be equal to Val. Is this what you meant?

You can make Autocorrelate return a list of the products by using the 'collect' feature of the for loop as:

fun {Autocorrelate Xs}
   NumberOfShifts = {List.length Xs} - 1
in
   for
      I in 1..NumberOfShifts
      collect:Collect
   do
      %% rotate the list Xs by: splitting the list at position I then
      %% slicing the list back together with the parts swapped
      CopyOfXsRotatedISlots={Append {List.drop Xs I} {List.take Xs I}}
      Matches={List.zip Xs CopyOfXsRotatedISlots fun {$ X Y} X=:Y end}
      Val
   in
      {FD.decl Val}
      {FD.sum Matches '=:' Val}
      {Collect Val}
   end
end


I hope this helps,
raph

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to