Sunday, April 22, 2007

Farm News 04-22-07

Sunday morning, after chores, 66°

Bunny and Kitty Adventures
On Tuesday the bunnies and kittens went to school. They visited two classrooms at the school and then went to the day care center for more visiting. They were very well behaved and left no messes behind. By Thursday the bunnies were hopping out of their nest box and bouncing around the cage. They will soon be big bunnies.

Shotgun, the mother cat, has moved her kittens from where they were easy for children to reach to a place that requires long arms to reach them. Silly cat, she doesn't understand that the more children play with her kittens, the more likely the kittens will find good homes.

Bebe the goose is still on her nest, keeping her eggs warm. She usually leaves around 5:00pm to go eat a bit, have a drink of water, and exercise. After twenty minutes or so she is back on her nest, protecting her eggs. Her babies are due to hatch at the end of this month.

After the Freeze
About half of the garden is planted with lettuce, radishes, beets, peas, carrots, onions, potatoes, zinnias, and marigolds. The asparagus is coming back after the freeze. The daylilies look terrible, worse than they looked in February. There probably won't be any fruit this year. The apples hadn't bloomed before the freeze, but the apples have never bloomed or bore fruit. I'm ready to cut them down and replace them.

The flowering dogwood is now covered with brown, crumpled flowers. The tulips that are left are missing half their petals. Enough of the Koreanspice Viburnum survived to bring in a few flower clusters that filled the house with fragrance.

Generating Text
Icon is a programming language developed at Arizona State University by Ralph Griswold. It is a great language for doing things with text. Icon is not widely used, the last time I checked there were two people in Kansas who were on the mailing list, and that was at least twenty years ago. Nevertheless, Icon is what I am going to use, because it fits the task so well.

Most programmers are comfortable with only one programming language and try to use that language for every task. I prefer to use a language that best matches the task at hand. I am not an expert in any language but I manage, especially now that I'm retired.

This task will, at first, be broken down into two programs, one to create data files and the other to use those data files to create travesties. The first, Scan, will go through the text and create a list of ngrams. An ngram is the little two to five character group that is found in the original text, where n is the number of characters. Take the sentence, “See Spot run.” If we set n equal to 2, the ngrams in the sentence are “Se, ee, e_, _S, Sp, po, ot, t_, _r, ru, un, and n.”. I substituted underscores for spaces to make it more clear. Also notice that the period at the end of the sentence is included.

It helps to know that, in most personal computers, a 'line' is a paragraph. The actual length of the line on the screen usually depends on the width of the window in which it is displayed.

I'm going to start with a very simple program, Scan0, which simply copies the original file to another file. This is what the Icon code looks like for that program:

# File: scan0.icn
# Subject: Simply copies input file to output file, one line at a time
# Author: The Geezer
# Date: 04/18/07
#
# file copier, a basis for a text scanner
#
#
procedure main
# Open files
lgf := open("Scan0.log", "w")
inf := open("Sample.txt", "r")
outf := open("Scan0out.txt", "w")
write(lgf, "Files opened")
#
# Initialize the variables
LinesRead := 0
line := ""
write(lgf, "Variables initialized")
# Process lines
while line := read(inf) do
{
LinesRead +:= 1
write(outf, line)
}
# Done! Write the number of lines to the log file
write(lgf, LinesRead)
# Close the files
close(inf)
close(outf)
write(lgf, "Files closed")
close(lgf)
# End of program.
end

In Icon any line starting with '#' is a comment, not a working part of the program. When the program runs, lines beginning with '#' are ignored. So, skipping all the comments, the first line of the program is procedure main(), which is the required name for the main part of an Icon program. The parentheses at the end are for command line arguments, which will be discussed later.

The first job is to open the files for use. A file variable is a name for the place where you put stuff you want to write to the file, or where you go to find what is read from the file. In some programming languages the file name is used instead of a file variable, but that practice can create some problems, so Icon uses file variables. The programmer can use any name he wishes for the file variable. I chose to use lgf for the log file, inf for the input file, and outf for the output file.

First the program opens the log file, with a “w” to tell the program it will be writing the log file. The the input file is opened with “r” to tell the program that it will be reading that file. Finally, the output file is opened for writing. When the files are opened the program writes a note to the log file that the files have been opened. A log file is not required, but it can be a help when something isn't working right and the programmer can't find the problem.

