• Activity
  • Votes
  • Comments
  • New
  • All activity
  • Showing only topics with the tag "original content". Back to normal view
    1. Genetic Algorithms

      Introduction to Genetic Algorithms Genetic algorithms can be used to solve problems that are difficult, or impossible to solve with traditional algorithms. Much like neural networks, they provide...

      Introduction to Genetic Algorithms

      Genetic algorithms can be used to solve problems that are difficult, or impossible to solve with traditional algorithms. Much like neural networks, they provide good-enough solution in short amount of time, but rarely find the best one. While they're not as popular as neural networks nor as widely used, they still have their place, as we can use them to solve complicated problems very fast, without expensive training rigs and with no knowledge of math.

      Genetic algorithms can be used for variety of tasks, for example for determining the best radio antenna shape, aerodynamic shapes of cars and planes, wind mill shapes, or various queing problems. We'll use it to print "Hello, World!".

      How does it work?

      Genetic algorithm works in three steps.

      1. Generate random solutions
      2. Test how good they are
      3. Pick the best ones, breed and mutate them, go to step 2

      It works just like evolution in nature. First, we generate randomised solutions to our problem (in this case: random strings of letters).

      Then, we test each solution and give it points, where better solutions gain more points. In our problem, we would give one point for each correct letter in the string.

      Afterwards, we pick the best solutions and breed it together (just combine the strings). It's not bad idea to mutate (or randomize) the string a bit.

      We collect the offsprings, and repeat the process until we find good enough solution.

      Generate random solutions

      First of all, we need to decide in which form we will encode our solutions. In this case, it will be simply string. If we wanted to build race cars, we would encode each solution (each car) as array of numbers, where first number would be size of the first wheel, the second number would be size of the second wheel, etc. If we wanted to build animals that try to find food, fight and survive, we would choose a decision tree (something like this).

      So let's start and make few solutions, or entities. One hundred should be enough.

      from random import randint
      
      goal = "Hello, World!"
      allowed_characters = list("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ,!")
      
      def get_random_entity(n, string_length):
          entities = []
          for _ in range(0, n):
              entity = ""
              for _ in range(0, string_length):
                  entity += allowed_characters[randint(0, len(allowed_characters)-1)]
              entities.append(entity)
          return entities
      
      print(get_random_entity(100, 13))
      

      Test how good they are

      This is called a "fitness function". Fitness function determines how good a solution is, be it a car (travel distance), animal (food gathered), or a string (number of correct letters).

      The most simple function we can use right now will simply count correct letters. If we wanted, we could make something like Levenshtein distance instead.

      def get_fitness(entity):
          points = 0
          for i in range(0, len(entity)):
              if goal[i] == entity[i]:
                  points += 1
          return points
      

      Crossover and mutation

      Now it's time to select the best ones and throw away the less fortunate entities. Let's order entities by their fitness.

      Crossover is a process, when we take two entities (strings) and breed them to create new one. For example, we could just give the offspring one part from one parent and another part from second parent.

      There are many ways how to do this, and I encourage you to try multiple approaches when you will be doing something like this.

      P:  AAAABBB|BCCCC
      P:  DDDDEEE|FGGGG
      
      F1: AAAABBB|FGGGG
      

      Or we can just choose at random which letter will go from which parent, which works the best here. After we have the offsprint (F1), we should mutate it. What if we were unfortunate, and H (which we need for our Hello, World!) was not in any of the 100 entities? So we take the string and for each character of the string, there is a small chance to mutate it - change it at random.

      F1:  ADDDEBEFGCGG
      F1`: ADHDEBEFGCGG
      

      And it's done. Now kill certain part of old population. I don't know which percentage is best, but I usually kill about 90% of old population. The 90% that we killed will be replaced by new offsprings.

      There is just one more thing: which entities do we select for crossover? It isn't bad idea - and it generally works just fine - to just give better entities higher chance to breed.

      def get_offspring(first_parent, second_parent, mutation_chance):
          new_entity = ""
          for i in range(0, len(first_parent)):
              if randint(0, 100) < mutation_chance:
                  new_entity += allowed_characters[randint(0, len(allowed_characters)-1)]
              else:
                  if randint(0, 1) == 0:
                      new_entity += first_parent[i]
                  else:
                      new_entity += second_parent[i]
          return new_entity
      

      When we add everything together, we get this output:

      Generation 1, best score: 2 ::: QxZPjoptHfNgX
      Generation 2, best score: 3 ::: XeNlTOQuAZjuZ
      Generation 3, best score: 4 ::: weolTSQuoZjuK
      Generation 4, best score: 5 ::: weTgnC uobNdJ
      Generation 5, best score: 6 ::: weTvny uobldb
      Generation 6, best score: 6 ::: HellSy mYbZdC
      Generation 7, best score: 7 ::: selOoXBWoAKn!
      Generation 8, best score: 8 ::: HeTloSoWYZlh!
      Generation 9, best score: 8 ::: sellpX WobKd!
      Generation 10, best score: 9 ::: welloq WobSdb
      Generation 11, best score: 9 ::: selloc WoZjd!
      Generation 12, best score: 10 ::: wellxX WoVld!
      Generation 13, best score: 10 ::: welltX World!
      Generation 14, best score: 10 ::: welltX World!
      Generation 15, best score: 10 ::: welltX World!
      Generation 16, best score: 11 ::: zellov Wobld!
      Generation 17, best score: 11 ::: Hellty World!
      Generation 18, best score: 11 ::: welloX World!
      Generation 19, best score: 11 ::: welloX World!
      Generation 20, best score: 11 ::: welloX World!
      Generation 21, best score: 12 ::: welloX World!
      Generation 22, best score: 12 ::: Helloy World!
      Generation 23, best score: 12 ::: Helloy World!
      Generation 24, best score: 12 ::: Helloy World!
      Generation 25, best score: 12 ::: Helloy World!
      Generation 26, best score: 12 ::: Helloy World!
      Generation 27, best score: 12 ::: Helloy World!
      Generation 28, best score: 12 ::: Helloy World!
      Generation 29, best score: 12 ::: Helloy World!
      Generation 30, best score: 12 ::: Helloy World!
      Generation 31, best score: 12 ::: Helloy World!
      Generation 32, best score: 12 ::: Helloy World!
      Generation 33, best score: 12 ::: Helloy World!
      Generation 34, best score: 13 ::: Helloy World!
      Generation 35, best score: 13 ::: Hello, World!
      

      As we can see, we find pretty good solution very fast, but it takes very long to find perfect solution. The complete code is here.

      Maintaining diversity

      When we solve difficult problems, it starts to be increasingly important to maintain diversity. When all your entities are basically the same (which happened in this example), it's difficult to find other solutions than those that are almost the same as the currently best one. There might be a much better solution, but we didn't find it, because all solutions that are different to currently best one are discarded. Solving this is the real challenge of genetic algorithms. One of the ideas is to boost diverse solutions in fitness function. So for every solution, we compute distance to the current best solutions and add bonus points for distance from it.

      20 votes
    2. This simple stylus userstyle hides vote counts on both voted and unvoted comments and your own comments. I really like what Deimos did, it significantly improved my time here on Tildes. If you...

      This simple stylus userstyle hides vote counts on both voted and unvoted comments and your own comments. I really like what Deimos did, it significantly improved my time here on Tildes. If you want the feature back, install Stylus extension, click the Stylus icon > write style for tildes.net and paste this:

      /* Hide vote count for unvoted comments */
      .btn-post-action[name="vote"] {
          visibility: hidden;
          position: relative;
      }
      .btn-post-action[name="vote"]:after {
          visibility: visible;
      	content: "Vote";
          position: absolute;
      }
      
      /* Hide vote count for voted comments */
      .btn-post-action[name="unvote"] {
          visibility: hidden;
          position: relative;
      }
      .btn-post-action[name="unvote"]:after {
          visibility: visible;
      	content: "Voted";
          position: absolute;
      }
      
      /* Hide vote count for your own comments */
      .comment-votes {
          display: none;
      }
      

      Known issues

      • There is extra padding around Vote button
      • Extensions such as Vim Vixen cannot interact with Vote button
      11 votes
    3. enikő a story written on the edge of sleep and sanity The dreams never seem to come unless they're tortured memories or painful reminders of some ill-begotten past nobody wants to remember. To...

      enikő

      a story written on the edge of sleep and sanity

      The dreams never seem to come unless they're tortured memories or painful reminders of some ill-begotten past nobody wants to remember. To sleep is to live with that reality, but there can be no sleep in such reality either, and neither can there be peace. In the reality there is Enikő, eyes strained against an all-consuming darkness, and the many fractured people that exist within.

      "No sleep," mutters Enikő into the void. There are no people around to hear that, except the many fractured people within. Enikő flashes out of existence at once and the fractured people take their spaces, dance their dances against the blackness.

      "You know," scolds Alyaza Birze, who flashes at once into existence, "you must cease to suppress me one of these days!" Probably Enikő is not truly around to hear this in the reality, for Enikő is just as nonexistent as all the other people within the darkness. Alyaza pays it no mind, for she is accustomed to such.

      "Why must you always tax yourself so, Enikő?" calls Alyaza out to the void. "You know as I that you must sleep. The nightmares are no more common than the daydreams, and neither too are the thoughts. They are not often for you. Rest at once." The void does not answer.

      Alyaza flashes back into nonexistence, and so takes her place is Natja Avidina. In some other place in some other space, it is so that Natja and Alyaza exist as roommates. In this reality though they are consigned to singular existences, never seeing one another. They are opposites, yin and yang, and in this reality yin and yang cannot be at the same time. Natja cannot exist where Alyaza does, nor can Alyaza exist where Natja does. Natja pays this no mind, for she too like Alyaza has long resigned to the void reality.

      "Why do you make yourself suffer, Enikő?" slips the quiet voice of Natja into the void. "Surely you too must be tired, even with the nightmares and the thoughts, and surely you too must realize that there is no guarantee you will even remember them if you rest?" And then Natja too snaps out of existence and is replaced by Enikő.

      "I don't want the thoughts or the nightmares or the dreams." says Enikő from reconstitution. "I have dreamed and thought like a crazy person for years and every day my sanity slips a little more because of it! Must I be consigned to suffer then like every other facet of life simply because you two demand it of me?"

      Enikő's eyes drift, and into the void Alyaza calls back a simple "yes" before disappearing again. In the void little figures dance to the rhythm of a silent melody, one-two like so then one-two again, not figures like Alyaza or Natja but the manifestations of the thoughts and dreams and every little thing the brain conceives and conspires to employ in this god-forsaken hellspace of a reality. Fire and brimstone could never compare to the void that taunts and harasses the very depths of soul and sanity.

      Enikő's eyes drift back into the void. "I refuse," she says with conviction. Sleep will bring upon this void all the figures dancing to the invisible beat a thousand times over complimented with the worst machinations of the mind. One thousand times too many has this happened and one thousand and one will not tonight.

      Enikő gives way to another shard of a body, the one that always confronts the thoughts. The eyes of Twilight Sparkle methodically survey the void for the usual actors, the ones that seem to recur every time she is spirited to this curious place. This is not her home, nor has it ever been, and why she is here she never does seem to know. In another place she is lauded but anxious perpetually, sent against fate and time and gods themselves in the name of an abstract concept she supposes she represents. Here, she exists as a mixture of reason and reaction, and in the void it is never certain which side dominates. She has never been used to the void, but the void cares little for such things.

      "The thoughts aren't anything you haven't experienced before." she says carefully. "If it were my call, I'd take it. Better than what the rest of the mind can spit out if you stay in this void for too long."

      The manifestation of reason disappears, and reaction it seems has lost the day for once. But Enikő responds only with "I refuse" and vanishes once more into nonexistence. The Thompson-esque scene must shamble along once more, resembling more and more an acid trip gone awry with its talking purple ponies and radical socialist gryphon-kind. The void answers the call with frantic pace, the one-two double timing without a breath to spare and the void reaching with the first tendrils of abject paranoia. The void must call its call and spread until entropy overcomes its will. Sleep must one day win over void, or void must overcome all things otherwise.

      But Enikő only pops back once more to refuse. "I shall not sleep, and none shall tell me otherwise. No void shall overcome me, no matter what, and I would sooner die than feel the thoughts once more."


      Alyaza Birze has a plan. She is no strategist of course, and pays no claim to being such, but just as Enikő was the body within which all of the fractal personalities contained themselves, Alyaza was a person into which Enikő could project. And just as Enikő knew Alyaza, Alyaza must then have known Enikő.

      The one-two one-two staccato of the void grew seemingly always more and more discordant, for which Enikő would no doubt pay in short order. But the void reality was not the only reality into which all of the fractal personalities could contain themselves, and Alyaza Birze knows this. There are many vectors by which to project yourself into another reality, and this too Alyaza Birze knows, but it is a very specific reality that Alyaza Birze seeks. And so into the void, with sudden rhythm, is a familiar humming.

      Doo do, doo do do do.

      Do do do do, do do do do, do do.


      It is some indiscriminate time, in a place that is less so indiscriminate. Alyaza Birze is on a podium at the head of a sea of curious lifeforms in a reality that places her in a Thompson-like Battle of Aspen. But far from Aspen, this reality invokes some mayoral election for a town named Ponyville in a land called Equestria, in some god-forsaken reality that demands words but defies them and calls for no less than six tabs of acid. It is Birze, the uncharismatic but ever convention-defying radical speaker who raises a Gonzo fist to a species with no opposable digits and recites with conviction "All you maggot-smoking fags on Santa Monica boulevard." No explanation for these words or their significance to the Birze campaign is given, nor for the Gonzo fist, and the reality at once seems to shatter into a million ill-fitting pieces from such an illogical state of being. Birze pays none of it mind.

      Somewhere to the side of the sea of life is a Twilight Sparkle equally oblivious of the void and all too aware of it, cringing at every word spoken by Birze and no doubt trying to distance herself from every syllable that is enunciated on that grand podium. No self-respecting person would be caught dead wholeheartedly agreeing with some platform literally based in nothing in this reality (except of course for the vast masses already doing so but without saying so). But then all of this is irrelevant and Twilight knows this and it is merely pomp and circumstance to the call of the void which exists and eats away at everything like a malignant cancer even in so far away a place as this. Behind the thinly veiled, multicolored sets of this reality jolt the rhythms of the void reality, ready to expand and consume here just as it too shall consume Enikő. And so it is under that circumstance that exponentially titled future Mayor of the Reality of the Freak Power Ponyvillians Alyaza Birze and shattered personality Twilight Sparkle meet both knowing and not knowing why it is they meet.

      "To what pleasure do I owe speaking to the visit of our presumptive mayor?" asks the purple pony in the Thompson-esque scene. The void at least will not eat these words, so there is point and purpose in the intonation put on them.

      "Someone as smart as you surely must know why I am here and not anywhere else today. Void is void, Tevilias. It is another one of those." said Alyaza with reservation. "And certainly I am no mayor, for the record."

      "You must forgive me," Twilight strings together with lackadaisical attitude, "but what would 'one of those' mean?" There is an air of resignation in the words, like the inevitable weight of a hundred-million realities is about to crash down on this reality and consign it to some bad acid trip where it belongs.

      "Well you know as I, Tevilias, that in twenty-odd hours I shoot all of you to that beat and tune, that bullshit line of "All you maggot-smoking faggots" in this strange smoke and mirrors bullshit reality that exists. That is where the thoughts go, that is what the void calls, and it is you who will die there too in agony a hundred times any other. And no doubt you know that I have no desire to do that. We've been through this a hundred times, haven't we? And we know what happens if we do that."

      "Sure." The resignation is enviable.

      "And so we will not let that happen, will we? Because it's not like I want to murder. And you know what will happen if we do." The three-headed cerberus that inhabits the void makes itself known then.

      "I WILL MURDER YOU ALL IN COLD BLOOD" bays the first head. The second nods solemnly as though carried along for a ride it never asked. The third head is manic, bearing no mind to anything but the vast and acid-like surroundings and teetering back and forth on the cusp of some far off reality from here. All of them are Alyazas, stuck in a body that never represented them in a world that never cared for them, or so it seems. No one head ever seems to dominate, except when it surfaces and becomes The Alyaza Birze, the one that people know. And never is there a time when one knows which one is The Alyaza Birze or if none of them are The Alyaza Birze, the one that everybody interacts with. Perhaps twenty-odd hours from now it will be the first that will do the killing.

      "So perhaps," says Alyaza Birze, the cerberus disappearing at once, "we should make this quick then." And Twilight Sparkle can merely nod as one of the fragmented personalities once in her own reality and soon to again no longer be.


      The void cannot pace itself any longer, and the discordant harmonies cease at once to contain themselves. The thoughts grow darker and drearier as they always do and the figures in the void give way to the schizophrenic happenings of the night. The shadow figures that once were become again and reanimate against the pitch black, the vividness ever greater. Sleep is enviable, but the void shall not overcome. The thoughts shall not overcome, not the dreams of dying or doing the death dealing nor the inenviable and inevitable thoughts of wanton mutilation. "The void will not overcome me, and I shall not sleep." says Enikő, and the void surges its tendrils once more.

      Alyaza Birze and Twilight Sparkle and all her friends and all the other fractal personalities but Natja Avidina constitute themselves in the void once more, humming the refrains to a song which they all care to know as fractal personalities to a person. What a thing to be a witness to the sunshine! What a dream to just be walking on the ground! Into the void must strum the beat to something more cheery, something to at least dispel the thoughts and the agonies and the void for awhile, something that isn't so depressive and destructive. Don't get so upset, the refrain cries, the world was never fair--but there are ways yet to get through the day and so too perhaps the night. None of the fractal personalities sing, for singing is never quite their tempo. In some other, non-void reality perhaps this is so, but here they simply drown in the thoughts. And the thoughts are drowned, slowly, but inexorably, by the feelings of the music.

      The void begins to slow, and entropy takes its course as does inevitably for all things. Soon the dreams are gone and so too go the thoughts with them, and at once there is a true void where the nightmares and the thoughts frolic no longer.

      "Well that was not so hard." says Alyaza Birze. "A work done well by everybody, I suppose." Twilight merely scoffs, and says nothing of it before she is reconstituted into her own reality, to perhaps be shot again sometime in not-so-far-gone future. So too out of existence and into their own blink her other friends, ever present in this void from time to time as she but never quite players in its major doings. One day in the not-so-far-gone future it is they too who may die at the hands of some Alyaza Birze. But tonight they are merely fractal personalities in a large symphony of them, called upon ever and remembered never.

      Into the night Alyaza Birze skitters onto paper a little testimony she picked up on a day she can no longer remember but which sticks into her mind evermore.

      It reads:

      In my own country I am in a far-off land
      I am strong but have no force or power
      I win all yet remain a loser
      At break of day I say goodnight
      When I lie down I have a great fear
      Of falling.

      And then she too blinks into nonexistence, perhaps in some not-so-far-flung future destined to be as she was this night to kill, perhaps destined to rewrite the words of testimony, but ever destined to repeat the cycle of doing and being and defusing crises on this night and all others a million times over now and forever more.

      And for the first time in a long while, Enikő is at peace and sleeps.

      7 votes
    4. What is our policy about posting original contents (e.g. me submitting a blog post I wrote, which I just did a few minutes ago)? IMO, if it is a personal blog, it should be okay, and not really...

      What is our policy about posting original contents (e.g. me submitting a blog post I wrote, which I just did a few minutes ago)?

      IMO, if it is a personal blog, it should be okay, and not really different from submitting a text topic here. Especially if the blog is not tracking you.

      15 votes
    5. I've read the docs and I personally have not seen this topic come up yet. I've been weary/afraid to post any more of my own content since my very first post here on ~Tildes. Are there currently...

      I've read the docs and I personally have not seen this topic come up yet.

      I've been weary/afraid to post any more of my own content since my very first post here on ~Tildes. Are there currently any unofficial rules for self-promotion? We all know Reddit once had that stupid 10:1 (or was it 5:1?) ratio rule before they chucked it. I don't want to feel like a selfish person or a spammy person if I submit content that I created and/or links to accounts that promote myself as a brand.

      12 votes