Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gene mapping (abstraction layer) #48

Closed
rengel8 started this conversation in Ideas
Jun 15, 2021 · 1 comments · 3 replies
Discussion options

gene mapping (abstraction layer)

Beyond different data types for genes there might be the need to use stepping (a defined distance) between different gene values. The feature described would also handle precision of floats to the extent, that the user defines/configures the gene space by range oriented expressions.

A user defined gene space might look like this

gene_spac = [{'low': 1, 'high': 21}, {'low': 45.2, 'high': 61.5}]
gene_type = [int, float]

Taking the example above, a user might want to use these ranges from low to max for one single gene with a certain stepping for the integer values and especially also for the floating point values.

Range-Expression:

gene_string = '1>21:2, 45.2>61.5:2.4'

The example contains two blocks of ranges, which can be resolved independantly to [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21] and [45.2, 47.6, 50.0, 52.4, 54.8, 57.2, 59.6]. Also negative gene values are possible, since the stepping value is apllied by addition.
1>21:2 = Starting from 1 (low) to 21 (high) by 2 (stepping size).

Python-Code to accomplish that:

def gene_ranges(minV, maxV, stepS):
 # create all paramameter variations from min to max acc. to stepping
 newList = []
 while minV <= maxV:
 newList.append(minV)
 if type(stepS) is float:
 minV = round((minV + stepS), len(str(stepS).split(".")[1]))
 else:
 minV = minV + stepS
 return newList
def gene_expression_unroll(string):
 # takes a string as input to convert to a list of numbers (genes)
 string = string.replace(" ", "") # removes spaces
 blocks = string.split(",") # splits into blocks of ranges, which will be handled separately
 try: # test for format convention qualification
 test1 = blocks[0].index(':')
 test2 = blocks[0].index('>')
 except Exception:
 exit('Input expression for gene ranges is not valid \"1>9:1\" format')
 resulting_ranges = []
 for _ in blocks:
 min_val = _[0:_.index('>')]
 min_val = float(min_val) if '.' in min_val else int(min_val)
 max_val = _[(_.index('>') + 1):_.index(':')]
 max_val = float(max_val) if '.' in max_val else int(max_val)
 stepping = _[(_.index(':') + 1):len(_)]
 stepping = float(stepping) if '.' in stepping else int(stepping)
 # print('min_val:', min_val, 'max_val:', max_val, 'stepping:', stepping)
 new_range = gene_ranges(min_val, max_val, stepping)
 resulting_ranges = resulting_ranges + new_range
 return resulting_ranges
# basic test to create gene ranges
print(gene_ranges(1, 21, 2))
print(gene_ranges(45.2, 61.5, 2.4))
print('')
gene_string = '1>21:2, 45.2>61.5:2.4'
print(gene_expression_unroll(gene_string), 'gene low is: 0 and high is:', len(gene_expression_unroll(gene_string)))

Working with mapped genes, I would recommend to work internally with integer ranges which start at 0 and can be seen as the index to access the mapped genes to built up the solutions. The last line of the code block above shows gene low/high for that gene mapping example provided.

You must be logged in to vote

Replies: 1 comment 3 replies

Comment options

This is indeed a good feature to be supported.

Without adding a new parameter like gene_string, the dictionary in gene_space can support that by adding a new optional item with key step that defaults to 1.

gene_space = [{'low': 1, 'high': 21, 'step': 1}, {'low': 45.2, 'high': 61.5, 'step': 1}]

I will consider supporting adding it to the next release 2.15.0.

Please let me know if something else to be supported.

You must be logged in to vote
3 replies
Comment options

If it would only be about stepping you are right, but I wanted also to be able to have certain ranges concatenated (stepping + some distance between ranges). I think that my first citation is obfuscating it.

So one single gene could have one or more ranges, which each consist of low, high and stepping. That I wanted to demonstrate with the code example of the last two lines for one gene.

Comment options

Oh OK I got it. To make things compatible with the current syntax, this would be supported by accepting multiple ranges within the gene_space parameter itself without adding a new parameter.

PyGAD 2.15.0 will be published soon which will support using a step in the dictionary.

For your info, you can assign a range() or numpy.arange() array to a gene in the gene_space parameter where you could use a step. This is an example:

gene_space = [range(1, 50, 2), range(1, 80, 2)]
Comment options

Sounds and looks great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /