- ago
I'm working on an optimizer wrapper that will later be used to hone in on specific metics (similar to the shrinking window concept) but not the same.

When an optimization begins I want to override the user parameter input to create a "shallow" first pass. To achive this I create a new ParameterList to which new Parameters are added.

However... I've encountered something I can't quite get my head arround.

If I specify a step value of 0.1 or greater (0.15, 0.20, 0.25, 0.30 etc) The Parameter created has a .Decimals value of 1 (one decimal place) even though the step value is recorded accurately.



If I specify a step value of 0.05 I get a .Decimals value of 2

I stripped back the code to the bare minimum to duplicate.

CODE:
'VB.net For i = 1 To 20    ' create the step value - use Decimal in VB.net as doubles are    ' not as precise and can result in numbers like 0.250000032 instead of 0.25    Dim thisStep As Decimal = 0.05 * i    ' Create the Parameter    Dim myP1 As New Parameter("My New Paramater", ParameterTypes.Double, 0, 0, 1, thisStep)    ' print out the result    Debug.Print("ThisStep Value: " & thisStep & " Decimal=" & myP1.Decimals.ToString) Next // C#-- I think ... for (i = 1; i <= 20; i++) { // create the step value - use Decimal in VB.net as doubles are // not as precise and can result in numbers like 0.250000032 instead of 0.25 decimal thisStep = 0.05 * i; // Create the Parameter Parameter myP1 = new Parameter("My New Paramater", ParameterTypes.Double, 0, 0, 1, thisStep); // print out the result Debug.Print("ThisStep Value: " + thisStep + " Decimal=" + myP1.Decimals.ToString); }


QUOTE:
Result:
----------------------
ThisStep Value: 0.05 Decimal= 2
ThisStep Value: 0.1 Decimal= 1
ThisStep Value: 0.15 Decimal= 1
ThisStep Value: 0.2 Decimal= 1
ThisStep Value: 0.25 Decimal= 1
ThisStep Value: 0.3 Decimal= 1
ThisStep Value: 0.35 Decimal= 1
ThisStep Value: 0.4 Decimal= 1
ThisStep Value: 0.45 Decimal= 1
ThisStep Value: 0.5 Decimal= 1
ThisStep Value: 0.55 Decimal= 1
ThisStep Value: 0.6 Decimal= 1
ThisStep Value: 0.65 Decimal= 1
ThisStep Value: 0.7 Decimal= 1
ThisStep Value: 0.75 Decimal= 1
ThisStep Value: 0.8 Decimal= 1
ThisStep Value: 0.85 Decimal= 1
ThisStep Value: 0.9 Decimal= 1
ThisStep Value: 0.95 Decimal= 1
ThisStep Value: 1 Decimal= 0


The incorrect decimal value has a undesireable impact on the step generation.

For example a 0.25 step between 0 and 1 results in steps of 0.2 (one decimal place), which generates 6 steps (0, 0.2, 0.4, 0.6, 0.8, 1) instead of 5 (0, 0.25, 0.5, 0.75, 1)

As a result, the number of permutations by steps and the total of GetTotalPermutations() is signifcantly differnet.

SideNote: The same thing occurs if the StepValue of an existing Paramaters is updated.


0
787
Solved
9 Replies

Reply

Bookmark

Sort
- ago
#1
Just a wild guess but have you tried to define the boundaries as double values, not as something that may be treated as integer?
CODE:
Dim myP1 As New Parameter("My New Paramater", ParameterTypes.Double, 0.0 0.0, 1.0, thisStep)
0
Glitch8
 ( 10.41% )
- ago
#2
This Decimal property isn’t intended to be used in this way. Cant you establish your own function to get the results you desire?
0
- ago
#3
I have used both Decimal and Double the .Decimals value is the same in both cases

@Eugene I have tried many variations including Dim'ing Double vars and inserting them. The results are always the same. Changing 0 to 0.0 does not explain why the first stepvalue of 0.05 results in a .Decimals value or 2 and the other have values of 1

QUOTE:
Result when using Double (not decimal)
------------------------
ThisStep Value: 0.05 Decimal=2
ThisStep Value: 0.1 Decimal=1
ThisStep Value: 0.15000000000000002 Decimal=1
ThisStep Value: 0.2 Decimal=1
ThisStep Value: 0.25 Decimal=1
ThisStep Value: 0.30000000000000004 Decimal=1
ThisStep Value: 0.35000000000000003 Decimal=1
ThisStep Value: 0.4 Decimal=1
ThisStep Value: 0.45 Decimal=1
ThisStep Value: 0.5 Decimal=1
ThisStep Value: 0.55 Decimal=1
ThisStep Value: 0.6000000000000001 Decimal=1
ThisStep Value: 0.65 Decimal=1
ThisStep Value: 0.7000000000000001 Decimal=1
ThisStep Value: 0.75 Decimal=1
ThisStep Value: 0.8 Decimal=1
ThisStep Value: 0.8500000000000001 Decimal=1
ThisStep Value: 0.9 Decimal=1
ThisStep Value: 0.9500000000000001 Decimal=1
ThisStep Value: 1[/b] Decimal=0


I don't know about C#, but in VB a double often has a long tail value that is imprecise. The result when incrementing in loops is that values can be missed (usually the last as the inccrement is HIGHER than the final value). I have encountered this over the years on multiple occasions. Decimals always give a greater accuracy in my experience.
0
- ago
#4
Code change to defining double as per @Eugenes suggestion - results below

CODE:
Dim myP1 As New Parameter("My New Paramater", ParameterTypes.Double, 0.0, 0.0, 1.0, thisStep)

QUOTE:
Results
----------------
ThisStep Value: 0.05 Decimal=2
ThisStep Value: 0.1 Decimal= 1
ThisStep Value: 0.15000000000000002 Decimal= 1
ThisStep Value: 0.2 Decimal= 1
ThisStep Value: 0.25 Decimal= 1
ThisStep Value: 0.30000000000000004 Decimal= 1
ThisStep Value: 0.35000000000000003 Decimal= 1
ThisStep Value: 0.4 Decimal= 1
ThisStep Value: 0.45 Decimal= 1
ThisStep Value: 0.5 Decimal= 1
ThisStep Value: 0.55 Decimal= 1
ThisStep Value: 0.6000000000000001 Decimal= 1
ThisStep Value: 0.65 Decimal= 1
ThisStep Value: 0.7000000000000001 Decimal= 1
ThisStep Value: 0.75 Decimal= 1
ThisStep Value: 0.8 Decimal= 1
ThisStep Value: 0.8500000000000001 Decimal= 1
ThisStep Value: 0.9 Decimal= 1
ThisStep Value: 0.9500000000000001 Decimal= 1
ThisStep Value: 1[/b] Decimal=0



0
Glitch8
 ( 10.41% )
- ago
#5
I fixed the Decimals property so it should return what you're expecting in B48!
0
Best Answer
- ago
#6
Thank you.... :)
0
- ago
#7
Does the change also correct the step value calculations mentioned in the initial post?
0
Glitch8
 ( 10.41% )
- ago
#8
Yes
0
- ago
#9
Excellent, thank you
0

Reply

Bookmark

Sort