Skip to content

Commit

Permalink
Fix "Log" Scaling (#1236)
Browse files Browse the repository at this point in the history
* fix log unscaling formula

* change min to 2 to verify log formula works

* make sure no other test has min at 1 or 0 to avoid future false successes
  • Loading branch information
bpaul4 authored Aug 6, 2024
1 parent 691185f commit 0aaa024
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion foqus_lib/framework/graph/nodeVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def unscale2(self, val):
elif self.scaling == "Linear":
out = val * (self.max - self.min) / 10.0 + self.min
elif self.scaling == "Log":
out = math.pow(self.min * (self.max / self.min), (val / 10.0))
out = self.min * math.pow((self.max / self.min), (val / 10.0))
elif self.scaling == "Power":
out = math.log10(
(val / 10.0) * (math.pow(10, self.max) - math.pow(10, self.min))
Expand Down
42 changes: 21 additions & 21 deletions foqus_lib/unit_test/nodeVars_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,90 +91,90 @@ def testLoadJSON(self):

def testScaleLinear(self):
var = self.makeVar()
var.min = 1
var.min = 2
var.max = 25
var.value = 4.12
var.scaling = "Linear"
var.scale()
self.assertAlmostEqual(var.scaled, 1.3)
self.assertAlmostEqual(var.scaled, 0.9217, places=3)

def testScaleLog(self):
var = self.makeVar()
var.min = 1
var.min = 2
var.max = 25
var.value = 4.12
var.scaling = "Log"
var.scale()
self.assertAlmostEqual(var.scaled, 4.3986, places=3)
self.assertAlmostEqual(var.scaled, 2.8614, places=3)

def testScalePower(self):
var = self.makeVar()
var.min = 0
var.min = 0.1
var.max = 2
var.value = 0.2
var.scaling = "Power"
var.scale()
self.assertAlmostEqual(var.scaled, 0.0591, places=3)
self.assertAlmostEqual(var.scaled, 0.0330, places=3)

def testScaleLog2(self):
var = self.makeVar()
var.min = 1
var.min = 2
var.max = 25
var.value = 4.12
var.scaling = "Log 2"
var.scale()
self.assertAlmostEqual(var.scaled, 3.3646, places=3)
self.assertAlmostEqual(var.scaled, 2.6235, places=3)

def testScalePower2(self):
var = self.makeVar()
var.min = 1
var.min = 2
var.max = 25
var.value = 4.12
var.scaling = "Power 2"
var.scale()
self.assertAlmostEqual(var.scaled, 0.3877, places=3)
self.assertAlmostEqual(var.scaled, 0.2627, places=3)

def testUnScaleLinear(self):
var = self.makeVar()
var.min = 1
var.min = 2
var.max = 25
var.scaled = 1.3
var.scaled = 0.9217
var.scaling = "Linear"
var.unscale()
self.assertAlmostEqual(var.value, 4.12)
self.assertAlmostEqual(var.value, 4.12, places=3)

def testUnScaleLog(self):
var = self.makeVar()
var.min = 1
var.min = 2
var.max = 25
var.scaled = 4.3986
var.scaled = 2.8614
var.scaling = "Log"
var.unscale()
self.assertAlmostEqual(var.value, 4.12, places=3)

def testUnScalePower(self):
var = self.makeVar()
var.min = 0
var.min = 0.1
var.max = 2
var.scaled = 0.059080120451
var.scaled = 0.0330
var.scaling = "Power"
var.unscale()
self.assertAlmostEqual(var.value, 0.2, places=3)

def testUnScaleLog2(self):
var = self.makeVar()
var.min = 1
var.min = 2
var.max = 25
var.scaled = 3.3646
var.scaled = 2.6235
var.scaling = "Log 2"
var.unscale()
self.assertAlmostEqual(var.value, 4.12, places=3)

def testUnScalePower2(self):
var = self.makeVar()
var.min = 1
var.min = 2
var.max = 25
var.scaled = 0.3877365362129
var.scaled = 0.2627
var.scaling = "Power 2"
var.unscale()
self.assertAlmostEqual(var.value, 4.12, places=3)

0 comments on commit 0aaa024

Please sign in to comment.