Friday, June 24, 2011

Simulating Genetics at the bit level

Early in my programming years I had an instructor who recommended the book about simulated artificial intelligence titled Genetic Algorithms in C++ by Scott Robert Ladd. Computer programs are coded to perform in predefined ways like displaying output based on what a user entered, or calculate digits based on solid mathematical principles. In short, programs are coded with the specific actions the programmer decided in advance - there is no deviation.

Genetic Algorithms (GA) allows a programmer to define a set outcome - that's it. The concept of GA allows the program to figure out how to accomplish the outcome in the most efficient way. Some examples would be an outcome to figure out the optional setup to allow five trains to efficiently utilize the same set of tracks, or an outcome could be a finish point located randomly on a maze created for a mouse - the program would not only have to figure out the optimal movements from start to finish, but would have the extra tasks of figuring out first that a mouse needs to be able to move (somehow), realize that a mouse has four legs (the programmer didn't tell it what those legs were for), and then teach itself how to make those four legs work together in an optimal fashion.

Let's look at this mouse maze issue a bit more and tackle each section in more detail; there's a lot of GA ideas that can be discussed using the mouse maze scenario. Working from the beginning, let's look at the mouse maze issue. Here we have a maze with a starting point and the goal is to find the finish point in the most expedient way possible. in a non-GA program, the programmer might write code that defines a rule to solve this maze problem. I would probably write code that says to start the maze by moving right until a wall is encountered, then turn 90 degrees and continue trying to move right. Eventually this program would solve the maze. This isn't efficient. GA allows mini populations of mice to wander the maze for a certain length of time. The top mice to go the furthest would (programmable) breed and their offspring would continue on adventuring until generations later a single mouse makes it from start to finish without any misstep. Keep in mind that these mini populations are like thoughts, and it isn't until the single mouse succeeds that an actual "real" move is made.

Now we have the additional issue of learning that the mouse has four legs. A normal program would have instructions for using all four legs to move the mouse along the maze. a GA programmer would not bog down the program with this information. Perhaps for this particular maze, a mouse that moves its body in a snakelike fashion is better than using four legs - who are we as programmers to decide this?

One of my last accomplishments as a programmer was to write a GA System to simulate an ant colony. Using the Java programming language I created ant objects with specific methods for movement, searching, acquiring food, and a detailed method for ants to leave pheromone trails for others in the colony to follow. I created a maze object based on random parameters - complete with start and finish locations, and randomly added in food sources for the ants to find. So what I had created was a maze environment for ants to explore. The main goal was to find the shortest path from start to finish, and to use the located food sources to sustain the ants that ventured further from the colony in search of the finish point. If you're wondering how this complicated program differs from a simple, brute force program for finding a finish point, well here's how GA shines. Let's say that we give each ant a 10 movement limit before it expires with food sources found in the maze adding 5 more movement allotments. Ants in the brute force program would expire quickly due to the unnecessary backtracking taking place, and especially so if the food sources were far and few between. A GA program would virtually send out ants to find the finish point. The ants making it the furthest would be selected to mate ( programming for mixing or combining actual bits of data to create offspring with inherited traits from both parents. Essentially the offspring will know more about the maze that any single parent learned. Again I stress that no computer ant has actually moved in the maze. Over generations of progressing offspring learning more about the maze, eventually a super generation will be created that has the information to successfully traverse the maze from start to finish without expiring. Once a solution is found, as defined by the programmer, the GA program will create an actual ant to make the trip with the foreknowledge of how to succeed.

Deion "Mule" Christopher

Saturday, August 14, 2010

The Logic in Studying Logic

Recently I got my hands on the book, 'How to Win Every Argument: The Use and Abuse of Logic' by Madsen Pirie in the hopes of brushing up on logic. I read the opening pages to get a feel for what was in store. Mr. Pirie wrote,

"This book is intended as a practical guide for those who wish to win arguments. It also teaches how to perpetrate fallacies with mischief at heart and malice aforethought. I have described each fallacy, given examples of it, and shown why it is fallacious. After any points of general interest concerning the history or occurrence of the fallacy, I have given the reader recommendations on how and where the fallacy may be used to deceive with maximum effect."

What a unique way of teaching logic! Never before have I come across a book that teaches logic by showing how to use fallacies to win arguments; every book I have studied has broken down arguments into individual parts to show how to argue properly while avoiding fallacies. For a quick reference of the books I have read:
  • 'Sherlock's Logic' by William Neblett
  • 'Critical Thinking: A Concise Guide' by Tracy Bowell and Gary Kemp
  • 'Logic and Contemporary Rhetoric: The use of Reason in Everyday Life' by Howard Kahane and Nancy M. Cavender
  • 'A Rulebook for Arguments' by Anthony Weston
and numerous electronic and computer programming books that covers the use of logic gates and using logic in artificial intelligence (AI) programming code such as:
  • 'Genetic Algorithms in C++' by Scott Robert Ladd.
So why study logic? The three obvious reasons are to argue effectively, write proper arguments, and to write programs accurately. Actually there are many reasons to study this subject. In fact, I was drawn to logic to prepare myself for the career path I had chosen so long ago.

From the age of 10 I have been working with computers. In this day and age this is pretty normal, but if you take into account that when I was 10 years old it was 1983, and the fact that computers were very hard to come by, and books or instructors were virtually non-existent, you will undoubtedly see how this was a momentous feat for such a young guy. At any rate, what started out as a fascination and hobby, eventually turned into a career path that lead me out of high school and into college, placed me onto the Information Technology career path, and ultimately sent me back to college for a graduate degree. The moment I realized I wanted to take this career path (I initially set my focus on Botany and Forestry), I started studying logic in hopes of scoring high on the ACT, GRE, and intelligence quotient tests. Although I haven't read any books devoted entirely to the use of logic in mathematics, in truth, logic is universal and can be applied to any area of study.

Today I study logic for the joy of it. I find it amusing listening to friends and coworkers arguing on matters of unimportance (why so-and-so on a reality show should win) to topics that affect our lives (Presidential elections or investment management). I like standing back and chuckling to myself as I pick apart the premises being forwarded in support of conclusions.

If you are interested in finding out what logic is all about, then I would suggest you do a Google search for Lewis Carroll's book mentioned above. There are undoubtedly other free, online logic books that Google will offer, but keep in mind that the free books are somewhat dry and boring. If you still find the subject intriguing, then you should check out the list of books I have provided in this post.

Deion "Mule" Christopher

Sunday, February 22, 2009

HAM RADIO - New Technologies, Same Fundamental Principals

I scored a plastic bag worth of free HAM-related books on a recent visit to the local public library. The books and magazines were free due to the publication dates ranging from 1965-1985.

Thumbing through an FCC self-study guide I recognized similar test questions that appeared on the Amateur Radio Technician test I took in 2004. Questions covered were over electronics theory, radio wave propagation, FCC rules/regulations, and antenna design. Amazingly the information was just as relevant today as it was 20-40 years back.

I started reading an Amateur Radio Novice examination book and found the electronics theory sections to be very well written and easily understood. It was literally a sense of nostalgia reading dated material on the Novice license which is now obsolete. I found the illustrations and electronics explanations to be very enlightening. This is coming from someone who has read countless electronics books (GE, ARRL, IEEE, DOD, Naval, and Air Force manuals). I concluded that this book was written for readers with little to no electronics background. In other words, the material was presented in a way to educate inexperienced readers on electronic ideas - the likes of which they had never seen or heard of. I'm talking about foundational information.

Here's an interesting observation: one magazine booklet (CQ Magazine) had articles that were relevant to today's HAMS. For example, I read of a California HAM who received a permit to erect a 50 foot tower, but the city later recanted it after a majority of the community opposed the permit. Turning to today's headlines, last month's QST magazine (printed by the ARRL) ran an article covering a HAM who had received a tower erection permit that was later recanted after neighbors complained. The ARRL was planning to provide legal and financial services to fight the city.

Another article I read, and that hit closer to home, was on the playing of chess over the radio (73 Magazine). I had written about radio chess over on QRZ.COM and even supplied rules that I had collected from yet another HAM a few years back. It was refreshing to see that my ideas were shared by HAMS whom I consider to be pioneers of radio.

And for my final example, there was of course a two-page spread (CQ Magazine) detailing how a heroic HAM assisted in locating and medivacing a sick person from another country. This ties in with a recently well-publicised story of a mountain hiker who had fallen and broken his leg. Luckily the hiker was a HAM who had his QRP rig with him. He used Morse code to contact another HAM and request help. This other HAM was located in another state and relayed information between the injured HAM and the rescue teams.

I guess what I am trying to convey is that when you become a HAM it's like being inducted into a prestigious group filled with brilliant men, women, and even children who share in the same successes, frustrations, insights, and nostalgia of everything that is encompassed by HAM radio. This happens because the foundation of the group is based on rock-solid laws and theories in electronics. So while the equipment and components mature (or shrink for that matter) over time, the understanding and knowledge to use, make, and understand them will always stay the same.


Deion "Mule" Christopher

Saturday, January 31, 2009

Become a Linux Server Wizard Part 3

Last night, as I was fading off to sleep, I noticed my router's green activity lights dancing in the darkness. My mind slowly came to life as I contemplated the various reasons for the network activity on my home network. "Probably I forgot to initialize sshdfilter the last time I rebooted my Linux web server." "Maybe I left the MySQL daemon running two nights ago and someone is attacking my database." The thoughts kept surfacing as the non-synchronous green lights lulled me off to sleep...

The next morning I remoted into my web server and checked the logs. A remote scanner found my port 22 responding, and there were hundreds of failed login attempts. This is a good point to stress the importance of VERY STRONG PASSWORDS!

The sshdfilter was not running as I suspected. It was one of those things that was on my to-do list, but oddly enough other projects kept jumping ahead of it.

This experience had me thinking up various ways of truly protecting my Linux system from unauthorized users. That's when I remembered an article I read a while back in a Linux magazine. The topic was how to secure a system with port knocking. The idea of port knocking was to have predefined ports turned off as an initial state. The client wishing to access a certain closed port would first send a single TCP or UDP packet to various other ports in a specific sequence. Correct "knocks" would open the needed port for access. When through, the client would send another set of "knocks" to close the port down. Port knocking essentially hides ports from scanners, since the ports are actually closed, yet are assessable to clients when needed.

After a quick Google search I found knockd. Its command page looked easy enough to figure out, so I decided to give it a try.

We will begin this project by resuming our work from the Linux System we have used in Parts 1 and 2 of 'Become a Linux Server Wizard':


  1. Type urpmi sshd knock to install openssh and the knockd port knocking package
  2. Type cp /etc/knockd.conf /etc/knockd.conf_original to save a copy of the original knockd config file in case we want to use it at a later date
  3. Type vi /etc/knockd.conf to edit the config file in vi
  4. Under the [options] heading you should type interface = . I typed interface = eth1 because that is the network interface that my virtual Linux system uses. I believe that If my system had used eth0 the knockd dameon would have worked without the need for the interface line
  5. Under [openSSH] you need to change the three sets of numbers on the sequence line. Leaving the number sets as they are would leave your system vulnerable to attack. I set my seq_timeout = line to 10. On the command = line you need to delete the iptables entry and then type /usr/sbin/sshd to bypass the whole iptables modifications. This command will start the sshd daemon for you to ssh into your system remotely
  6. Under [closeSSH] you need to change the three sets of numbers on the sequence line. Again you do not want to leave your system vulnerable to attack. I set this seq_timeout = line to 10 also. On the command = line you need to delete the iptables entry and then type /usr/bin/killall -9 sshd to once again bypass the iptables modifications. This will kill the sshd daemon to close the ssh port down
  7. Press the [Esc] key followed by the [ Shift + : + wq ] and press Enter to save your changes and exit the vi editor
  8. Type service sshd stop to ensure that sshd isn't running
  9. Type chkconfig sshd off to keep sshd from running at boot
  10. Type chkconfig --add knockd to run the knockd daemon as a service on boot
  11. Type chkconfig --level 2345 knockd on to change the runlevel of the knockd daemon

You are now done with setting up and configuring port knocking on your Linux system. The next step in the project is to install and use a client to "knock" on your predefined ports and then ssh into your system remotely.

  1. Download your proper OS port knocking client from: http://www.zeroflux.org/cgi-bin/cvstrac.cgi/knock/wiki
  2. In this instance I used a Windows Vista machine to test my port knocking, so I downloaded the Win32 client software.
  3. I clicked on the START button, typed CMD in the search line and hit Enter
  4. I used the CD command to traverse the folder structure to where the knock.exe file was located
  5. I typed knock.exe 3000 7100 7500 and hit Enter. I immediately used Putty to ssh into the same IP address and port 22. I received the login prompt which indicated port 22 was open, and thus the port knocking was working
  6. I disconnected Putty and in the DOS window I typed knock.exe 7700 3500 7150 and hit Enter. I immediately used Putty to ssh into the same IP address and port 22. I did not receive a login prompt, and a short time later I received a connection timed out error
  7. I performed the last two steps again to verify that port knocking was working properly



Deion "Mule" Christopher

Sunday, January 18, 2009

Become a Linux Server Wizard Part 2

This entry is derived from a conversation I had with a local animal shelter owner who was having issues with a branch office employee. The employee initially set up the shelter's PetFinder account. The main issue was that this owner was left at the whim of that employee when it came to updates on the PetFinder account. Every so often the employee would make updates, but only for certain branch offices (actually all of the branches except the owners' location). Futhermore, this employee had the username and password for the account and was balking at giving it to the owner when requested. When pushed, the employee threatened to quit.

It took me a couple of days to work out a game plan for this owner. My goals were to have a system in place that would allow automatic account updates to PetFinder. The shelter needed an easy to learn GUI for employees at each branch to use (uniformity is a good thing with data management). The shelter needed a reliable database backend that allowed simultaneous database access for both the primary shelter and its branch offices. This project obviously needed redundancy with an automated backup scheme. Because animal shelters run on donations (money and equipment) they tend to rely on poor machines. By poor quailty I mean the workstations and server would be low-end systems with faulty hardware that the origninal owner replaced with a new unit.

Linux was the operating system of choice for cost reasons. Since I would be using Linux I figured MySQL was the database to use because it met the requirement of simultaneous client access.

I must confess that I already had a front-end in mind when I started planning the project. At my former job I researched Animal Control software for a police department. That research turned me onto Animal Shelter Manager which I knew would fit the GUI requirement.

The last requirement was a redundancy scheme. Again I was in luck with my choices of Linux for the operating system and MySQL for the database. With a couple of scripts I could easily perform a nightly backup of the database and store extra copies off site for further protection.

All that was left was to work out how to tie all of this together into a seamless package. I read most of the entries on the ASM forum and found that quite a lot people were having issues with setting their systems up for remote client access - so much so that on practically every thread there was one or more postings offering to host sites for a fee. My thought was if these money-hungry buggers were able to setup remote client access then by golly I would figure it out too!

Three days later I had a Linux server running MySQL and a fully functioning Animal Shelter Manager database with three remote users accessing the data.


Using the Linux System I created from my last posting (ProFTPd server), here's how I completed this project:



Log into your Linux system as root and Type urpmi mysql to install Mysql on your system

Type vi /etc/my.cnf at the command prompt to open my.cnf in vi for editing

Type /skip to search for the string skip networking. If it isn't on the first result then type n for the next instance of the word

Press the [Shift+I] keys or the Insert key on your keyboard, and with the cursor in front of the words skip networking, place a # sign (Shift+3 keys) in front of it. The # comments out the instruction

Press the [Shift+:] key to leave Editing mode, and then type wq then hit Enter to write your changes and exit out of vi

Type service mysqld restart to restart mysql with the new change you made to my.cnf (you are now allowing network access to MySQL)

Type mysql at command prompt to enter into MySQL> so you can enter SQL commands

Type SET PASSWORD FOR root@localhost=PASSWORD('rubberchicken'); to set a MySQL password for the root user - place your prefered password in place of rubberchicken (DON'T LOSE THIS PASSWORD! Resetting it is an option, but it's a darn lenghty process to do)

Type create database asm; to create a database for the Animal Shelter Manager data

Type quit; to exit the mysql command prompt

At this point you could type mysql -u root -p and type at the prompt the pssword you replaced rubberchicken with in the command above to test it out. You can type quit; to leave MySQL

Type mkdir /var/src to create a folder to store your tar files in.

Type cd /var/src to move into the new directory

Type urpmi lynx to install a text-only web browser. We will use this to download the ASM package to your system

Type lynx http://downloads.sourceforge.net/sheltermanager/sheltermanager-2.3.5_i386_linux.tar.gz

Hit D for download, press the down arrow to highlight Save to Disk, hit enter to save the file to disk, and hit enter again to save the file with its default file name.

Type tar -xzf shetlermanager-2.3.5_i386_linux.tar.gz to untar and uncompress the downloaded file in the current folder (/var/src)

Type cd /var/src/asm/data/sql and press Enter to move into the sql folder

Type at the (NORMAL) command prompt mysql -u root -p asm '<'mysql.sql and press the Enter key. You must type in your MySQL password when prompted. This command will populate your previously created asm database with the necessary tables and fields from the mysql.sql file

Type mysql -u root -p and password when prompted, and then type grant all privileges on asm.* to 'ferdenand'@'%' identified by 'royal1'; and hit Enter to allow remote access to the asm database from this particular user. Be sure you replace ferdenand with whatever username you like and also chance royal1 to an appropriate password for that user. Repeat the grant statement with other users and passwords if you wish for branch offices. Also note that this username/password combo is only for remotely connecting to the asm database. the asm software that will be installed on the client machines will require unique username/password combos for access for each user at each shelter site.

Next step is to create the redundancy segment of the project. We are going to rely again on sourceforge for the answer:

Type cd /var/src to move into the new directory

Type lynx http://downloads.sourceforge.net/automysqlbackup/automysqlbackup.sh.2.5

Hit D for download, press the down arrow to highlight Save to Disk, hit Enter to save the file to disk, and hit Enter again to save the file with its default file name.

