def init_processor(self): self.processor = get_processor(self.configs["processor"]) self.init_optimizer() if 'regularizer' in dir(self.processor): self.loss_function = self.loss_with_regularizer else: self.loss_function = self.loss_fn
def load_voltage_ranges(configs): if configs['processor_type'] == 'dnpu' or configs[ 'processor_type'] == 'surrogate': p = get_processor(configs) amplitude = np.array(p.info['data_info']['input_data']['amplitude']) offset = np.array(p.info['data_info']['input_data']['offset']) else: amplitude = np.array(configs['input_data']['amplitude']) offset = np.array(configs['input_data']['offset']) min_voltage = offset - amplitude max_voltage = offset + amplitude return min_voltage, max_voltage
def init_processor(self, configs): self.input_electrode_no = configs['input_electrode_no'] self.input_indices = configs['input_indices'] self.nr_control_genes = self.input_electrode_no - len( self.input_indices) self.control_voltage_indices = get_control_voltage_indices( self.input_indices, self.input_electrode_no) self.processor = get_processor(configs) self.load_control_voltage_configs(configs) self.clipvalue = configs['waveform'][ 'output_clipping_value'] * self.processor.get_amplification_value( ) # 3.55
def __init__(self, configs, is_main=True): # configs = self.load_directory_configs(configs) self.is_main = is_main self.algorithm = get_algorithm(configs['algorithm_configs']) self.load_methods(configs['algorithm_configs']) self.load_task_configs(configs) if 'validation' in configs: self.validation_processor_configs = configs['validation'][ 'processor'] self.validation_processor = get_processor( configs['validation']['processor']) else: self.validation_processor_configs = None
def run_test(self): self.processor = get_processor(self.configs['processor']) experiments = ["IV1", "IV2", "IV3", "IV4", "IV5", "IV6", "IV7"] output = {} output_array = [] for exp in experiments: output[exp] = {} output_array = self.processor.get_output( IVtest.create_input_arrays(self)) for i, dev in enumerate(self.configs["processor"]['devices']): output[exp][dev] = output_array[:, i].T self.iv_plot(output)
def validate_prediction(self, name, inputs, control_voltages, predictions, mask): print( '==========================================================================================' ) print(f"Validating model prediction of {name}...") inputs = self.clip(inputs, max_value=MAX_CLIPPING_VALUE, min_value=MIN_CLIPPING_VALUE) control_voltages = self.clip(control_voltages, max_value=MAX_CLIPPING_VALUE, min_value=MIN_CLIPPING_VALUE) input_matrix = self.generate_input_matrix(inputs, control_voltages) if self.configs["processor"]["shape"] != len(predictions): print( f"Changing shape key of processor from value {self.configs['processor']['shape']} to {len(predictions)}" ) self.configs["processor"]["shape"] = len(predictions) processor = get_processor(self.configs['processor']) measurement = processor.get_output(input_matrix) processor.close_tasks() error = ((measurement[mask, 0] - predictions[mask])**2).mean( ) # TODO: predictions should be 2 dim array with last dim singleton print(f'MSE: {str(error)}') var_measurement = np.var(measurement[mask], ddof=1) print(f'(var) NMSE: {100*error/var_measurement} %') self.plot_validation(name, measurement[mask], predictions[mask], show_plots=self.show_plots, save_dir=self.validation_dir) print( '==========================================================================================' ) return error, var_measurement, measurement[mask]
def init_processors(self): self.validation_processor = get_processor( self.configs['validation']['processor']) self.processor = get_processor( self.configs['algorithm_configs']['processor'])
def __init__(self, configs): self.configs = configs self.processor = get_processor(configs['algorithm_configs']['processor']) self.task = Task(configs)