Next the program creates a variable I chose to call LinesRead and intializes it to zero. Because a line is a paragraph to the computer, this will keep track of the number of paragraphs processed. The next variable is line, which is used to carry the paragraph from the input file to the output file, and it is initialized to be an empty line. Notice that the operator := is used to assign a value to a variable. The := is used to avoid confusion with = which is used to compare to variables to see if they are equal.

Now we come to the actual work of the program. The statement while line := read(inf) do tells the program to do whatever follows every time it can read a line from the input file. When there are no more lines to be read the statement will fail and the program will move on to the next statement.

There are two things to do each time a line is read: increment LinesRead by 1 and write line to the output file. The operator +:= is a very handy thing, it tells the program to increase the value in the variable to the left by whatever number is to the right. The write statement is pretty much self explanatory, write the paragraph in line to the file indicated by outf.

Once the while statement has finished, the work is done. The only things left to do are to write the number of lines to the log file, which might be helpful if things didn't work correctly, and then to close the files. Those are simple tasks, and then end is the end of the program.

So, there is a program that does nothing worthwhile, but it works. Next week I'll start changing it to bring it a step closer to the desired program, one that creates a data file for a travesty generator.


To subscribe to receive Farm News by email, unsubscribe, contribute stories, or complain, send an email to FarmNews@GeezerNet.com . The editor reserves the right to steal ideas submitted, rewrite submissions, and sign false names to them whenever it strikes his fancy to do so.



Labels: , , , , , , , ,

Sunday, March 25, 2007

Farm News 03-25-07

Sunday morning, after chores, 66°


Computer Fun

Somehow the bulk mail program I use for Farm News was trashed, along with the data files. I managed to recover about 75% of the email addresses. So, if you don't receive this, blame it on the computer.

Spring

There will probably be baby bunnies in the rabbitry today or tomorrow. This morning Suzette was in her nest box, pulling out fur to make a nice soft nursery.

Shotgun cat is enormous. I have never seen a cat that pregnant before. She is acting a little strange this morning and the tomcats are acting puzzled in her company, so I expect kittens very soon.

The geese are laying eggs and being completely obnoxious. The ganders are so protective that it is difficult to walk around doing chores. The rest of the year they are generally reasonable, but not while there are eggs in the nests. Beth and Bebe each have five or six eggs in their nests.

I purchased 25 newly-hatched Red Sex Link chicks Tuesday and they are in the brooder, eating, drinking, and growing.

Paula cut a cluster of hyacinths and brought them in the house. The entire house is filled with fragrance.

It's spring.

Spring Chores, an excerpt from Suburbia, by Dr. M.

March is upon us in New Jersey and here that means the odd errant snow storm followed by 50 degree days that make one itch to clean, plant and renew. Thus, my husband and I embarked on our spring projects; to seriously start composting (happily started last fall with the leaves), to paint our bedroom, and to update the lighting in the house. Further projects will follow once these are completed.

Last weekend it was lovely and warm for this time of year so we started cleaning up the yard and organizing our composting efforts. Because our German Shepherd dog spends her days in our back yard, any substantial work outside must start with removing the copious amount of poop therein. Medchen weighs 90 pounds and has a lot of fiber in her diet; so really, the poop is something to contend with. We wish we could do something useful with it, but, hygiene dictates that the offending material be deposited in the trash. That chore over, we attacked the day’s garden task.

First was to address the dog house on the property. Medchen doesn’t use it because it’s in a side yard; also it sat upon the parcel upon which I wished to grow vegetables. We put it on Craig’s List for zero dollars if someone would come and take it away. A bargain at twice the price we figured. We did not figure on how heavy the thing was. The previous owner of our house was very handy, and built things to last, for which Andrew and I are profoundly grateful. We neglected to consider that he built the dog house patterned after one of the cheap ones at Home Depot, but, considerably more sturdy; with a lot more wood, and many more nails, and real shingles. It weighed a ton, and Andrew and I could not lift it. We modified our posting and we still had a willing customer. Andrew tells me that removing the dog house involved backing a trailer into the back yard. I don’t know, I was at work but it sure sounded tough. And with the dog house gone, we could commence preparing the bed for the garden. Of course, the next day we got 3 inches of snow, sleet and ice. Thus, we directed our energies indoors.

