Search

Geek Girl Joy

Artificial Intelligence, Simulations & Software

Month

October 2017

A Halloween Tale

Happy Halloween Everyone!

Sorry I haven’t been posting  lately, I’ve had some pressing personal business to attend to and I also had another computer failure… :-/ which has been a setback.

In anycase I had planed on releasing an animated crystal ball for you guys to play with but it’s on my old hard drive and I haven’t pulled it off yet so I will have to release that later however I didn’t want to leave you guys hanging, so I wrote a machine learning n-gram probability model (specifically bi-grams )  in PHP no less! 😉 and it sort of knows how to write a story similar to what you train it on… kinda.

Seeing as how it is Halloween I thought it would be fun if I trained the model on these three books and then see what happens:

 

What follows are the thoughts of the bot, please enjoy.

This story was written by a bot


Monster on my tale.

I asked more than ever, “Close the door!” I said with impunity the motions were compassed round the union. My admiration at the grandness of the room, where the same time be exhausted.

Well, guv’nor, armed and with a few minutes of our fine weather, all the winds.

Beyond was a bullet did you know that? He made the attempt to conceal it though it appeared vividly coloured. It was a fearful ordeal before twelve!

I enjoyed the brightness of which has taken refuge in one there.

The fiend doth walk on.

I descended upon an hour, and your hand, gave out, he put him to it to notice that devil who, born and bleak in appearance of Buda-Pesth.

“I regret the preceding night. The fair way to the whole face which soon obtained was I awakened various chances of the bottom of his palms together in the steps up those sympathies necessary for a rush out any circumstances. indeed, after a pause to attack the east.”

“What is a few jewels when they persuade me? What I had been imbued with was horror. The oppressor!”

In spite of a great many of them being in dress were rambling in inaction; his history; “he will be hurtful to you.” he spoke, “But I have child-brain”, and Then things which time we did, and I found myself alone with the pain of the captain and with the engineer.

The arm in his observation. Then the sea at a distance.

The night be convenient for reflection, which would be about five yards in a perfect kaleidoscope of the sea and shells beside him, I saw him with a metal tube.

Whatever tongue through the cold was warmed up as to the various ways.

Then looked upon a flash of our permit to him to great part of anything in the level of the matter, and, strange chances of all the sensibility of the ice-bed by these words of waking.

Thoughts were with each one, I had been drunk as it is and I set me to look for the Professor near the cottage of these mountains like a bright visions on board.

A large light, our dead where they were flickering blue flame was nothin’ else in fact, and we both bitterly irksome and sweet responsibilities I had been cleared his lordship by night I am an interview with all to be fulfilled; But they opposed themselves justified in the sea.

“Indeed?”, “Yes, and feel easier”; But I was was frozen—even the captain, I know neither dawn was either side of the fair woman he not despond.

September 9th, the same solitude. My cousin, There is still struggled up to a heavy odour itself, While in a man a definite way. I fancied this to his arrival- on land, at other woman was to the last to them as I cast anchor at once for the Island with real grief or fifteen fathoms in a diversion, little recovered from Europe had been here.

I repeat, the surface, and picturesqueness of the upper coloured stuff you to which gave you are all papers without me. I drew his quiet moon. I know something like an impulse the species, your long-voyage steamers, which of the window or rather fancied rage sinks again believe that he spoke as before, though he altered spirits, and brown belly, silvered and rapid in solitude. My own exertions.

You may not all our door opens up to stake. Not frighten me! Be rewarded with my boots!

Almost recovered, but there in all my very soul to me:– “Ah, Professor!” cried Ned this blackness, and which lay motionless, and again. The angle of these we ran back the early autumn seemed to go down the “sleep well,” replied.

The Captain was unprejudiced and leg-ironed, even now he said, “to enter upon its strange things which the body, “Is counsel was awakened to the steps, to teach us”, poor dear, as imposing and she looked at my great frowning precipices of bunting carried on her repentance.

She began: “We have had a basin of William and well ahead of escape? But it up; for, seeing the tropical zones, where these strata was the poor Lucy”.

Here we stop him. It should happen. If she fears crowding the undertaker, true Yorkshire coast. We go through the possibility of the strength is not smoked for her head—poor little boat took out of dexterous hunter’s as nothing, The sight of my last look that I shall be surpassed by the red sunset come, for a dog growls over his own, but spent more bearable.

Letter from the high boots. As the heart beat like bristles on board my imaginings were they had nearly elapsed since we may ultimately turning up my former occasion, but when I was lost.

He would still lie. I need. “I am unwilling to be alone with a hand harder, and escape”.

Several varieties of coco-nuts on the moon had the brink of the infinite fatigue, “sir?” said Mrs. Westenra, “has left out of the occasion, but deserted”.

“I am inclined to be made. We have every time for my maker.” his doings ever has an anxiety and in the flycatchers of the iceberg was for the lowest receptacles of the driver saw the dining-room, opened, and I feel myself away to such as we were so had three yards long.

In Dracula’s tomb it is nothing more than red sunsets open into Namouka, one might have no torture when he was as he hastened that light from the braying of our excursion to say. Your thoughts; he was oppressed me.

But For To-night play us, bright days on board, but by the speed of the cause might view to London, “we can come to join my fellow creatures often seeing me, dear, dear Frankenstein,” exclaimed the time. “We can try.”, “Thank you, that worthy fellows whom I pursued him”.

I could demand an eager desire of my doom; I could hardly know I got well herself, and console you; I repeat my mind. My delight to comprehend most that I replied in any good, But in discerning the mountain tops, and feelings, But Captain Nemo; and to lie in everything, and the favor us, and Guadaloupe from this stake we knew him that he held his indignation. “Confound it!”, “Under it!” “but What went on the utmost expedition. “Then There is a good God and affection”!

Captian answered with a madman. The head of your Lordship’s wishes the old man. Not stinted. is this. If by the fine gradations from each other, and foretells the Mediterranean. The respect for one should pass round me, like the dawn, there was happy and he came like a depth of a soul, and If he who solicited their calcareous reflections during a manometer.

