def test_matrix_scale(self): m = Matrix(2,2 , value = 1) m.scaleColumn(0 , 2) self.assertEqual(2 , m[0,0]) self.assertEqual(2 , m[1,0]) m.setAll(1) m.scaleRow(1 , 2 ) self.assertEqual(2 , m[1,0]) self.assertEqual(2 , m[1,1]) with self.assertRaises(IndexError): m.scaleColumn(10 , 99) with self.assertRaises(IndexError): m.scaleRow(10 , 99)
def calculatePrincipalComponent(self, fs, local_obsdata, truncation_or_ncomp=3): pc = Matrix(1, 1) pc_obs = Matrix(1, 1) singular_values = DoubleVector() state_map = fs.getStateMap() ens_mask = BoolVector(False, self.ert().getEnsembleSize()) state_map.selectMatching(ens_mask, RealizationStateEnum.STATE_HAS_DATA) active_list = ens_mask.createActiveList( ) if len(ens_mask) > 0: meas_data = MeasData(ens_mask) obs_data = ObsData() self.ert().getObservations().getObservationAndMeasureData(fs, local_obsdata, active_list, meas_data, obs_data) meas_data.deactivateZeroStdSamples(obs_data) active_size = len(obs_data) if active_size > 0: S = meas_data.createS() D_obs = obs_data.createDObs() truncation, ncomp = self.truncationOrNumberOfComponents(truncation_or_ncomp) obs_data.scale(S, D_obs=D_obs) EnkfLinalg.calculatePrincipalComponents(S, D_obs, truncation, ncomp, pc, pc_obs, singular_values) if self.__prior_singular_values is None: self.__prior_singular_values = singular_values else: for row in range(pc.rows()): factor = singular_values[row]/self.__prior_singular_values[row] pc.scaleRow( row , factor ) pc_obs.scaleRow( row , factor ) return PcaPlotData(local_obsdata.getName(), pc , pc_obs , singular_values) return None