Giter Club home page Giter Club logo

Comments (7)

eriklindernoren avatar eriklindernoren commented on May 1, 2024

Given that the mutation rate parameter is compared against a value sampled randomly between 0 and 1 mutation will be applied in proportion to the mutation rate value provided. E.g. for mutation rate set to 0.6, mutation will be applied ~60% of the times given that the random value is uniformly sampled between 0 and 1.

from ml-from-scratch.

0xskywalker avatar 0xskywalker commented on May 1, 2024

Run this experimental code.

import numpy
mutation_rate = 0.6
times = 0
for i in range(10):
if numpy.random.random() < mutation_rate:
times += 0.1
print(times)

The random value is uniformly sampled but it isn't applied 60% of the time. It is also random.

from ml-from-scratch.

eriklindernoren avatar eriklindernoren commented on May 1, 2024

It's applied 100% of the time but it's true roughly 60% of the time. See below.

Eriks-MacBook-Pro:~ erik$ python3
Python 3.7.0 (default, Jun 29 2018, 20:13:13) 
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> val = 0
>>> for _ in range(100000):
...     if np.random.random() < 0.6:
...             val += 1
... 
>>> print (val)
59966

from ml-from-scratch.

0xskywalker avatar 0xskywalker commented on May 1, 2024

Run it multiple times and compare the results. Numpy's random value generation is independent of boolean comparisons.

from ml-from-scratch.

eriklindernoren avatar eriklindernoren commented on May 1, 2024

Mutation rate is commonly implemented as a probability of mutation with respect to the mutation rate parameter. Because of this it's implemented as a comparison between a random value and the parameter.

from ml-from-scratch.

0xskywalker avatar 0xskywalker commented on May 1, 2024

You don't understand what I was trying to communicate, anyways, you did a good job.

from ml-from-scratch.

eriklindernoren avatar eriklindernoren commented on May 1, 2024

This is handled similarly to what I've seen in several other reference implementations of GA. Check https://blog.sicara.com/getting-started-genetic-algorithms-python-tutorial-81ffa1dd72f9 in the section where mutation is implemented for instance. The argument that setting a higher mutation rate would not have an impact is clearly false as the statement np.random.random() < mutation_rate would be true more often and mutation would thereby be applied more often.

from ml-from-scratch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.