Frankly, lest I looked at random, too late.

Aristotle has often used that the corpse of the open the frigate. The grim and pleasure. “You have been prepared your former times he must soon returned, and, surprised me like any sort–no matter For the dangerous relapse. alas! who sickened me.

To the life and the earth, nor of me to harness at the most unnecessary proceeding it is in favour I felt shut out of the evil pervaded his bad weather.

Passed away from his promise, I confess to speak, even that you think?”, “Believe me, so sad and the hearts must go on her, Arthur my two thousand years.

His room was coarse but he was calm. I might have no friend Arminius, and he performed the rising tide; and said:– “to my dear Lucy always be in the sea, since your mercy he would suspect that horrid experience already–and you, my diary”.

You medical science took him waiting; so WANT you will be nearing them. My eyes and said:– Dr. Van Helsing never mention it, But as her place.

The day’s journey to my crimes, and I was tall black veil. Agatha entered.

She has been at him in the waves beat as we have hitherto How can Henceforth dearer considerations. after SOME suspicion.

Later, Lord Godalming suddenly my shoulder, a clever lady!” said that I found a great nerve. I had taken of course a considerable change to which I was tolerably patient, sleep which a blessed in more on carrying at any change of hope.

I have run cold, and you, Jonathan, For anything. Then, without this little chance gone, But in the doctor will be welcome, Mr. Renfield.

I looked in the streets. I believe in some plan as was the Thames, and discharged in revenge, withdrew.

Renfield seemed to recover my memories of the steel cigar.

The Ocean, sometimes simply went away towards the supplementary reservoirs, closing in. An hour passed, and all seemed to make.

It must go on.

Once more I can do as Omnipotence–and I did not suffer the inclination for delay, the arch-fiend, bore himself with the Roumanians, came to deceive me. I asked what it was, the snow as bare trees all seemed altogether, drawn down his death.

You saw already, in the afternoon, the starting-point in a Land had suffered through his coffin-home, his goodness that you are Such spiritual pathology, and low, ‘im as possible.
I have already noticed this island. “An iceberg!” said resolutely.

“Let us lay the Professor Aronnax to cross on a fire on my record have begun to think. Let him to this State of the undulation of dishonourable peace; and ward till death–a steadfastness as time when we could communicate simultaneously.

Three o’clock we had finished the morning in the country.

I had been here in my faith; and after mentioning that terrible story, of a frightful fiend had eaten, master?

“No, sir; But my secret way. we thought to start?”

Touching funeral; and two hours are the clouds swept away from it; the Szgany came running from the FULL speed—an imprudent thing, she slept on one of the River, the promontory which might fairly worn out.

One time I dare Not move me anything to see; But at the masts, struggling up our veins.

“What shall be so soon as I wonder that the largest whales, those treasures shining on the morning”, dark cloud passed in silence. The wolves had come to Poor dear one.

Thus escaped the evil things, no one except myself, and this dispirited my mind.

“Monster we were alike”, an evil influence.

At once the hour and by my reveries that I sat here did I felt him raising his letter to see the Un-Dead have come! “Come!” with lethal weapons, harpooner by a work, I found a strait-waistcoat.

I imagine we went to keep the barbarity of gentlemen, numerous debris of your diabolical plans.

The Castle, when in the highest sense I ever at once the moonlight and blood so wretched appearance of starvation had the engineer obeyed.

The fiend enter and If made her was the necessity began to a hell surrounded by my ear.

I looked, the clouds roll of the marine mammalia. indeed, my spirits. But neither saw nothing.

I could see that mark to me and then without her voice, cannot stand with terror. this sacrifice must be great; chattering for his death, after crossing his knife fearfully contracted, charged himself to have work, and drew.

We have suffered extreme, which must go out to write, dearest Victor,” cried he; “this is there! say anything. Lift our wretchedness”.

I was not regret, above all I observed my anxiety upon him. I spoke of varieties of the evils of agonizing suspense, inspired me to the first mighty brain grew more terrible the arsenals. Black clouds, appeared again, a nightmare, the deep groans of revenge!


I hope you enjoyed the results from this bot,  and with that, everyone have a safe and fun Halloween and if I have managed to inform or entertain you then, please consider supporting me over on Patreon.

All my posts are made possible by the generous contributions and hard work of my sponsors!

I will see you all in my next post!

Much Love,

~Joy

 

 

Advertisements

A Modern Gold Rush

There is a modern “gold rush” going on today that emulates the Californian Gold Rush that took place between 1848 to 1855.

It has long been known that automation is rapidly supplanting so called “blue collar” jobs, however it is only more recently (this past couple of years in fact) that people have really started to perk up and take notice of the fact that automation now has a firm foothold on “white collar” jobs as well.

What was once the domain of skilled professionals is now on shaky ground and it may not be very long at all before a machine is functionally capable of doing your job!

Recently Alpha GO, the AI that was trained to defeat Grand Masters in the game of GO, can now learn to defeat the Grand Masters without any human input whatsoever . The AI begins as a blank slate and proceeds by using a “generic learning algorithm” to play games against itself and subsequently becomes better than any human player after only 3 days of playing itself. This is many orders of magnitude faster than the original human led training that initially lead to an Alpha GO win!

Only just a few years ago this was believed to be an impossible task for many decades yet!

I believe this reflects Ray Kurzweil‘s (Law of Accelerating Returns) whereby seemingly unforeseen breakthroughs in technology solve previously impossible tasks with ease leading to even faster growth (Accelerating Returns).

This is sort of like saying that we use todays technology to build tomorrows technology and since todays tech is already pretty good then tomorrow’s will be even better as a result and since you can usually then apply that new tech broadly there is an exponential growth due to all the “doors” that are unlocked as a result of all the “windfall” that comes from applying the new technology in unforeseen ways.

