logarithm

Taking logs and adding versus multiplying

你离开我真会死。 提交于 2019-12-22 10:22:20
问题 If I want to take the product of a list of floating point numbers, what's the worst-case/average-case precision lost by adding their logs and then taking exp of the sum as opposed to just multiplying them. Is there ever a case when this is actually more precise? 回答1: Absent any overflow or underflow shenanigans, if a and b are floating-point numbers, then the product a*b will be computed to within a relative error of 1/2 ulp. A crude bound on the relative error after multiplying a chain of N

Logarithm Function in SPARQL Query

Deadly 提交于 2019-12-21 20:07:28
问题 I am trying to create a SPARQL query that performs the logarithm function on the returned results. I have implemented the Jena SPARQL engine in my java program, but have only been able to find these available functions : http://jena.sourceforge.net/ARQ/library-function.html Does anybody know of a way to take the logarithm (preferably the natural log) of a SPARQL return variable? Example query that works: SELECT DISTINCT ((?Transactions_Num) AS ?BusinessValue) WHERE {{?BusinessProcess relation

How to get lg2 of a number that is 2^k

故事扮演 提交于 2019-12-21 09:13:56
问题 What is the best solution for getting the base 2 logarithm of a number that I know is a power of two ( 2^k ). (Of course I know only the value 2^k not k itself.) One way I thought of doing is by subtracting 1 and then doing a bitcount: lg2(n) = bitcount( n - 1 ) = k, iff k is an integer 0b10000 - 1 = 0b01111, bitcount(0b01111) = 4 But is there a faster way of doing it (without caching)? Also something that doesn't involve bitcount about as fast would be nice to know? One of the applications

JavaFX 2.x : Logarithmic scale on Y axis

限于喜欢 提交于 2019-12-21 02:41:25
问题 As from this very good post here Logarithmic scale in Java FX 2 I have changed this class to get log scale on Y axis, and it works fine. The only problem I have is that there are very few horizontal grid lines and scale always start ranges from 0 or near zero. Here is what I get I would like to have tick values grid also in the min and max range of my data serie, in this case min = 19,35 max = 20,35; as of now all 10 horizontal grid lines are all plotted outside this range. How to accomplish

JavaFX 2.x : Logarithmic scale on Y axis

ε祈祈猫儿з 提交于 2019-12-21 02:41:14
问题 As from this very good post here Logarithmic scale in Java FX 2 I have changed this class to get log scale on Y axis, and it works fine. The only problem I have is that there are very few horizontal grid lines and scale always start ranges from 0 or near zero. Here is what I get I would like to have tick values grid also in the min and max range of my data serie, in this case min = 19,35 max = 20,35; as of now all 10 horizontal grid lines are all plotted outside this range. How to accomplish

python: scatter plot logarithmic scale

六眼飞鱼酱① 提交于 2019-12-20 16:14:21
问题 In my code, I take the logarithm of two data series and plot them. I would like to change each tick value of the x-axis by raising it to the power of e (anti-log of natural logarithm). In other words. I want to graph the logarithms of both series but have x-axis in levels. Here is the code that I'm using. from pylab import scatter import pylab import matplotlib.pyplot as plt import pandas as pd from pandas import Series, DataFrame import numpy as np file_name = '/Users/joedanger/Desktop

numerically stable way to multiply log probability matrices in numpy

青春壹個敷衍的年華 提交于 2019-12-20 10:18:41
问题 I need to take the matrix product of two NumPy matrices (or other 2d arrays) containing log probabilities. The naive way np.log(np.dot(np.exp(a), np.exp(b))) is not preferred for obvious reasons. Using from scipy.misc import logsumexp res = np.zeros((a.shape[0], b.shape[1])) for n in range(b.shape[1]): # broadcast b[:,n] over rows of a, sum columns res[:, n] = logsumexp(a + b[:, n].T, axis=1) works but runs about 100 times slower than np.log(np.dot(np.exp(a), np.exp(b))) Using logsumexp((tile

Matplotlib - rotating text on log scale where angles are incorrectly rounded

佐手、 提交于 2019-12-20 04:45:06
问题 I am trying to have text rotate onto a plot which is shown on log scale. When I compute the angles (based on the solution in this answer) the angles are getting incorrectly rounded to 0 or 90 degrees . This is because the angles are computed on a linear scale first, and then transformed. This calculation in linear space is the cause of the trouble. Even in a situation where I know the gradient, (either in a linear or logarithmic scale), I am not sure how I can put this onto the graph

How to plot a linear regression to a double logarithmic R plot?

江枫思渺然 提交于 2019-12-20 01:09:28
问题 I have the following data: someFactor = 500 x = c(1:250) y = x^-.25 * someFactor which I show in a double logarithmic plot: plot(x, y, log="xy") Now I "find out" the slope of the data using a linear model: model = lm(log(y) ~ log(x)) model which gives: Call: lm(formula = log(y) ~ log(x)) Coefficients: (Intercept) log(x) 6.215 -0.250 Now I'd like to plot the linear regression as a red line, but abline does not work: abline(model, col="red") What is the easiest way to add a regression line to

Non-linear axes for imshow in matplotlib

﹥>﹥吖頭↗ 提交于 2019-12-18 18:53:28
问题 I am generating 2D arrays on log-spaced axes (for instance, the x pixel coordinates are generated using logspace(log10(0.95), log10(2.08), n) . I want to display the image using a plain old imshow, in its native resolution and scaling (I don't need to stretch it; the data itself is already log scaled), but I want to add ticks, labels, lines that are in the correct place on the log axes. How do I do this? Ideally I could just use commands line axvline(1.5) and the line would be in the correct