algorithm - Assigning weight to a variable Python/linear equations -


i trying assign weight variable using minimum value, optimal , maximum. example, have calculated float temperature (tm) of dna sequences (calculated based on nn joining algorithm). interested in sequences fall within specific temperature range. opt=61, min=58, max=64. want program 2 linear equations, weight of temperature variable can used future comparisons (within weight variable itself). example if tm = 61, desirable (optimal), should receive weight of 100. tm of 58 (least desirable) have weight of 10, tm of 64 (least desirable) has weight of 10.

pseudocode:

def tm_weight(tm):     if tm == 61:         weight = 100     elif tm > 61:         weight = ((-30*(tm)) + 1930)     else:         weight = ((30*(tm)) - 1730)     return weight  

this give me desired weight, i'm looking more general way this, without providing values. wish use argparse (so can change options (for opt, min , max) command line, , still calculate linear weight particular variable. there better way this?

i looking more universal this, still don't know if there better/more efficient way this.

def tm_weight(self): if self.temp == options.opttm: self.temp_weight = 100 elif self.temp > options.opttm: self.slope = (10-100)/(options.maxtm - options.opttm) self.inter = (100 - ((10-100)/(options.maxtm - options.opttm))(options.opttm)) self.temp_weight = ((self.slope)(self.temp) + (self.inter)) else: self.slope = (100 - 10)/(options.opttm - options.mintm) self.inter = (100 - ((100 - 10)/(options.opttm - options.mintm))(options.opttm)) self.temp_weight = ((self.slope)(self.temp) + (self.inter)) return self.temp_weight


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -