Python numpy.float_power() Examples
The following are 24 code examples for showing how to use numpy.float_power(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: ViolenceDetection Author: JoshuaPiinRueyPan File: parameters.py License: Apache License 2.0 | 6 votes |
def _draw_samples(self, size, random_state): seed = random_state.randint(0, 10**6, 1)[0] samples = self.other_param.draw_samples(size, random_state=ia.new_random_state(seed)) elementwise = self.elementwise and not isinstance(self.val, Deterministic) if elementwise: exponents = self.val.draw_samples(size, random_state=ia.new_random_state(seed+1)) else: exponents = self.val.draw_sample(random_state=ia.new_random_state(seed+1)) # without this we get int results in the case of # Power(<int>, <stochastic float param>) samples, exponents = both_np_float_if_one_is_float(samples, exponents) samples_dtype = samples.dtype # float_power requires numpy>=1.12 #result = np.float_power(samples, exponents) # TODO why was float32 type here replaced with complex number # formulation? result = np.power(samples.astype(np.complex), exponents).real if result.dtype != samples_dtype: result = result.astype(samples_dtype) return result
Example 2
Project: slates_semisynth_expts Author: adith387 File: Estimators.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def estimate(self, query, logged_ranking, new_ranking, logged_value): exactMatch=numpy.absolute(new_ranking-logged_ranking).sum() == 0 currentValue=0.0 if exactMatch: numAllowedDocs=self.loggingPolicy.dataset.docsPerQuery[query] validDocs=logged_ranking.size invPropensity=None if self.loggingPolicy.allowRepetitions: invPropensity=numpy.float_power(numAllowedDocs, validDocs) else: invPropensity=numpy.prod(range(numAllowedDocs+1-validDocs, numAllowedDocs+1), dtype=numpy.float64) currentValue=logged_value*invPropensity self.updateRunningAverage(currentValue) return self.runningMean
Example 3
Project: slates_semisynth_expts Author: adith387 File: Estimators.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def estimate(self, query, logged_ranking, new_ranking, logged_value): exactMatch=numpy.absolute(new_ranking-logged_ranking).sum() == 0 currentValue=0.0 if exactMatch: numAllowedDocs=self.loggingPolicy.dataset.docsPerQuery[query] validDocs=logged_ranking.size invPropensity=None if self.loggingPolicy.allowRepetitions: invPropensity=numpy.float_power(numAllowedDocs, validDocs) else: invPropensity=numpy.prod(range(numAllowedDocs+1-validDocs, numAllowedDocs+1), dtype=numpy.float64) currentValue=logged_value*invPropensity self.updateRunningAverage(currentValue) denominatorDelta=invPropensity-self.runningDenominatorMean self.runningDenominatorMean+=denominatorDelta/self.runningSum if self.runningDenominatorMean!=0.0: return 1.0*self.runningMean/self.runningDenominatorMean else: return 0.0
Example 4
Project: alpha_zero_othello Author: bhansconnect File: aiplayer.py License: MIT License | 6 votes |
def pick_move(self, game, side): possible_moves = game.possible_moves(side) if len(possible_moves) == 0: possible_moves.append((-1,-1)) monte_prob = self.monte_carlo(game, side) if self.train: self.temp_state.append((self.preprocess_input(game.board, side), np.divide(monte_prob, np.sum(monte_prob)))) monte_prob = np.float_power(monte_prob, 1/self.tau) monte_prob = np.divide(monte_prob, np.sum(monte_prob)) r = random() for i, move in enumerate(possible_moves): r -= monte_prob[Othello.move_id(move)] if r <= 0: return move return possible_moves[-1]
Example 5
Project: VSE-C Author: ExplorerFreda File: saliency_visualization.py License: MIT License | 5 votes |
def plot_saliency(raw_img, image_var, img_embedding_var, caption_var): dis = (caption_var.squeeze() * img_embedding_var.squeeze()).sum() dis.backward(retain_graph=True) grad = image_var.grad.data.cpu().squeeze().numpy().transpose((1, 2, 0)) grad = normalize_grad(grad, stat=True) grad = imresize((grad * 255).astype('uint8'), (raw_img.height, raw_img.width)) / 255 grad = normalize_grad(grad.mean(axis=-1, keepdims=True).repeat(3, axis=-1)) grad = np.float_power(grad, args.grad_power) np_img = np.array(raw_img) masked_img = np_img * grad final = np.hstack([np_img, masked_img.astype('uint8'), (grad * 255).astype('uint8')]) return Image.fromarray(final.astype('uint8'))
Example 6
Project: NeuroKit Author: neuropsychology File: fractal_dfa.py License: MIT License | 5 votes |
def _fractal_dfa_fluctuation(segments, trends, multifractal=False, q=2): detrended = segments - trends if multifractal is True: var = np.var(detrended, axis=1) fluctuation = np.float_power(np.mean(np.float_power(var, q / 2), axis=1) / 2, 1 / q.T) fluctuation = np.mean(fluctuation) # Average over qs (not sure of that!) else: # Compute Root Mean Square (RMS) fluctuation = np.sum(detrended ** 2, axis=1) / detrended.shape[1] fluctuation = np.sqrt(np.sum(fluctuation) / len(fluctuation)) return fluctuation
Example 7
Project: NeuroKit Author: neuropsychology File: fractal_dfa.py License: MIT License | 5 votes |
def _fractal_mfdfa_q(q=2): # TODO: Add log calculator for q ≈ 0 # Fractal powers as floats q = np.asarray_chkfinite(q, dtype=np.float) # Ensure q≈0 is removed, since it does not converge. Limit set at |q| < 0.1 q = q[(q < -0.1) + (q > 0.1)] # Reshape q to perform np.float_power q = q.reshape(-1, 1) return q
Example 8
Project: recruit Author: Frank-qlu File: test_umath.py License: Apache License 2.0 | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 9
Project: lambda-packs Author: ryfeus File: _continuous_distns.py License: MIT License | 5 votes |
def _argcheck(self, h, k): condlist = [np.logical_and(h > 0, k > 0), np.logical_and(h > 0, k == 0), np.logical_and(h > 0, k < 0), np.logical_and(h <= 0, k > 0), np.logical_and(h <= 0, k == 0), np.logical_and(h <= 0, k < 0)] def f0(h, k): return (1.0 - float_power(h, -k))/k def f1(h, k): return np.log(h) def f3(h, k): a = np.empty(np.shape(h)) a[:] = -np.inf return a def f5(h, k): return 1.0/k self.a = _lazyselect(condlist, [f0, f1, f0, f3, f3, f5], [h, k], default=np.nan) def f0(h, k): return 1.0/k def f1(h, k): a = np.empty(np.shape(h)) a[:] = np.inf return a self.b = _lazyselect(condlist, [f0, f1, f1, f0, f1, f1], [h, k], default=np.nan) return h == h
Example 10
Project: vnpy_crypto Author: birforce File: test_umath.py License: MIT License | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 11
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_umath.py License: MIT License | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 12
Project: trax Author: google File: math_ops.py License: Apache License 2.0 | 5 votes |
def float_power(x1, x2): return power(x1, x2)
Example 13
Project: GraphicDesignPatternByPython Author: Relph1119 File: test_umath.py License: MIT License | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 14
Project: GraphicDesignPatternByPython Author: Relph1119 File: _continuous_distns.py License: MIT License | 5 votes |
def _argcheck(self, h, k): condlist = [np.logical_and(h > 0, k > 0), np.logical_and(h > 0, k == 0), np.logical_and(h > 0, k < 0), np.logical_and(h <= 0, k > 0), np.logical_and(h <= 0, k == 0), np.logical_and(h <= 0, k < 0)] def f0(h, k): return (1.0 - float_power(h, -k))/k def f1(h, k): return np.log(h) def f3(h, k): a = np.empty(np.shape(h)) a[:] = -np.inf return a def f5(h, k): return 1.0/k self.a = _lazyselect(condlist, [f0, f1, f0, f3, f3, f5], [h, k], default=np.nan) def f0(h, k): return 1.0/k def f1(h, k): a = np.empty(np.shape(h)) a[:] = np.inf return a self.b = _lazyselect(condlist, [f0, f1, f1, f0, f1, f1], [h, k], default=np.nan) return h == h
Example 15
Project: imgaug Author: aleju File: parameters.py License: MIT License | 5 votes |
def _draw_samples(self, size, random_state): rngs = random_state.duplicate(2) samples = self.other_param.draw_samples(size, random_state=rngs[0]) elementwise = ( self.elementwise and not isinstance(self.val, Deterministic)) if elementwise: exponents = self.val.draw_samples(size, random_state=rngs[1]) else: exponents = self.val.draw_sample(random_state=rngs[1]) # without this we get int results in the case of # Power(<int>, <stochastic float param>) samples, exponents = both_np_float_if_one_is_float(samples, exponents) samples_dtype = samples.dtype # TODO switch to this as numpy>=1.15 is now a requirement # float_power requires numpy>=1.12 # result = np.float_power(samples, exponents) # TODO why was float32 type here replaced with complex number # formulation? result = np.power(samples.astype(np.complex), exponents).real if result.dtype != samples_dtype: result = result.astype(samples_dtype) return result
Example 16
Project: DL.EyeSight Author: liuguiyangnwpu File: parameter.py License: GNU General Public License v3.0 | 5 votes |
def _draw_samples(self, size, random_state): seed = random_state.randint(0, 10**6, 1)[0] samples = self.other_param.draw_samples( size, random_state=eu.new_random_state(seed)) elementwise = self.elementwise and not isinstance(self.val, Deterministic) if elementwise: exponents = self.val.draw_samples( size, random_state=eu.new_random_state(seed+1)) else: exponents = self.val.draw_sample( random_state=eu.new_random_state(seed+1)) # without this we get int results in the case of # Power(<int>, <stochastic float param>) samples, exponents = both_np_float_if_one_is_float(samples, exponents) samples_dtype = samples.dtype # float_power requires numpy>=1.12 #result = np.float_power(samples, exponents) # TODO why was float32 type here replaced with complex number # formulation? result = np.power(samples.astype(np.complex), exponents).real if result.dtype != samples_dtype: result = result.astype(samples_dtype) return result
Example 17
Project: predictive-maintenance-using-machine-learning Author: awslabs File: test_umath.py License: Apache License 2.0 | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 18
Project: pySINDy Author: luckystarufo File: test_umath.py License: MIT License | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 19
Project: mxnet-lambda Author: awslabs File: test_umath.py License: Apache License 2.0 | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 20
Project: Splunking-Crime Author: nccgroup File: _continuous_distns.py License: GNU Affero General Public License v3.0 | 5 votes |
def _argcheck(self, h, k): condlist = [np.logical_and(h > 0, k > 0), np.logical_and(h > 0, k == 0), np.logical_and(h > 0, k < 0), np.logical_and(h <= 0, k > 0), np.logical_and(h <= 0, k == 0), np.logical_and(h <= 0, k < 0)] def f0(h, k): return (1.0 - float_power(h, -k))/k def f1(h, k): return np.log(h) def f3(h, k): a = np.empty(np.shape(h)) a[:] = -np.inf return a def f5(h, k): return 1.0/k self.a = _lazyselect(condlist, [f0, f1, f0, f3, f3, f5], [h, k], default=np.nan) def f0(h, k): return 1.0/k def f1(h, k): a = np.empty(np.shape(h)) a[:] = np.inf return a self.b = _lazyselect(condlist, [f0, f1, f1, f0, f1, f1], [h, k], default=np.nan) return h == h
Example 21
Project: elasticintel Author: securityclippy File: test_umath.py License: GNU General Public License v3.0 | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 22
Project: coffeegrindsize Author: jgagneastro File: test_umath.py License: MIT License | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 23
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: test_umath.py License: MIT License | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)
Example 24
Project: twitter-stock-recommendation Author: alvarobartt File: test_umath.py License: MIT License | 5 votes |
def test_type_conversion(self): arg_type = '?bhilBHILefdgFDG' res_type = 'ddddddddddddgDDG' for dtin, dtout in zip(arg_type, res_type): msg = "dtin: %s, dtout: %s" % (dtin, dtout) arg = np.ones(1, dtype=dtin) res = np.float_power(arg, arg) assert_(res.dtype.name == np.dtype(dtout).name, msg)