In the genetic toolbox of matlab, there is a function which is called bs2rv which takes random binary strings and map them to real numbers using either binary or gray coding.
I don't understand how bs2rv works, what exactly happens. I want to understand the algorithm of it, can someone help me understand it?
binary string to real value conversion
Phen = bs2rv(Chrom, FieldD)
Chrom=crtbp(Nind,Nvar) where crtbp generates a random matrix of element zero and one of size Nind rows and Nvar columns
Phen = bs2rv(Chrom, FieldD) decodes the binary representation of the
population, Chrom, into vectors of reals. The chromosomes are seen as
concatenated binary strings of given length, and decoded into real numbers over a
specified interval using either standard binary or Gray coding according to the
decoding matrix, FieldD. The resulting matrix, Phen, contains the
corresponding population phenotypes.
The matrix FieldD has the following structure:
The rows of the matrix are composed as follows:
len, a row vector containing the length of each substring in Chrom. Note that
sum(len) should equal length(Chrom).
lb and ub are row vectors containing the lower and upper bounds respectively for
each variable used.
code is a binary row vector indicating how each substring is decoded. Select
code(i) = 0 for standard binary and code(i) = 1 for Gray coding.