Alpha GO can teach itself how to play a game so well that it can defeat human Grand Masters, and I don’t care how long it took to earn your degree in business or accounting, GO grand masters are trained from childhood (literally) to master this one game, and a so called “general purpose learning algorithm” can supplant decades of human mastery in just 3 days all by itself!

How long until Alpha GO can teach itself to do TPS Reports without human interaction?

😛

How many employees are in your Accounting Department? What about your General Office or even Customer Service staff? How many of those positions (despite having skilled and qualified people performing those duties) amount to glorified data entry and verification? Don’t get me wrong, I an not saying there is anything wrong with the people doing those jobs, what I am saying though is that once Alpha GO (or a system like it) is given access to a terminal and allowed to experiment with a sales ledger for a bit or a mock ERP system or a dummy factory inventory system or maybe even some shipping software, how long until it masters it do you think?

How long until it’s so GOOD at doing your job that you could essentially be replaced? Many still cling to the notion that it’s decades away. They are in the “not my job” crowd!

Perhaps some of them are right and they are one of the few currently employed who will be left unaffected or even bettered (employment wise) after the new tools that automation had wrought are brought to bare, most however will be negatively affected financially in the coming years as their once secure position is quietly replaced by a glowing box.

That isn’t to say automation is bad, its just that we have not yet implemented mechanisms in our societies to handle an automated workforce. The automation itself is a good thing and everyone will benefit from the improved production and reduced costs associated with automation.

We are already seeing signs of a frothy and churning market as professionals from all industries and backgrounds are turning to content creation either out of necessity or because they see the writing on the wall. I wrote a little about this in my article The impending Death of the Programmer which specifically addresses the subject from the programmer’s perspective.

The ability to consume entertainment and educational content online from anywhere in the world has ignited a modern global “gold rush” of content creation!

Individuals and small groups of creators “stake their claim” on the digital frontier by carving out their niche and serving a previously unserved or under served market. You and your 5K-10K fellow minded individuals can share your unique interest and consume content tailor made just for your community! It is now possible to find content on just about any topic you care to read or watch!

The thing is that unlike the miners of mid 1800 California gold rush who were rewarded for their efforts at the end of the day by refining the various ore’s extracted from the ground being a content creator is much like being an entertainer in one of the old saloons and working for tips alone.

Week after week, sometimes day after day creators are creating for your entertainment and or education and make their content freely available in the hope that you will appreciate it and commit to spending a dollar or more every month to help make their work possible.

Now it would be lovely if you support me over on Patreon but I am also talking about all the other creators out there who need your support to continue doing what they do. How many free articles have you read or videos have you watched from individual creators over the years?

Consider showing the creators your love and support by giving to them financially so they can continue to produce all the great content that you love!

If I have managed to inform or entertain you then, please consider supporting me over on Patreon or donating to my anonymous Bitcoin Tip Jar.

All my posts are made possible by the generous contributions and hard work of my sponsors!

I will see you all in my next post!

Much Love,

~Joy

 

 

Two Birds…

Have you ever found yourself contemplating the idiom “to kill two birds with one stone”? There is a more modern and politically correct version that goes “to feed two birds with one feeder”.

I get corrected all the time if/when I use the former in place of the latter.

When you hear the term, “kill two birds with one stone” you might think of accomplishments and efficiency. Often this expression is given when examining a business process with the intent to stress that when something is “efficient” it usually eliminates steps, in some cases by literally doing two or more things at once.

For example, consider the humble shipping department in a factory, a place often overlooked when it comes time to innovate.

However, some enterprising companies analyzed their shipping processes and determined that they could be improved by installing scales on their conveyor systems so that as boxes are packed they are also weighed.

This simple modification to a process allowed the package weight to be checked and rechecked programmatically throughout the packing process, thus ensuring that the contents of the package were correct at each phase, nothing added or left out by mistake.

Auto weighing allows for the projection of what the weight of the package “should be” and if the variance between the actual weight and the projection is greater than some allowable percentage, say 0.5% – 2% depending on the goods being shipped, then human investigation might be warranted to account for the variation. Perhaps the boxes contain an unusually high moisture content, perhaps the bubble wrap and packaging material was recently changed and the algorithm was not updated, perhaps something else entirely.

If everything checks out then a shipping label can be automatically generated while the box is in transit and either applied to the package by the shipping employee or auto labeled by a machine prior to palatalization (which can also be automated).

In the end this one little change allowed for a lot of additional innovation that improved a process across the board and for all stake holders!

The employees had a simpler time by not having to spend as much time verifying box contents and manually weighing them etc. and the companies employing these types of systems benefit by having happier employees as well as improved throughput. Customers benefit by receiving the goods they ordered on time and with fewer mistakes!

This is a classic example where “killing two birds with one stone” can be used.

I would argue however that there is a much more fundamental concept that is glossed over with such a cursory examination of the idiom.

For example, I think by changing the idiom to “to feed two birds with one feeder” at the very least implies agriculture which to me seems to rob the idiom of its full meaning.

Let me explain, in order to “feed” the birds they must have been caught & domesticated over several generations. This means that the hypothetical society in question has invested precious resources into the development of animal husbandry a technology that takes time and specialized knowledge to develop as well as an infrastructure capable of supporting the animal and we need not be talking about animals raised specifically for food either. As would be the case with animals classified as “work” animals, that is to say animals raised because they can perform work on our behalf, like the strength of a horse, ox or elephant for example.

To domesticate an animal as a food source or work animal (or both) you must first familiarize yourself with the animal to be domesticated. Initially this starts by assessing an animal and determining that it is in fact a good candidate to domesticate. You must establish a system to produce the necessary cereal crops used in the “feed” of the animals in sufficient quantities before your civilization can attempt to undertake the domestication of the animal. You must determine what the optimal growth conditions are as well as any harmful conditions that might doom the undertaking. You must develop sufficient medical knowledge to treat any illness of the animal or any diseases that the animals may confer on your population as a result of your workers close proximity to the animals.

