Python numpy.float_power() Examples
The following are 24
code examples of numpy.float_power().
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 also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: aiplayer.py From alpha_zero_othello with 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 #2
Source File: Estimators.py From slates_semisynth_expts with 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 #3
Source File: Estimators.py From slates_semisynth_expts with 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 #4
Source File: parameters.py From ViolenceDetection with 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 #5
Source File: test_umath.py From predictive-maintenance-using-machine-learning with 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 #6
Source File: test_umath.py From twitter-stock-recommendation with 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 #7
Source File: test_umath.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with 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 #8
Source File: test_umath.py From coffeegrindsize with 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 #9
Source File: test_umath.py From elasticintel with 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 #10
Source File: _continuous_distns.py From Splunking-Crime with 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 #11
Source File: test_umath.py From mxnet-lambda with 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 #12
Source File: test_umath.py From pySINDy with 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 #13
Source File: saliency_visualization.py From VSE-C with 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 #14
Source File: parameter.py From DL.EyeSight with 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 #15
Source File: parameters.py From imgaug with 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
Source File: _continuous_distns.py From GraphicDesignPatternByPython with 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 #17
Source File: test_umath.py From GraphicDesignPatternByPython with 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 #18
Source File: math_ops.py From trax with Apache License 2.0 | 5 votes |
def float_power(x1, x2): return power(x1, x2)
Example #19
Source File: test_umath.py From Mastering-Elasticsearch-7.0 with 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 #20
Source File: test_umath.py From vnpy_crypto with 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 #21
Source File: _continuous_distns.py From lambda-packs with 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 #22
Source File: test_umath.py From recruit with 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 #23
Source File: fractal_dfa.py From NeuroKit with 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 #24
Source File: fractal_dfa.py From NeuroKit with 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