Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fusedwind/fused_data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def load_hdf5(self, hdf5_file):
#converting from hdf5 format:
self.data[key] = {}
self.data[key]['values'] = np.array(f['data/'+key+'/values'])
self.data[key]['is_set'] = np.array(f['data/'+key+'/status'])
self.data[key]['is_set'] = np.array(f['data/'+key+'/status'])
self.collumn_list.append(key)

# def save_pickle(self,pickle_name=None):
# import pickle
Expand Down
74 changes: 73 additions & 1 deletion fusedwind/fused_surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,79 @@ def get_prediction(self,input):
sigma = self.cheap_GP_model.get_sigma(input)**2+self.exp_correction_GP_model.get_sigma(input)**2
sigma = sigma**0.5
return [prediction,sigma]


#Single fidelity surrogate object:
class Single_Fidelity_Surrogate(object):

def __init__(self, input=None, output=None, dataset=None):
self.input = input
self.output = output

self.output_names = ['prediction','sigma']

built = 'False'

def build_model(self):
self.linear_model = Linear_Model(self.input,self.output)
self.linear_model.build()

linear_prediction = self.linear_model.get_prediction(self.input)
linear_remainder = self.output-linear_prediction

self.GP_model = Kriging_Model(self.input,linear_remainder)
self.GP_model.build()

built = 'True'

def get_prediction_matrix(self,input):
prediction = self.linear_model.get_prediction(input)+self.GP_model.get_prediction(input)
return prediction

def get_prediction(self,input):
prediction = self.linear_model.get_prediction(input)+self.GP_model.get_prediction(input)
sigma = self.GP_model.get_sigma(input)
return [prediction,sigma]

def do_LOO(self, extra_array_input=None, extra_array_output=None):
error_array = do_LOO(self, extra_array_input, extra_array_output)
return error_array

def do_LOO(self, extra_array_input=None, extra_array_output=None):
'''
This function creates a Leave One Out error calculation on the input/output data of the model.
The function takes an extra data array of test-cases.
'''
full_input = self.input
full_output = self.output
error_array = []

#Doing leave one out test:
for ind in range(len(self.input[:,0])):
test_input = np.array([full_input[ind]])
test_output = full_output[ind]

self.input = np.delete(full_input,ind,0)
self.output = np.delete(full_output,ind)

self.build_model()
predicted_output = self.get_prediction(test_input)[0]

error_array.append(np.abs(predicted_output-test_output))

self.input = full_input
self.output = full_output
self.build_model()

#Testing error on extra points:
if not extra_array_input is None:
for ind, test_input in enumerate(extra_array_input):
TI = np.array([test_input])
TO = extra_test_array_output[ind]
predicted_output = self.get_prediction(TI)[0]
error_array.append(np.abs(predicted_output-TO))

return np.mean(error_array)

class Linear_Model(linear_model.LinearRegression):

def __init__(self,input=None,output=None,linear_order=3):
Expand Down
5 changes: 4 additions & 1 deletion fusedwind/fused_wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def parse_connect_args(dest_object, source_object, var_name_dest=None, var_name_
src_name = var_name_source
# Verify things are OK
if not dst_name in dst_var:
raise Exception('That destination variable name does not exist')
import pdb;pdb.set_trace()
raise Exception('That destination variable %s name does not exist in %s'%(dst_name,dst_var))
if not src_name in src_var:
raise Exception('That source variable %s name does not exist in %s'%(src_name,src_var))
if dst_name in dst_src_map:
Expand Down Expand Up @@ -1023,6 +1024,7 @@ def __getitem__(self, key):
# Return the result
return self.output_values[key]


# This will label all variables as remotely calculated
def set_as_remotely_calculated(self, at_rank):

Expand Down Expand Up @@ -1292,6 +1294,7 @@ def get_object_dict_and_list(object_container):
if hasattr(obj, 'object_name'):
name = obj.object_name
from fusedwind.fused_util import make_unique_name
raise Exception('LISTLISTLIST')
name = make_unique_name(name, object_name_set)
object_dictionary[name] = obj
if is_fused_object_or_group(obj):
Expand Down