source: issm/trunk-jpl/src/m/classes/qmu/uniform_uncertain.py@ 24256

Last change on this file since 24256 was 24256, checked in by bdef, 5 years ago

BUG: fixing some negative number syntax

File size: 4.6 KB
Line 
1import numpy as np
2#from vlist_write import *
3from MatlabArray import *
4
5
6class uniform_uncertain(object):
7 '''
8 definition for the uniform_uncertain class.
9
10 [uuv] = uniform_uncertain.uniform_uncertain(args)
11 uuv = uniform_uncertain()
12
13 where the required args are:
14 descriptor (str, description, '')
15 lower (float, lower bound, -np.Inf)
16 upper (float, upper bound, np.Inf)
17
18 note that zero arguments constructs a default instance, one
19 argument of the class copies the instance, and three or more
20 arguments constructs a new instance from the arguments.
21'''
22
23 def __init__(self):
24 self.descriptor = ''
25 self.lower = - np.Inf
26 self.upper = np.Inf
27
28 @staticmethod
29 def uniform_uncertain(*args):
30 nargin = len(args)
31
32 # create a default object
33 if nargin == 0:
34 return uniform_uncertain()
35
36 # copy the object
37 elif nargin == 1:
38 if isinstance(args[0], uniform_uncertain):
39 uuv = args[0]
40 else:
41 raise RuntimeError('Object ' + str(args[0]) + ' is a ' + str(type(args[0])) + ' class object, not "uniform_uncertain".')
42
43 # not enough arguments
44 elif nargin == 2:
45 raise RuntimeError('Construction of "uniform_uncertain" class object requires at least 3 inputs.')
46
47 # create the object from the input
48 else:
49 # leaving this here in case it becomes important in the future
50 #asizec = array_size(*args[0:min(nargin, 3)])
51 #uuv = [uniform_uncertain() for i in range(asizec[0]) for j in range(asizec[1])]
52 uuv = uniform_uncertain()
53 uuv.descriptor = str(args[0])
54 uuv.lower = args[1]
55 uuv.upper = args[2]
56 if (nargin > 3):
57 print('WARNING: uniform_uncertain:extra_arg: Extra arguments for object of class ' + type(uuv) + '.')
58
59 return [uuv]
60
61 def __repr__(self):
62 # display an individual object
63 string = '\n'
64 string += 'class "uniform_uncertain" object = \n'
65 string += ' descriptor: ' + str(self.descriptor) + '\n'
66 string += ' lower: ' + str(self.lower) + '\n'
67 string += ' upper: ' + str(self.upper) + '\n'
68
69 return string
70
71 # from here on, uuv is either a single, or a 1d vector of, uniform_uncertain
72
73 @staticmethod
74 def prop_desc(uuv, dstr):
75 if type(uuv) not in [list, np.ndarray]:
76 if uuv.descriptor != '' or type(uuv.descriptor) != str:
77 desc = str(uuv.descriptor)
78 elif dstr != '':
79 desc = str(dstr)
80 else:
81 desc = 'uuv'
82 return desc
83
84 desc = ['' for i in range(np.size(uuv))]
85 for i in range(np.size(uuv)):
86 if uuv[i].descriptor != '' or type(uuv[i].descriptor) != str:
87 desc[i] = str(uuv[i].descriptor)
88 elif dstr != '':
89 desc[i] = str(dstr) + str(string_dim(uuv, i, 'vector'))
90 else:
91 desc[i] = 'uuv' + str(string_dim(uuv, i, 'vector'))
92
93 desc = allempty(desc)
94
95 return desc
96
97 @staticmethod
98 def prop_initpt(uuv):
99 initpt = []
100 return initpt
101
102 @staticmethod
103 def prop_lower(uuv):
104 if type(uuv) not in [list, np.ndarray]:
105 return uuv.lower
106
107 lower = np.zeros(np.size(uuv))
108 for i in range(np.size(uuv)):
109 lower[i] = uuv[i].lower
110
111 lower = allequal(lower, -np.Inf)
112
113 return lower
114
115 @staticmethod
116 def prop_upper(uuv):
117 if type(uuv) not in [list, np.ndarray]:
118 return uuv.upper
119
120 upper = np.zeros(np.size(uuv))
121 for i in range(np.size(uuv)):
122 upper[i] = uuv[i].upper
123
124 upper = allequal(upper, np.Inf)
125
126 return upper
127
128 @staticmethod
129 def prop_mean(uuv):
130 mean = []
131 return mean
132
133 @staticmethod
134 def prop_stddev(uuv):
135 stddev = []
136 return stddev
137
138 @staticmethod
139 def prop_initst(uuv):
140 initst = []
141 return initst
142
143 @staticmethod
144 def prop_stype(uuv):
145 stype = []
146 return stype
147
148 @staticmethod
149 def prop_scale(uuv):
150 scale = []
151 return scale
152
153 @staticmethod
154 def dakota_write(fidi, dvar):
155 # collect only the variables of the appropriate class
156 uuv = [struc_class(i, 'uniform_uncertain', 'uuv') for i in dvar]
157 # possible namespace pollution, the above import seems not to work
158 from vlist_write import vlist_write
159 # write variables
160 vlist_write(fidi, 'uniform_uncertain', 'uuv', uuv)
Note: See TracBrowser for help on using the repository browser.