Our bedroom had not been painted since the Bush père administration, and the lines and the cracks on the walls matched its age. So, we moved things out, emptied the closet, taped to within an inch of our life, and moved in the ladders. When the emptying was over, all that was left was the king size bed and my dresser. With plenty of swearing we moved the mattress out of the room and put a drop cloth over the rest. We are moving up in the world because this time we invested in the nice canvas drop cloths that actually stay where they are put; a miracle to be sure. Then came washing the walls, which I think just spread the dirt around. With our preparations done we started painting.

Andrew started on the ceiling, and I started on the closet. You learn a lot about house construction painting, like where someone did not quite grasp the concept that the walls are supposed to meet the floor, and that orthogonal means at true right angles, not just a close approximation. We marveled at some of the construction, and laughed at other portions. We sang to the radio and painted. We both got paint in our hair and I think Andrew still has paint on his glasses. We argued some during the process, but mostly had a good time. And the results are fabulous. We’ve gone from a room that looks like a wrinkled old man, to one with smooth skin and bright energy; a lovely transformation.

As I write this looking at our lovely walls, Andrew is reading about wiring for our next project. We are going to install our own ceiling fans and track lighting. Another adventure in home-ownership waits!

Off to the Races

The race is between intellectual property software and open source software. Recently, I have realized that open source software fits the requirements for a Darwin Machine, an idea from William Calvin. Here, in his own words, are the six essential requirements for a Darwin Machine:

1. There must be a pattern involved.
2. The pattern must be copied somehow (indeed, that which is copied may serve to define the pattern). [Together, 1 and 2 are the minimum replicable unit -- so, in a sense, we could reduce six essentials to five. But I'm splitting rather than lumping here because so many "sparse Darwinian" processes exhibit a pattern without replication.]
3. Variant patterns must sometimes be produced by chance -- though it need not be purely random, as another process could well bias the directionality of the small sidesteps that result. Superpositions and recombinations will also suffice.
4. The pattern and its variant must compete with one another for occupation of a limited work space. For example, bluegrass and crab grass compete for back yards. Limited means the workspace forces choices, unlike a wide-open niche with enough resources for all to survive. Observe that we're now talking about populations of a pattern, not one at a time.
5. The competition is biased by a multifaceted environment: for example, how often the grass is watered, cut, fertilized, and frozen, giving one pattern more of the lawn than another. That's Darwin's natural selection.
6. New variants always preferentially occur around the more successful of the current patterns. In biology, there is a skewed survival to reproductive maturity (environmental selection is mostly juvenile mortality) or a skewed distribution of those adults who successfully mate (sexual selection). This is what Darwin later called an inheritance principle. Variations are not just random jumps from some standard starting position; rather, they are usually little sidesteps from a pretty-good solution (most variants are worse than a parent, but a few may be even better, and become the preferred source of further variants).

In the case of open source software the patterns are the individual line of code, which I will suggest resemble, from this viewpoint, genes in biology. As in biology, lines of code are copied, usually in the form of large, interacting collections of patterns, similar to the populations of genes which make up organisms.

Intellectual property software is now built upon the Microsoft foundations: enormous blocks of code and machines for creating code, all of which are considered to be intellectual property. Windows, the base upon which all this is built, is probably the most complex machine ever devised by humans.

Open source software is built upon Linux: enormous blocks of code and machines for creating code, all of which are considered to be public property. My thesis is that the open source software 'commons' is, in itself, a Darwin machine. There are no individual programmers in the open source community who are essential to the continued existence of that community. Open source software attracts programmers who, because they feel pleasure from doing so, will create new parts and pieces in the universe of open source software.

The multifaceted environment of open source code is the internet and all the computers attached to it.



E-mail Subscribers: To subscribe, unsubscribe, contribute stories, complain or send a gift subscription, send an email to FarmNews@GeezerNet.com . The editor reserves the right to steal ideas submitted, rewrite submissions, and sign false names to them whenever it strikes his fancy to do so.


Labels: , , , ,