-
15 votes
-
Source Code for Libra: Facebook's Cryptocurrency
8 votes -
Mercury: a speculative reimagining of the operating system
8 votes -
No, Elon Musk did not delete his Twitter account
4 votes -
Has “Homosexual” always been in the Bible?
9 votes -
Ireland to ban new petrol and diesel vehicles from 2030
13 votes -
Google is enabling RCS independently of mobile operators in the UK and France this month
10 votes -
The Trauma Floor: The secret lives of Facebook moderators in America
7 votes -
MacOS Folks -- chunkwm is dead, yabai is the future (same dev, too!)
tldr; chunkwm has been completely rewritten and is now yabai From the chunkwm site: chunkwm is no longer in development because of a C99 re-write, yabai. yabai was originally supposed to be the...
tldr; chunkwm has been completely rewritten and is now yabai
From the chunkwm site:
chunkwm is no longer in development because of a C99 re-write, yabai.
yabai was originally supposed to be the first RC version of chunkwm. However due to major architectural changes, supported systems, and changes to functionality, it is being released separately. There are multiple reasons behind these changes, based on the experience I've gained through experimenting with, designing, and using both kwm and chunkwm. Some of these changes are performance related while other changes have been made to keep the user experience simple and more complete, attempts to achieve a seamless integration with the operating system (when possible), proper error reporting, and yet still keep the property of being customizable.
For those who don't know, chunkwm was / is a tiling windows manager that is sort of like bspwm / i3 etc. I've been using chunkwm for a few months now and love it. If you're also an i3 user, the lack of a proper super key does make your key combos different, but overall its an excellent window manager. Both chunkwm and yabai use koekeishiya's Simple Hotkey Daemon (skhd).
Anyway, I gave the new version the day and its pretty good, but still has some quirks. It seems like development is moving along quickly, so keep an eye on it.
8 votes -
Twitch is suing the trolls who flooded Artifact streams with porn and gore
13 votes -
Is it time to retire ‘climate change’ for ‘climate crisis’?
27 votes -
Carbon dioxide levels hit record peak in May
11 votes -
Factorio players, what are your favorite mods?
Factorio has a rich modding scene. Which ones are your favorites?
16 votes -
Why I found my community in a Starbucks
6 votes -
Notes on privacy and data collection of Matrix.org
12 votes -
Mezzano - An operating system written in Common Lisp
11 votes -
The end of the Arctic as we know it
10 votes -
Rethinking open source: The challenges behind establishing a modern emulator
21 votes -
Linux and FreeBSD Kernel: Multiple TCP-based remote denial of service vulnerabilities
7 votes -
Man who shared mosque shooting livestream sentenced to twenty-one months in prison
20 votes -
Alex Jones sent Sandy Hook victims files with child sex abuse images, say lawyers
18 votes -
Meet the angry gaming YouTubers who turn outrage into views
20 votes -
Five years ago, Malaysia Airlines Flight MH370 vanished into the Indian Ocean. Officials on land know more about why than they dare to say
16 votes -
Asian countries take a stand against the rich world’s plastic waste
11 votes -
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.
- Generate random solutions
- Test how good they are
- 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 pointsCrossover 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|FGGGGOr 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, andH(which we need for ourHello, 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`: ADHDEBEFGCGGAnd 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_entityWhen 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 -
The platform excuse is dying
16 votes -
Samsung TVs should be regularly virus-checked, the company says
6 votes -
Why Mazda is purging touchscreens from its vehicles
18 votes -
The M&A process is broken - Which is why we’re publishing the Atlassian Term Sheet to fix it
5 votes -
Taylor Swift - You Need To Calm Down (2019)
11 votes -
Categorically Gay: For queer people who grew up in an era when rigid identities were essential, today’s fluidity can feel like their history is washing out with the tide.
12 votes -
What Chinese citizens have learned about the Hong Kong protests
13 votes -
Seattle Seawolves defend Major League Rugby crown before season three expansion
4 votes -
India heatwave: Rain brings respite for some but death toll rises
3 votes -
A year after spinal surgery, a $94,000 bill feels like a backbreaker
6 votes -
Tabletop RPGs with kids
Has anybody had much experience playing DnD or other tabletops with children? I've been toying with the idea of making a fairly straightforward and simplified RPG using Story Cubes and GURPS that...
Has anybody had much experience playing DnD or other tabletops with children? I've been toying with the idea of making a fairly straightforward and simplified RPG using Story Cubes and GURPS that kids can get involved with easily and have fun playing. I'm specifically aiming to play with my daughter (8) and my niece (5) on a big family holiday in August, though I see no real reason that this couldn't work with adults as well.
Essentially, the conceit would go along the lines of each player rolling a limited number of story dice to help with character creation and such. I'd ask the players a few simple questions about their powers (for example, are you more of a wizard or more of a warrior?) to get some basic stats stats together (STR, DEX, INT, CON), and then use story dice myself to quickly improvise a short one-shot session.Does anyone have experience playing with kids, and if so - any pointers? Am I being too ambitious about children's ability to imagine stuff in this way? If so, are there any good systems out there that are good for young people to pick up and get stuck into roleplaying with?
9 votes -
Power has been restored to much of Argentina and Uruguay after a massive electrical failure left tens of millions of people in the dark
8 votes -
Five Kinds of Relationship Problems
7 votes -
How the hell has Danielle Steel managed to write 179 books?
13 votes -
Masks, cash and apps: How Hong Kong’s protesters find ways to outwit the surveillance state
10 votes -
Man killed by off-duty officer in California Costco was 'mentally challenged'
7 votes -
This psychologist explains why people confess to crimes they didn’t commit
17 votes -
Data bleeding everywhere: A story of period trackers
11 votes -
VHD in the USA: Failure to Launch
4 votes -
In court, Facebook blames users for destroying their own right to privacy
19 votes -
Pulse wasn’t about me. But covering it changed me
4 votes -
Israel Folau launches fresh attack on gay and transgender people
9 votes -
Hideyuki Fukasawa - Five
3 votes -
What mobile games do you play?
I don't play many games on my phone, mostly because I can't find any good ones that arent just lazy cash grabs. What do you play on your phone?
17 votes -
L'ENTOURLOOP - Le Savoir Faire (2019)
4 votes