def _convert_to_onehot(labels): # use the original numpy functions from numpy import zeros as nzeros from numpy import arange as narange # to one-hot new_labels = nzeros((labels.size, labels.max() + 1)) new_labels[narange(labels.size), labels] = 1. return new_labels
def calculateTripleFrequency(remainder, strobe): a = np.array([1., 2., 3.]) remainder1 = remainder.copy() remainder2 = remainder1.copy() - 0.6 strobeLen = strobe.shape[1] aLen = a.shape[1] fre_1 = nzeros([strobeLen, aLen], dtype=float) for i in narange(1., (strobeLen) + 1): for j in narange(1., (aLen) + 1): fre_1[int(i) - 1, int(j) - 1] = ndot(strobe[int(i) - 1], a[int(j) - 1]) t = np.shape(fre_1) iter = 1. remainder2Len = remainder2.shape[1] freq_plus = nzeros([t[0, 0] * t[0, 1], remainder2Len]) freq_minus = nzeros([t[0, 0] * t[0, 1], remainder2Len]) freq_plus_shift_negative1 = nzeros([t[0, 0] * t[0, 1], remainder2Len]) freq_plus_shift_negative2 = nzeros([t[0, 0] * t[0, 1], remainder2Len]) for i in narange(1., (t[0, 0]) + 1): for j in narange(1., (t[0, 1]) + 1): fre_11 = fre_1[int(i) - 1, int(j) - 1].copy() remainder_1 = remainder2[int(i) - 1, :].copy() for k in narange(1., remainder2Len + 1): if remainder_1[0, int(k) - 1] > 0.: freq_plus[int(iter) - 1, int(k) - 1] = fre_11 + remainder_1[0, int(k) - 1] freq_minus[int(iter) - 1, int(k) - 1] = fre_11 - remainder_1[0, int(k) - 1] freq_plus_shift_negative1[ int(iter) - 1, int(k) - 1] = fre_11 + 30. - remainder_1[0, int(k) - 1] freq_plus_shift_negative2[ int(iter) - 1, int(k) - 1] = fre_11 - 30. - remainder_1[0, int(k) - 1] iter = iter + 1. est_fre = np.vstack((freq_plus, freq_minus, freq_plus_shift_negative1, freq_plus_shift_negative2)) frequency1 = nround(est_fre) frequency2 = nfloor(est_fre) return [frequency1, frequency2]
def checkValidity_MultiFrquency(X1, Y1, f1, NFFT1): d1_list = [] d2_list = [] g2_list = [] peak1 = np.sort(findPeakPyVersion((2. * X1[0:int(NFFT1 / 2. + 1.)])), 'descend') peak1Len = peak1.shape[1] chk_val1 = nzeros([peak1Len, 1]) index1 = nzeros([peak1Len, 1]) for i in narange(1., (peak1Len + 1)): chk_val1[int(i) - 1, :] = peak1[int(i) - 1] / (nmean(peak1[int(i):peak1Len])) if chk_val1[int(i) - 1, :] > 2.: index1[int(i) - 1, :] = np.nonzero( X1[0:NFFT1 / 2. + 1.] == peak1[:, int(i) - 1] / 2.) d1_list.append(f1[index1[int(i) - 1, :]]) mean1 = nmean(peak1[0:peak1Len]) k = 1. peak2 = np.sort(findPeakPyVersion((2. * Y1[0:NFFT1 / 2. + 1.])), 'descend') peak2Len = peak2.shape[1] chk_val = nzeros([peak2Len, 1]) index2 = nzeros([peak2Len, 1]) for i in narange(1., peak2Len): chk_val[int(i) - 1, :] = peak2[0, int(i) - 1] / nmean(peak2[int(i):peak2Len]) if chk_val[int(i) - 1, :] > 3.: g2_list.append(chk_val[int(i) - 1, :]) index2[int(i) - 1, :] = np.nonzero( (Y1[0:NFFT1 / 2. + 1.] == peak2[:, int(i) - 1] / 2.)) d2_list.append(f1[index2[int(i) - 1, :]]) d2 = np.array([d2_list]) d1 = np.array([d1_list]) g2 = np.array([g2_list]) if g2 >= 0.: g1 = nmean(g2) else: g1 = nmean(g2) return [g1, d1, d2]
def calculateFrequency(d11, z): colSize = d11.shape[1] diff = nzeros([3, colSize], dtype=float) diff[0, :] = nabs(nround( (d11[int((z - 3.)) - 1] - d11[int((z - 2.)) - 1]))) diff[1, :] = nabs(nround( (d11[int((z - 2.)) - 1] - d11[int((z - 1.)) - 1]))) diff[2, :] = nabs(nround((d11[int((z - 1.)) - 1] - d11[int(z) - 1]))) w = scp.stats.mode(diff) return w
def _DelObject(self, _id): """Removes an object from the VBO""" if self._vbo is None: return index = self._indices[_id] num_values = type(self).__num_values del self._indices[_id] if not (index == self._max_index): self._empty_indices.append(index) else: self._max_index -= 1 self._vbo[index * num_values : (index + 1) * num_values] = nzeros(num_values, "f")
def _DelObject(self, _id): """Removes an object from the VBO""" if self._vbo is None: return index = self._indices[_id] num_values = type(self).__num_values del self._indices[_id] if not (index == self._max_index): self._empty_indices.append(index) else: self._max_index -= 1 self._vbo[index * num_values:(index + 1) * num_values] = nzeros( num_values, "f")
def velocityPendCenter(pend_centers): time = 1. / 30. [r, c] = np.shape(pend_centers) VelocityMarker = nzeros([r, c], dtype=float) for i in narange(2., (r) + 1): VelocityMarker[int(i) - 1, int((c - 1.)) - 1] = ( pend_centers[int(i) - 1, int((c - 1.)) - 1] - pend_centers[int( (i - 1.)) - 1, int((c - 1.)) - 1]) / time VelocityMarker[int(i) - 1, int(c) - 1] = (pend_centers[int(i) - 1, int(c) - 1] - pend_centers[int( (i - 1.)) - 1, int(c) - 1]) / time return VelocityMarker
def _BuildData(self, descriptor): """Builds data array from scratch and creates VBO object""" if len(descriptor) == 0: return num_objects = len(descriptor) values_per_object = len(self.__descToArray(descriptor[0])) self._data_size = 2 ** ceil(log(num_objects, 2)) self._data = nzeros(self._data_size * values_per_object, "f") self._indices = {} for i, obj in enumerate(descriptor): _id = obj["id"] values = self.__descToArray(obj) for j, v in enumerate(values): self._data[i * values_per_object + j] = v self._indices[_id] = i self._empty_indices = [] self._max_index = num_objects - 1 self._vbo = vbo.VBO( self._data, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER, size=self._data_size * values_per_object * 4 ) self._dirty_objects = {}
def _BuildData(self, descriptor): """Builds data array from scratch and creates VBO object""" if len(descriptor) == 0: return num_objects = len(descriptor) values_per_object = len(self.__descToArray(descriptor[0])) self._data_size = 2**ceil(log(num_objects, 2)) self._data = nzeros(self._data_size * values_per_object, "f") self._indices = {} for i, obj in enumerate(descriptor): _id = obj["id"] values = self.__descToArray(obj) for j, v in enumerate(values): self._data[i * values_per_object + j] = v self._indices[_id] = i self._empty_indices = [] self._max_index = num_objects - 1 self._vbo = vbo.VBO(self._data, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER, size=self._data_size * values_per_object * 4) self._dirty_objects = {}
def zeros(N, dtype="float", bytes=16): return pyfftw.n_byte_align(nzeros(N, dtype=dtype), bytes)
def mfreq_simulate2(frequency): nfreq = 4. nsampl = 33. sampling_option = 0. cam_fps = 15. prime1 = np.array([ 61., 67., 71., 73., 79., 83., 89., 97., 101., 103., 107., 109., 113., 127., 131., 137., 139., 149., 151., 157., 163., 167., 173., 179., 181., 191., 193., 197., 199., 211., 223., 227., 229. ]) sFile = open('strobe_file.txt', 'w+') freq = np.random.rand(1., nfreq) frequencies = np.array([70., 100., 170., 230.]) if sampling_option == 1.: sampling = nzeros([nsampl]) for i in narange(1., (nsampl) + 1): stri = "give" + str(i) + "th frequency of strobe" print stri sampling[int(i) - 1] = float(raw_input()) else: sampling = prime1.copy() print sampling remainder = nzeros([int(nfreq), int(nsampl)]) remainder2 = remainder.copy() for j in narange(1., (nsampl) + 1): for i in narange(1., (nfreq) + 1): if nmod( nfloor((np.minimum( nmod(frequencies[int(i) - 1], sampling[int(j) - 1]), (sampling[int(j) - 1] - nmod(frequencies[int(i) - 1], sampling[int(j) - 1]))) / cam_fps)), 2.) == 0.: remainder[int(i) - 1, int(j) - 1] = nmod( np.minimum( nmod(frequencies[int(i) - 1], sampling[int(j) - 1]), (sampling[int(j) - 1] - np.mod(frequencies[int(i) - 1], sampling[int(j) - 1]))), cam_fps) else: remainder[int(i) - 1, int(j) - 1] = 15. - nmod( np.minimum( nmod(frequencies[int(i) - 1], sampling[int(j) - 1]), (sampling[int(j) - 1] - np.mod(frequencies[int(i) - 1], sampling[int(j) - 1]))), cam_fps) remainder2[:, int(j) - 1] = np.sort(remainder[:, int(j) - 1]) sFile.write("%f\n" % nfreq) sFile.write("%f\n" % nsampl) for j in narange(1., (nsampl) + 1): sFile.write("%f " % sampling[int(j) - 1]) sFile.write("\n") for i in narange(1., (nfreq) + 1): for j in np.arange(1., (nsampl) + 1): sFile.write('%8.2f ' % remainder2[int(i) - 1, int(j) - 1]) sFile.write('\n') sFile.close() return [frequencies, sampling]
def uncertainty(self): return (np.asarray(self._uncertainty) if self._uncertainty is not None else np.nzeros(self.length))