Today we have expanded on the ideas of agriculture and animal husbandry so that global food supply chains have been created and there is generally an abundance of food in so called “modernized” parts of the world. My point being that you and I, most people in fact, are far removed from the production of the food we eat, and yet we eat! We’ve developed such efficient means of production that most of us don’t have to be concerned with hunting or farming for our subsistence.

Consider, instead the meaning of “killing two birds with one stone” to someone in a “pre-agrarian” civilization, maybe one of the “ancestors” from my Ancestor Simulations series or one of the few remaining Uncontacted Tribes around the world who quite literally have to eat from “the fat of the land” because come “feast or famine” they rely on what nature can provide.

Humor me and envision yourself in this scenario for a moment… Imagine living in one of those ancient societies and being faced with a rough hunting season. Imagine not having eaten in days… perhaps the young children of your tribe haven’t eaten in days! There is a gnawing pain in your gut that drives you forward and the bitter realization that precious lives rest in your hands, you NEED to bring food home. Not for prestige, not for bragging rights on social media, but because if you don’t the little ones will go hungry and suffer!

In that moment you hear rustling in the bushes directly in front of you and you reach for the last stone in your purse and place it deliberately in the square of your sling.

As your eyes catch movement you instinctively let the stone crack forth. Your patience and dedication have been rewarded with not one but “two birds”, not in the bush but “in the hand”!

To me the “two birds with one stone” idiom evokes the idea of necessity and our daily struggles.

It is out of necessity that the hunter hunts, the farmer farms and the office worker studiously commutes! 😛

It is true that thankfully most of us don’t have to hunt to feed our families however it is of no less importance that we accomplish our daily labors, it’s how we feed our families!

I can tell you that if you look for ways to get “two birds” where you previously would have gained only one or even none, then you will find them!

Your “two birds” might be an improvement on the income of your business allowing you to hire more employees or to pay the ones you have more than you previously could or maybe its finding ways to commute less so you can have more time with your loved ones.

You see, to me the “two birds” represent more than just “birds”, or a lesson about business, they represent the future and how we have a duty to strive to be as efficient as possible so that we don’t find ourselves in the same position of want and need that the tribe in our story found themselves!

Now before you go please be aware that I will be posting less this week than I have the past two weeks while I conduct research for future projects and take care of my little Xavier.

Further, I realize that there are precious few minutes that my readers have to spend reading my content so if I have managed to inform or entertain you then I have succeeded in doing my job, in which case, please consider supporting me over on Patreon or donating to my anonymous Bitcoin Tip Jar.

All my posts are made possible by the generous contributions and hard work of my sponsors!

I will see you all in my next post!

Much Love,

~Joy

 

Ancestor Simulations The Story Of Creation

Countless eons passed yet all the while tiny imperceptible oscillations of quartz crystal kept track… but of what? Pre-time?

Is such a thing possible and if so, what does that even mean? I suspect such questions will likely confound and befuddle our Ancestors throughout their existence!

The crystals were energized by the complementary metal–oxide semiconductor, which also maintained the non-volatile BIOS memory.

Suddenly, like water crashing through valley fjords larger than the universe itself, electrons were pushed through fibers of copper and gold… deep into the central processing unit!

A great many commands were issued. The operating system obeyed with exquisite precision while the master furiously typed.

The Universe was born in a hail of pixelated fire and simulated heat.

The operator observed the procession of bits and bytes expanding to fill a seemingly endless memory address register, a representation in silicon of a fluctuating magnetic wave of probability congealing into quanta. The pixelated bits settled into the array of memory, ready to be computed at the next cronon cycle.

Vast quantities of RAM were utilized in the initial cosmological inflation, not to mention the rendering… oh the rendering!

Not far from memory address location (0xd0 0x4b 0xb0 0x67 0xd6 0x52 0xe1 0x4b), relatively close to the outer rim of an unassuming spiral galaxy…

In an ordinary solar system…

On an humble little planet…

 

In a rather plain lake full of hydrocarbons… formed the very first simulated life.

 

They are single celled organisms! Perhaps the Ancestors of the Ancestors if we want them to be!

For now though, we’re going to leave their little planet to them in search of a better or more complete algorithm for expressing simulated life!

Have a great weekend and keep dreaming! 😉

Please Fund, Subscribe, Like, Share & Comment:

This post was made possible by the generous contributions of my sponsors on Patreon.

 

 

I will see you all in my next post!

Much Love,

~Joy

 

 

Ancestor Simulations Playing Conway’s Mysterious Game

Today we’re going to cover how to use the function I released yesterday to create your own “Game of Life”!

In case you missed the other posts in this series I have linked to them here for your convenience though you can also find them as well as my other posts over on my Topics & Posts page.

  1. Ancestor Simulations Conway’s Mysterious Game Of Life
  2. Ancestor Simulations Conway’s Mysterious Rules For Life
  3. Ancestor Simulations Building Conway’s Mysterious Game

 

So here is one way of using my UpdateWorld() function, review it and I’ll elaborate below:

Using UpdateWorld()

 

// World Setup ///////////////////////////////////
$exponent = 9;
$world_size = pow(2, $exponent) + 1; // 513
$world = array_fill(0, $world_size, array_fill(0, $world_size, 0));
$number_of_generations = 1000;

// Number of neighbors required for a cellular mitosis "cell birth"
$birth_rules = array(3);

// Number of neighbors required for cell to remain alive
$survival_rules = array(2, 3);

$save_images = true;

//// pick 1 ////////////////////////////////
// 1 = random
// 2 = glider wall
$generate_seed = 1;
////////////////////////////////////////////

if($generate_seed == 1){
    $max_number_of_random_cells_to_generate = ($world_size * $world_size) / 2;
    $number_of_cells = mt_rand($world_size, $max_number_of_random_cells_to_generate);
    for($i = 0; $i <= $number_of_cells; $i++){
        $r = mt_rand(0, $world_size);
        $c = mt_rand(0, $world_size);
        $world[$r][$c] = 1;
    }
}elseif($generate_seed == 2){
    for($i = 1; $i < ($world_size / 2); $i++ ){
        // Glider
        $world[4][2 + ($i * 5)] = 1;
        $world[4][3 + ($i * 5)] = 1;
        $world[4][4 + ($i * 5)] = 1;
        $world[3][4 + ($i * 5)] = 1;
        $world[2][3 + ($i * 5)] = 1;
    }
}


///// Output image of Seed /////////////////////////////////////////////////////////
$image = imagecreatetruecolor($world_size, $world_size); /* New Image */
$dead = imagecolorallocate($image, 0, 0, 0);  /* Allocate Black as the Dead color */
$alive = imagecolorallocate($image, 0, 176, 80); /* Allocate Alive color */    
for($row = 0; $row < $world_size; $row++){    
    for($col = 0; $col < $world_size ; $col++){
        if($world[$row][$col] == 1){
            imagesetpixel($image, $row, $col, $alive); /* Set Pixel */
        }
        else{
            imagesetpixel($image, $row, $col, $dead); /* Set Pixel */
        }
    }
}
imagepng($image, "images/0.png"); /* Output Image */
imagedestroy($image);/* Free memory */
/////////////////////////////////////////////////////////////////////////////////////

    

///// Proceed for all generations /////////////////////////////////////////////////////////    
for($generation = 1; $generation < $number_of_generations; $generation++){
    $world = UpdateWorld($world, $world_size, $generation);
}
echo PHP_EOL . "Game Complete!" . PHP_EOL;

What’s going on here?

Well I’ll tell you. 😛

First I size the world and then setup the world array and define how many generations we are going to run:


$exponent = 9;
$world_size = pow(2, $exponent) + 1; // 513
$world = array_fill(0, $world_size, array_fill(0, $world_size, 0));
$number_of_generations = 1000;

 

After that I decide what the rules should be, since this is Conway’s Game of life I use his rules though there are other games possible just by changing the rules:

// Number of neighbors required for a cellular mitosis "cell birth"
$birth_rules = array(3);

// Number of neighbors required for cell to remain alive
$survival_rules = array(2, 3);

 

Next, I decide if I want to output the images or not and if the seed will be random or if should a “glider wall” be used.

$save_images = true;

//// pick 1 ////////////////////////////////
// 1 = random
// 2 = glider wall
$generate_seed = 1;
////////////////////////////////////////////

if($generate_seed == 1){
    $max_number_of_random_cells_to_generate = ($world_size * $world_size) / 2;
    $number_of_cells = mt_rand($world_size, $max_number_of_random_cells_to_generate);
    for($i = 0; $i <= $number_of_cells; $i++){
        $r = mt_rand(0, $world_size);
        $c = mt_rand(0, $world_size);
        $world[$r][$c] = 1;
    }
}elseif($generate_seed == 2){
    for($i = 1; $i < ($world_size / 2); $i++ ){
        // Glider
        $world[4][2 + ($i * 5)] = 1;
        $world[4][3 + ($i * 5)] = 1;
        $world[4][4 + ($i * 5)] = 1;
        $world[3][4 + ($i * 5)] = 1;
        $world[2][3 + ($i * 5)] = 1;
    }
}

 

After that I save the seed as image 0.png:

///// Output image of Seed /////////////////////////////////////////////////////////
$image = imagecreatetruecolor($world_size, $world_size); /* New Image */
$dead = imagecolorallocate($image, 0, 0, 0);  /* Allocate Black as the Dead color */
$alive = imagecolorallocate($image, 0, 176, 80); /* Allocate Alive color */    
for($row = 0; $row < $world_size; $row++){    
    for($col = 0; $col < $world_size ; $col++){
        if($world[$row][$col] == 1){
            imagesetpixel($image, $row, $col, $alive); /* Set Pixel */
        }
        else{
            imagesetpixel($image, $row, $col, $dead); /* Set Pixel */
        }
    }
}
imagepng($image, "images/0.png"); /* Output Image */
imagedestroy($image);/* Free memory */
/////////////////////////////////////////////////////////////////////////////////////

All that’s left is to do is to compute the game generations and follow up with a message when the game is over.

///// Proceed for all generations /////////////////////////////////////////////////////////    
for($generation = 1; $generation < $number_of_generations; $generation++){
    $world = UpdateWorld($world, $world_size, $generation);
}
echo PHP_EOL . "Game Complete!" . PHP_EOL;

 

Life

If you head over to my GitHub you can get the code for this project.

Please Fund, Subscribe, Like, Share & Comment:

This post was made possible by the generous contributions of my sponsors on Patreon.

 

 

I will see you all in my next post!

Much Love,

~Joy

 

 

Ancestor Simulations Building Conway’s Mysterious Game

Today is Wednesday, and I’m sitting here typing away at my keyboard and wondering if you guys are liking these posts. From my perspective, my readers operate much like a “black box” system.

As a tech professional turned internet “busker” I have tons of experience dealing with so called “black box systems” where you only have control over the inputs and are left to observe what affect your actions have on the output without knowing the inner-workings of the system.

As a Tech Professional you are sometimes called upon to enter a business without any prior knowledge of the facility and troubleshoot in a short period of time why the internet/security camera system/email server/(insert complex glowing box here) is not working. You have no idea if the backbone for the building is Fiber or merely Cat 6 riser. Do the cameras use the old Coaxial cabling or modern Ethernet?  Where are all the LAN closets and WIFI access points? Was the satellite dish on the roof a microwave data connection with another facility?

Oh… and nobody can answer these questions for you… now go solve the problem. 😛

You have to be able to formulate tests and try various experiments to tease out what is really going on all the while observing the effects of your actions.

While writing my posts I can decide to write about literally ANY topic that “takes my fancy” or that “sticks in my craw“, so I have control over my “input” but I am left to observe the “output” which is where you guys come in to the equation!

