idaholab / raven

RAVEN is a flexible and multi-purpose probabilistic risk analysis, validation and uncertainty quantification, parameter optimization, model reduction and data knowledge-discovering framework.
https://raven.inl.gov/
Apache License 2.0
217 stars 133 forks source link

[DEFECT] initializeFromDict from UniformDiscrete crashes #2218

Open alfoa opened 9 months ago

alfoa commented 9 months ago

Thank you for the defect report

Defect Description

The initializeFromDict from the UniformDiscrete distribution is not fully (correctly) implemented. It crashes even if the parameters that distribution takes are passed in (i.e. lowerBound, upperBound, nPoints, strategy).

 File "/Users/aalfonsi/projects/raven/ravenframework/SupervisedLearning/FeatureSelection/RFE.py", line 220, in _handleInput
  discrete.initializeFromDict({'strategy': "withReplacement",'lowerBound': 0, 'upperBound': 1, 'nPoints': 2,})
 File "/Users/aalfonsi/projects/raven/ravenframework/Distributions.py", line 1925, in initializeFromDict
  self.categoricalDist.initializeFromDict(inputDict)
 File "/Users/aalfonsi/projects/raven/ravenframework/Distributions.py", line 1698, in initializeFromDict
  for idx, val in enumerate(inputDict['outcome']):

builtins.KeyError: 'outcome'

In addition, the manual in the example the is set as orderedWithReplacement that it does not exist (it should be withReplacement

Steps to Reproduce

from .Distributions import factory as distFactory
discrete = distFactory.returnInstance("UniformDiscrete")
discrete.initializeFromDict({'strategy': "withReplacement",'lowerBound': 0, 'upperBound': 1, 'nPoints': 2,})

Expected Behavior

The method to be used in the distribution creation (also from input file) to make sure the method is actually implemented correctly (And does not crash)

Screenshots and Input Files

 File "/Users/aalfonsi/projects/raven/ravenframework/SupervisedLearning/FeatureSelection/RFE.py", line 220, in _handleInput
  discrete.initializeFromDict({'strategy': "withReplacement",'lowerBound': 0, 'upperBound': 1, 'nPoints': 2,})
 File "/Users/aalfonsi/projects/raven/ravenframework/Distributions.py", line 1925, in initializeFromDict
  self.categoricalDist.initializeFromDict(inputDict)
 File "/Users/aalfonsi/projects/raven/ravenframework/Distributions.py", line 1698, in initializeFromDict
  for idx, val in enumerate(inputDict['outcome']):

builtins.KeyError: 'outcome'

OS

MacOS

OS Version

No response

Dependency Manager

CONDA

For Change Control Board: Issue Review

For Change Control Board: Issue Closure