Type chmod +x automysqlbackup.sh.2.5 to make the file executable

Type mv automysqlbackup.sh.2.5 /etc/cron.daily where it will be ran automatically each day

Type vi /etc/cron.daily/automysqlbackup.sh.2.5 to edit the file

Edit (at least) the following lines:

USERNAME=root (The user must have at least select privileges to the databases)

PASSWORD=yourrootpassword

DBNAMES="asm"

BACKUPDIR="/mnt/automysqlbackup"

Save the changes and exit the editor

Type mkdir /mnt/automysqlbackup to create the archive folder for your daily, weekly, and monthly database backups

You are done, at least as far as the server installation portion goes. The next part of this project is to install the ShelterManager software on a remote machine. Here's what you need to do:

Download the ShelteManager software for your operating system (I will assume this will be on a Windows OS machine)

Install the ShelterManager software

Double-click the Animal Shelter Icon on the desktop to start the program

Choose English at the first window (if that is your preference)

Choose MySQL as the database

Type the IP address of your Linux system in the host field

Type asm for the database name

Type ferdenand for the user and royal1 for the password


OK, at this point a lot of people have issues with not being able to connect to the remote MySQL server. Here is the sollution I found through trial & error:

Click Cancel on the database window. This will bypass the remote MySQL access and instead set you up to use localhost.

When the second window pops up asking you to log into Shelter Manager, simply close the window to get out of the software.

Do a search for a jdbc.properties file and edit it in notepad

Delete the entire JDBCURL line and replace it with the following:

JDBCURL=jdbc:mysql://yourLinuxSystemIPaddress/asm?user=ferdenand&password=royal1&characterEncoding=UTF8

Save the file and restart the ShelterManager software. Hopefully all will go well and you will receive a login screen.

Type user for the username

Type letmein for the password

As a final verification you can hover your mouse pointer over the middle icon in the bottom right corner of the window - the icon looks like two stacks of gold coins. A bubble should pop up showing mailto:MySQL@yourLinuxsystem.




Deion "Mule" Christopher

Saturday, January 17, 2009

Become a Linux Server Wizard

How does a person become proficient at the Linux operating system? I asked a friend that once. He was a "Linux Guru" if ever there was such a person. His answer was simple, "I've been using Linux for years." I understand that statement now. With roughly ten years under my belt I can profess that I am a "Linux Geek"; I'm just below Guru status.

So tonight I was thinking about what to write about, or what could I do to help others with the Linux operating system. It struck me immediately. Why not demonstrate how to set up a Linux system on which a person can build a server, test it out, and add other servers to it!

My first attempt went pretty well, but you can be the judge. The Linux system I suggest doesn't have a GUI - everything is command line. The servers are installed in random order to eliminate any type of "cookie-cutter" configuration. However, we will be basing a lot of configurations off of such a "cookie-cutter" system (http://www.howtoforge.org/perfect-server-mandriva-2009.0-x86_64).

Our first project is to set up a Linux system and build an FTP server on it. I am using VMware on a Windows Vista system because I have no spare machines at the moment. This system, as I stated earlier, will have no GUI. We will do everything "command-style" to ensure a better understanding of the Linux system.


Let's begin!


1. Download mandriva-linux-free-2009-dual-arch.iso (Google for it)

2. Continue the installation, but follow the screenshots I am providing:




3. Uncheck all package group selections and hit next

4. Accept the default of "With basic documentation (recommended!)". Be sure you choose normal security or you will run into trouble later on as we progress through upcoming projects!

5. urpmi drakxtools to ease administration of the server using the commandline

6. urpmi mlocate to ease administration when searching for files using the commandline

7. updatdb to build index of files on system for the locate command to use

8. vi /etc/cron.daily/software_update to create a script to update and auto install updates daily

9. Type and save

  • #!/bin/bash on the first line
  • urpmi.update on the second line
  • updatesurpmi --auto --update --auto-select on the third line
10. urpmi proftpd to install the ftp server

11. vi /etc/proftpd.conf to configure the ftp server

12. Change ServerName "Your Servers Name or whatever you want it to say"

13. Uncomment DefaultRoot ~

14. Add IdentLookups off

15. Add ServerIdent on "FTP Server Ready."

16. Comment out all of the Bar Use Site CHMOD by default entries

17. service proftpd restart

18. Use your prefered ftp program and connect to your new ftp server using the username and password that you used when installing the server

19. Create a new folder and copy a file into it

20. Traverse into the users home directory and verify the folder and file are there

21. Delete the folder and file

22. Disconnect your ftp program.



Deion "Mule" Christopher