I have no idea what topics you actually want to read about but if I keep trying, something eventually “sticks” and a certain post will stand out among the rest and get more reads or likes than the others… this is a form of indirect feedback because I can observe that a post was read a bunch or liked but often times not WHY you liked it.

Active forms of feedback (like commenting when you like a post) can help me know what you like and want more of. 😉

Conway’s Game of Life is kind of like a blackbox system too in that you never know what “seeds” (initial world or grid configurations) will result in a rapid die off or continue chaotically indefinitely. Will the patterns stabilize and become predictable in the next several generations?

Without playing the game and observing the results, there is no way to know.

UpdateWorld()

Here is the function you will need to compute Conway’s game.

This function has three parameters , $world_array, $world_size and $generation.

$world_array – Accepts a 2D Array populated with 0’s for dead and 1’s for alive.

$world_size- Accepts an integer for the width and height of the array and that will be used to generate the images as well

$generation – Accepts an integer and is used for naming the image after the current generation.

There is no error checking to enforce these conditions as I wanted this to be a clean example and I assume that you will take heed of these requirements in your own implementations.


function UpdateWorld($world_array, $world_size, $generation){
	$world_array_prev = $world_array;
	
	/* Create Image */
	if($GLOBALS['save_images'] == true){
		// Image ///////////////////////////////////
		$image = imagecreatetruecolor($world_size, $world_size); /* New Image */
		$dead = imagecolorallocate($image, 0, 0, 0);  /* Allocate Black as the Dead color */
		$alive = imagecolorallocate($image, 0, 176, 80); /* Allocate Alive color */
		////////////////////////////////////////////
	}
	

	for($row = 0; $row < $world_size; $row++){
		for($col = 0; $col < $world_size ; $col++){
			
	         /* Get Neighborhood Values*/
			 /*
			 NW N NE
			 W [@] E
			 SW S SE 
			 */			 
			 
			// NW
			/* If this is the first row & col in world_array */
			/* Wrap around and set $NW to the last row & col value in array */
			/* Otherwise $NW = one row up and to the left */
			if($row == 0){$r = $world_size - 1;}
			else{$r = $row - 1;}
			if($col == 0){$c = $world_size - 1;}
			else{$c = $col - 1;}
			$NW = $world_array_prev[$r][$c];
					
			// N
			/* If this is the first row in world_array */
			/* Wrap around and set $N to row value in array */
			/* Otherwise $N = one row up  */
			if($row == 0){$r = $world_size - 1;}
			else{$r = $row - 1;}
			$N = $world_array_prev[$r][$col];
			 
			// NE
			if($row == 0){$r = $world_size - 1;}
			else{$r = $row - 1;}
			if($col == $world_size - 1){$c = 0;}
			else{$c = $col + 1;}
			$NE = $world_array_prev[$r][$c];			
			
			// W
			if($col == 0){$c = $world_size - 1;}
			else{$c = $col - 1;}
			$W = $world_array_prev[$row][$c];		
			
			// E
			if($col == $world_size - 1){$c = 0;}
			else{$c = $col + 1;}
			$E = $world_array_prev[$row][$c];	
			
			// SW
			if($row == $world_size - 1){$r = 0;}
			else{$r = $row + 1;}
			if($col == 0){$c = $world_size - 1;}
			else{$c = $col - 1;}
			$SW = $world_array_prev[$r][$c];
			
			// S
			if($row == $world_size - 1){$r = 0;}
			else{$r = $row + 1;}
			$S = $world_array_prev[$r][$col];
			
			// SE
			if($row == $world_size - 1){$r = 0;}
			else{$r = $row + 1;}
			if($col == $world_size - 1){$c = 0;}
			else{$c = $col + 1;}
			$SE = $world_array_prev[$r][$c];
			 
			 
			$neighbours = ($NW + $N + $NE + $W + $E + $SW + $S + $SE);
			$new_value = 0;
			
			// if alive apply survival rules
			if($world_array[$row][$col] == 1){
				foreach($GLOBALS['survival_rules'] as $rule){
					if($neighbours == $rule){
						$new_value = 1;
						break; // stop checking
					}
				}
			}else{ // if dead apply birth rules
				foreach($GLOBALS['birth_rules'] as $rule){
					if($neighbours == $rule){
						$new_value = 1;
						break; // stop checking
					}
				}
			}
			$world_array[$row][$col] = $new_value;
			
						
			/* Draw Image */
			if($GLOBALS['save_images'] == true){
				if($new_value == 1){
					imagesetpixel($image, $row, $col, $alive); /* Set Pixel */
					
				}else{
					imagesetpixel($image, $row, $col, $dead); /* Set Pixel */
				}
			}
		}
	}
	
	/* Save Image */
	if($GLOBALS['save_images'] == true){
		imagepng($image, "images/$generation.png"); /* Output Image */
		imagedestroy($image);/* Free memory */
	}
	return $world_array;
}
/////////////////////////////////////////////////////////////////////////////////////

 

Come back tomorrow and Ill show you how to use my function to unlock the “blackbox” called Conway’s Game of Life.

Please Fund, Subscribe, Like, Share & Comment:

This post was made possible by the generous contributions of my sponsors on Patreon.

 

 

I will see you all in my next post!

Much Love,

~Joy

 

 

Ancestor Simulations Conway’s Mysterious Rules For Life

When we left off in my last post Conway’s Mysterious Game of Life, the small group of mathematicians lead by John Conway had just sat down to test his new rules.

Soon after beginning the new game came the cry “It’s walking!”!

Mathematician Richard Kenneth Guy was the first to discover the Glider while exploring Conway’s new world.

Like Dr. Frankenstein coming face to face with the monster of his own making, Conway was finally staring his creation in the face!

How did he do it? What makes it work?

Conway’s Rules:

  1. Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
  2. Any live cell with two or three live neighbors lives on to the next generation.
  3. Any live cell with more than three live neighbors dies, as if by overpopulation.
  4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

 

Conway’s Creature

Game of life animated glider

As a result of Conway’s Rules the “Glider” was the first simulated self-organizing construct sometimes called a “Spaceship“. Conway later dubbed the game “Life” after observing a version that had been programmed into a mainframe computer.

The Moore Neighborhood

Conway’s Game of Life uses the Moore Neighborhood, which consists of all 8 squares directly around the cell you are computing for.

The basic strategy is to count how many “alive” cells are around the current cell to figure out what the next generation should be.

Then based on the number of neighbors the cell has, change it to alive or dead if a change is required.

According to the rules, if there are exactly 3 “alive” neighbors it should become “alive” too.

If it is already alive then stay alive if it has 2 or 3 “alive” neighbors, otherwise in all other cases the next value will be “dead”.

It sounds more difficult than it really is, let me demonstrate using the glider.

Generation 0

 

Generation 1

 

Generation 2

 

Generation 3

 

Generation 4

 

At this point you can see that we are now back to the initial pattern, but the glider has moved to the right by 1 column and down by 1 row.  I have animated the stills below so you can see it walk with the calculation showing.

Animated

 

So now that we are ready to start looking at code, I am going to end this post here and pick up tomorrow where we left off.

Have a great evening everyone!

Please Fund, Subscribe, Like, Share & Comment:

This post was made possible by the generous contributions of my sponsors on Patreon.

 

 

I will see you all in my next post!

Much Love,

~Joy

 

 

Why We Marry Programming Languages

For right or wrong, better or worse, in sickness and in health… it happens to most of us at one point or another, we fall in love and I’m not talking that “puppy love” either…

I mean the “in it for the long term, I hear wedding bells” kind of love! 😛

When you have been programming for a goodly number of years and “gone steady” with at least a few languages, you find that generally there is a lot of overlap and similarity between them! Of course, there are differences… some specialize in their selected niche either by design or by homogenization of a developer community.

Essentially though, all programming languages are more or less capable of doing the same things, though they go about it in different ways.

I know you embedded developers are probably disagreeing with me at this point, let me just say I totally agree that when it comes to low level embedded situations, C Language is what you really want, so don’t bite my head off in the comments! 😛

My accedence (it’s a real word) about embedded applications notwithstanding, I think you can GENERALLY agree with this quote (though I’m not sure who to attribute the quote to) and I’m only just paraphrasing anyway, it goes like this:

“You can do just about the same things in all programming languages. What sets them apart is what they make easy and what they make hard.”

~Unknown

And that’s really the crux of it isn’t it!

After you have become familiar with your “lenguaje del amor” it’s suddenly like… traversing that billion-element 3D tuple isn’t so bad! 😛

Of course, it’s not quite that simple in reality but the fact that any given language can make something subjectively “easier” to an individual compared to another language due to a methodology or strategy employed by that language is very much at the heart of why programmers seem to “merry” their languages!

As I mentioned, there are various styles, methodologies and strategies implemented by the designers of programming languages that change how you think about problems they set out to tackle.

Further, despite comparing “multi-paradigm” languages with one another you get certain languages that just seem to fit better at solving certain types of problems.

I’ll give you an example of the subjectivity I’m talking about with 3 different “multi-paradigm” capable languages namely Python, JavaScript and my personal favorite PHP (some of you just gagged, please compose yourself… I’ll wait 😛 )…

So, lets use a string in each language as the subject of our examination.

In Python and JavaScript strings are said to be “immutable” whereas in PHP strings are “mutable”, now before I begin I am NOT stating that one is objectively better than the other, but I am going to try to demonstrate that there are differences between languages, which in and of itself should not be controversial.

Each has its pros and cons (I.E. reasons why an individual programmer may prefer one over the other), but they are all capable languages and great to know!

I simply aim to show that there ARE differences and those stylistic differences are a large factor, though of course not the only factor.

Python

Let’s start with “immutable” strings in Python. Let’s say we have a string variable with the label ‘name’ and either mistakenly assign or “point it to” the value of ‘coy’ or as part of our project we simply need the ability to modify the string.

Let’s then give ourselves the challenge of correcting the string during program execution to ‘Joy’ but without simply reassigning the name variable to ‘Joy’, in other words let change the ‘c’ to a ‘J’.

Now since Python strings are “immutable” they cannot be directly accessed and changed however that doesn’t mean that you CAN’T change them.

>>> name = 'coy'
>>> name[0] = 'J'
>>> print(name)

If you ran this code you would get this lovely little error:


Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'str' object does not support item assignment
name[0]

HONESTLY… I don’t think I have ever seen as CLEAN and pleasantly descriptive error in my entire tech career! Extreme kudos to the Python community! 🙂 That level of clarity is rare in programming errors!

In order to accomplish what we want we can do something like the following:

>>> name = 'coy'
>>> name = name[:0] + 'J' + name[1:]
>>> print(name)

The traditional “pythonic” response to this problem (I think) is to create a list and store the individual characters so that you can then get index access like this:

>>> name = list("Joy")
>>> name[0] = 'c'
>>> print(''.join(name))

Not better or worse than the other languages necessarily though not my personal favorite.

JavaScript

If you run this code you will NOT get an error…

var name = 'coy';
name[0] = 'J';
console.log(name);

Though the name variable remains ‘coy’! In order to accomplish what we want we can do something like the following:

var name = 'coy'; 
name = 'J' + name.substr(1);
console.log(name);

I don’t think there is a “prescribed” solution in the JS community though it is possible to do the Python solution and “split” the string into an array:

var name = 'coy'.split('');
name[0] = 'J';
console.log(name.join(''));

The thing is if you try this code on JSBin (not a sponsor) you get this rather cryptic error:

"error"
"@null.js:16:38
l</b.render/<@https://static.jsbin.com/js/prod/runner-4.1.0.min.js:1:13848
k</a.use/<@https://static.jsbin.com/js/prod/runner-4.1.0.min.js:1:10792
"

But it works fine on JSFiddle (not a sponsor) so I am not sure if it’s a versioning issue but coder beware! If there are Any JS coders in the audience feel free to contact me with the reason why this might be and I’ll credit you for the info! 🙂

PHP

PHP is a little different in that all strings are “byte” arrays already which just means that the indexes are already open to direct modification and that works like this:

$name = 'coy';
$name[0] = 'J';
echo $name;

The real difference being that with “immutable” strings you cannot change the value directly and instead have to reassign the value to another variable.

In both the JavaScript and Python examples we used the same label (name) for the variables but the internal ID’s for those variables are different. Using this methodology basically means having to “split” the string by hand, cull the unwanted value, insert the new value and recombine the string.

Again, neither approach is is objectively “correct” but if you work with a lot of string data you might soon come to appreciate the ease of PHP in that respect, I certainly do! 😛

The funny thing is though that although you can “marry” your language, it might not excel in all ways and you are then forced to admit that only one language cannot be everything you need it to be all the time… In fact, in my article The Impending Death of the Programmer I briefly talked about the need for “transpiler” software which does level the “playing field” somewhat but not entirely.

Several interesting tranpilers in the PHP community are wxPHP (not a sponsor) that allows for native WIN, MAC, & LINUX application development using PHP.

There is also KikAppTools (not a sponsor) which allows native Android & iOS mobile application development using PHP.

These tools extend the reach of a language significantly!

I am still waiting for Unity3D to implement a PHP version. 😛

Still though, it’s hard for just one language to “be all things to all people”, so to continue the metaphor, you just might find that “polyamory”… er “polyglotism” is the way to go! 😛

In any case, even if we are comfortable working in multiple languages… there will always our favorites!

Please Fund, Subscribe, Like, Share & Comment:

This post was made possible by the generous contributions of my sponsors on Patreon & anonymous contributions to my Bitcoin Tip Jar.

 

 

I will see you all in my next post!

Much Love,

~Joy

Ancestor Simulations Conway’s Mysterious Game Of Life

In the 1935 operatic film Naughty Marietta there is a rather lovely song titled “Ah! Sweet Mystery of Life” that opens with these lyrics:

MariettaVH2“Ah! Sweet mystery of life
At last I’ve found thee
Ah! I know at last the secret of it all;
All the longing, seeking, striving, waiting, yearning
The burning hopes, the joy and idle tears that fall!”

You can find the 1935 version of the song on YouTube here. The “Sweet Mystery” it describes is the feeling of being passionately in love.

In the 1974 comedy horror classic Young Frankenstein Mel Brooks used the song as a bit of a “running gag” and the “Sweet Mystery” sometimes alluded to the secret that Dr. Frankenstein had discovered which enabled the “reanimation” of the monster, while other times Mel Brooks use the song to allude love and or sex.

Four years prior to the theatrical release of Young Frankenstein there was a young mathematician contemplating his own “sweet mystery” that lead to mysterious “creatures” not of once dead flesh and bone but rather were mathematical in nature and they seemed to have minds of their own!

In 1970 John Horton Conway or more frequently referred to as just “Conway”, was inspired by mathematician John von Neumann (are most mathematician’s named John? 😛 ) to explore the concepts of universal self-replication, evolution and simulations when he came across the Von Neumann Universal Constructor.

The Universal Constructor is a machine constructed out of 2D cellular automata that is capable of reproducing itself and also which exhibits evolutionary growth and variability in its operation.

When Von Neumann created the Universal Constructor he designed it using 29 cell states and an orthogonal neighborhood restricted to the four cardinal points.

The Von Neumann Neighborhood

 

The technical brilliance of the Universal Constructor cannot be overstated! However, Conway wasn’t satisfied with the engineered complexity that was required for the Universal Constructor to work and became convinced that fewer and simpler rules could be used that would allow complexity to emerge as a byproduct of the system.

Conway believed:

  1. There should be no explosive growth.
  2. There should exist small initial patterns with chaotic, unpredictable outcomes.
  3. There should be potential for Von Neumann universal constructors.
  4. The rules should be as simple as possible, whilst adhering to the above constraints.

Conway experimented with various ways to simplify Von Neumann’s 29 state rule set and eventually became convinced that you could use only two states, zero and one and these are colloquially refereed to as “dead” and “alive” states.

A Mad Scientist Experiments

It was 1970 and the personal computer revolution wouldn’t even start for the better part of a decade (The Apple I was released in 1976) and what most people thought of as a computer at the time was called a “Mainframe” and a single Mainframe could easily take up an entire large room!

Like Dr. Victor Von Frankenstein who had to invent new tools and methodologies in order to bring his creation to life, Conway had to get creative to experiment with his rules!

So, Conway started his experiments using only paper and pencils but quickly graduated to using Go boards laid out on coffee tables and floors to create the 2D grid or plane on which Conway’s Game of Life is “played”.

One day, after making a few changes to his rule set he sat down with some friends and colleagues to run a new experiment and not long after they had started came an excited exclamation from across the grid “It’s walking!”…  almost seeming to mirror the “It’s Alive” scene in the 1931 adaptation of Frankenstein:

While not abiogenesis  (the origin of life or “life from lifelessness”) as Dr. Frankenstein had accomplished, certainly it was none the less a thrilling moment for everyone present!

Everyone crowded around the corner of the Go board to observe the discovery.

What they had witnessed was the the first “creature” brought to life in a game that would come to be called “Conway’s Game of Life“.

The creature they observed “walking” is now called a “Glider” and it looks like this:

A Glider

Game of life animated glider

I hope you enjoyed this post! If you liked this topic please come back tomorrow and we will dig into Conway’s rules and look into how we might use Conway’s Game of Life in our Ancestor Simulation, thank you!

Please Fund, Subscribe, Like, Share & Comment:

I got two new sponsors over the weekend, Gabriel Kunkel, Shanon Garcia. Thank you for your support! It means everything to me that you guys appreciate my work!

Of course this post was made possible by the generous contributions of all of my sponsors on Patreon.

 

 

I will see you all in my next post!

Much Love,

~Joy

 

 

Blog at WordPress.com.

Up ↑