I am calculating a weights matrix for a geopandas df. I know there is a keyword that will allow me to silence the island warning (pysal doc), but I get a keyword error when I try to use it...
wt = ps.weights.DistanceBand.from_dataframe(df, threshold=600000, binary=True, silent_island_warning=True)
Error...
TypeError: __init__() got an unexpected keyword argument 'silent_island_warning'
Any help would be much appreciated. Thanks!
The helper functions use the 'silent' argument, as opposed to the W object which uses the 'silent_island_warning' argument.
wt = ps.weights.DistanceBand.from_dataframe(df, threshold=600000, binary=True, silent=True)
See source: https://github.com/pysal/pysal/blob/master/pysal/weights/Distance.py
Related
I am using RANSAC to fit a line to my data. The data is 30X2 double, I have used MatLab example to write the code given below, but I am getting an error in my problem. I don't understand the error and unable to resolve it.
The link to Matlab example is
https://se.mathworks.com/help/vision/ref/ransac.html
load linedata
data = [xm,ym];
N = length(xm); % number of data points
sampleSize = 2; % number of points to sample per trial
maxDistance = 2; % max allowable distance for inliers
fitLineFcn = polyfit(xm,ym,1); % fit function using polyfit
evalLineFcn =#(model) sum(ym - polyval(fitLineFcn, xm).^2,2); % distance evaluation function
[modelRANSAC, inlierIdx] = ransac(data,fitLineFcn,evalLineFcn,sampleSize,maxDistance);
The error is as follows
Error using ransac Expected fitFun to be one of these types:
function_handle
Instead its type was double.
Error in ransac>parseInputs (line 202) validateattributes(fitFun,
{'function_handle'}, {'scalar'}, mfilename, 'fitFun');
Error in ransac (line 148) [params, funcs] = parseInputs(data, fitFun,
distFun, sampleSize, ...
Lets read the error message and the documentation, as they tend to have all the information required to solve the issue!
Error using ransac Expected fitFun to be one of these types:
function_handle
Instead its type was double.
Hum, interesting. If you read the docs (which is always the first thing you should do) you see that fitFun is the second input. The error says its double, but it should be function_handle. This is easy to verify, indeed firLineFun is double!
But why? Well, lets read more documentation, right? polyfit says that it returns an array of the coefficient values, not a function_hanlde, so indeed everything the documentation says and the error says is clear about why you get the error.
Now, what do you want to do? It seems that you want to use polyfit as the function to fit with ransac. So we need to make it a function. According to the docs, fitFun has to be of the form fitFun(data), so we just do that, create a function_handle for this;
fitLineFcn=#(data)polyfit(data(:,1),data(:,2),1);
And magic! It works!
Lesson to learn: read the error text you provide, and the documentation1, all the information is there. In fact, I have never used ransac, its just reading the docs that led me to this answer.
1- In fact, programmers tend to reply with the now practically a meme: RTFM often, as it is always the first step on everything programming.
Happy Monday Everyone!
So. I'm really, really new to IDL. I need to translate a program I have written in Python to IDL, and I can barely get it started.
I am trying to define a function, but I am given the following error each time I try to compile it.
% Compiled module: OSTN02.
% Compiled module: OSTN02.
% Attempt to call undefined procedure: 'OSTN02'.
% Execution halted at: $MAIN$
I have tried following the guide from Harris Geospatial, but I am getting nowhere.
The code is below:
FUNCTION OSTN02, DATA, EASTCOL, NORTHCOL
;MAY NEED TO ADD FILLNaN HERE
DATAFILE = READLIS(FILE = !DATA_DIR + 'PROJECT ONE/OSTN15_OSGM15_DataFile.CSV', SEP = ',')
RETURN, DATAFILE
STOP
END
Any help is much appreciated. Thank you.
The error message is telling you:
% Attempt to call undefined procedure: 'OSTN02'.
You have defined a function, but IDL is looking for a procedure (because you are calling it as a procedure). The call to your function should be:
datafile = ostn02(data, eastcol, northcol)
although you aren't using those parameters, so you might want to remove them from your function.
Using mxnet 1.1,
When I try to run net(data) on the following network:
net = gluon.nn.HybridSequential()
with net.name_scope():
net.add(gluon.nn.Embedding(input_dim=MAX_EVENT_INDEX + 1, output_dim=EMBEDDING_VECTOR_LENGTH))
net.add(gluon.nn.Conv1D(channels=conv1D_filters, kernel_size=conv1D_kernel_size, activation='relu'))
net.add(gluon.nn.MaxPool1D(pool_size=max_pool_size, strides=2))
net.add(gluon.rnn.LSTMCell(100))
net.add(gluon.rnn.DropoutCell(dropout_rate))
net.add(gluon.rnn.LSTMCell(100))
net.add(gluon.rnn.DropoutCell(dropout_rate))
net.add(gluon.rnn.LSTMCell(100))
net.add(gluon.rnn.DropoutCell(dropout_rate))
net.add(gluon.nn.Flatten())
net.add(gluon.nn.Dense(1, activation="sigmoid"))
net.hybridize()
Error: forward() missing 1 required positional argument: 'states'
Everything works when I use gluon.nn.Sequential() with net.add(gluon.rnn.LSTM(100, dropout=dropout_rate))
Thanks
If you look into implementation of LSTMCell you would notice, that hybrid_forward requires explicit states argument. LSTM class, using its base class implementation doesn't require states parameter (it can be None). So switching from one to another will definitely help you.
LSTM class is more than LSTMCell. It actually uses LSTMCell internally, but it also adds extra functionality on top of it. For example, you can specify LSTM to be multilayered or bidirectional, where LSTMCell is essentially just a bunch of LSTM-related formulas for calculating gates, c and h.
I have the following issue:
I want to use autowrap to generate a compiled version of a sympy matrix, with cells containing sympy expressions. Depending on the specification of my problem, the number of arguments can get very large.
I ran into the following 2 issues:
The number of arguments that autowrap accepts seems to be limited to 509.
i.e., this works:
import sympy
from sympy.utilities.autowrap import autowrap
x = sympy.symbols("x:509")
exp = sum(x)
cyt = autowrap(exp, backend="cython", args=x)
and this fails to compile:
x = sympy.symbols("x:510")
exp = sum(x)
cyt = autowrap(exp, backend="cython", args=x)
The message I get seems not very telling:
[...] (Full output upon request)
Generating code
c:\users\[classified]\appdata\local\temp\tmp2zer8vfe_sympy_compile\wrapper_module_17.c(6293) : fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\p2\hash.c', line 884)
To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
LINK : fatal error LNK1257: code generation failed
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1257
Is there any way around this? I would like to use versions of my program that need ~1000 input variables.
(I have no understanding of C/cython. Is this an autowrap limitation, a C limitation ...?)
Partly connected to the above:
Can one compile functions that accept the arguments as array.
Is there any way to generate code that accepts a numpy array as input? I specifically mean one array for all the arguments, instead of providing the arguments as list. (Similar to lambdify using a DeferredVector). ufuncify supports array input, but as I understand only for broadcasting/vectorizing the function.
I would hope that an array as argument could circumvent the first problem above, which is most pressing for me. Apart from that, I would prefer array input anyways, both because it seems faster (no need to unpack the numpy array I have as input into a list), and also more straightforward and natural.
Does anyone have any suggestions what I can do?
Also, could anyone tell me whether f2py has similar limitations? This would also be an option for me if feasible, but I don't have it set up to work currently, and would prefer to know whether it helps at all before investing the time.
Thanks!
Edit:
I played around a bit with the different candidates for telling autowrap that the input argument will be something in array form, rather than a list of numbers. I'll document my steps here for posterity, and also to increase chances to get some input:
sympy.DeferredVector
Is what I use with lambdify for the same purpose, so I thought to give it a try. However, warning:
A = sympy.DeferredVector("A")
expression = A[0]+A[1]
cyt = autowrap(expression, backend="cython", args=A)
just completely crashed my OS - last statement started executing, (no feedback), everything got really slow, then no more reactions. (Can only speculate, perhaps it has to do with the fact that A has no shape information, which does not seem to bother lambdify, but might be a problem here. Anyways, seems not the right way to go.)
All sorts of array-type objects filled with the symbols in the expression to be wrapped.
e.g.
x0 ,x1 = sympy.symbols("x:2")
expression = x0 + x1
cyt = autowrap(expression, backend="cython", args=np.array([x0,x1]))
Still wants unpacked arguments. Replacing the last row by
cyt = autowrap(expression, backend="cython", args=[np.array([x0,x1])])
Gives the message
CodeGenArgumentListError: ("Argument list didn't specify: x0, x1 ", [InputArgument(x0), InputArgument(x1)])
Which is a recurrent theme to this approach: also happens when using a sympy matrix, a tuple, and so on inside the arguments list.
sympy.IndexedBase
This is actually used in the autowrap examples; however, in a (to me) inintuitive way, using an equation as the expression to be wrapped. Also, the way it is used there seems not really feasible to me: The expression I want to cythonize is a matrix, but its cells are themselves longish expressions, which I cannot obtain via index operations.
The upside is that I got a minimal example to work:
X = sympy.IndexedBase("X",shape=(1,1))
expression = 2*X[0,0]
cyt = autowrap(expression, backend="cython", args=[X])
actually compiles, and the resulting function correctly evaluates - when passed a 2d-np.array.
So this seems the most promising avenue, even though further extensions to this approach I keep trying fail.
For example this
X = sympy.IndexedBase("X",shape=(1,))
expression = 2*X[0]
cyt = autowrap(expression, backend="cython", args=[X])
gets me
[...]\site-packages\sympy\printing\codeprinter.py", line 258, in _get_expression_indices " rhs indices in %s" % expr)
ValueError: lhs indices must match non-dummy rhs indices in 2*X[0]
even though I don't see how it should be different from the working one above.
Same error message when sticking to two dimensions, but increasing the size of X:
X = sympy.IndexedBase("X",shape=(2,2))
expression = 2*X[0,0]+X[0,1]+X[1,0]+X[1,1]
cyt = autowrap(expression, backend="cython", args=[X])
ValueError: lhs indices must match non-dummy rhs indices in 2*X[0, 0] + X[0, 1] + X[1, 0] + X[1, 1]
I tried snooping around the code for autowrap, but I feel a bit lost there...
So I'm still searching for a solution and happy for any input.
Passing the argument as an array seems to work OK
x = sympy.MatrixSymbol('x', 520, 1)
exp = 0
for i in range(x.shape[0]):
exp += x[i]
cyt = autowrap(exp, backend='cython')
arr = np.random.randn(520, 1)
cyt(arr)
Out[48]: -42.59735861021934
arr.sum()
Out[49]: -42.597358610219345
I'm using numpy.svd to compute singular value decompositions of badly conditioned matrices. For some special cases the svd won't converge and raise a Linalg.Error. I've done some research and found that numpy uses the DGESDD routine from LAPACK. The standard implementation has a hardcoded iteration limit of 35 or something iterations. If I try to decompose the same matrix in Matlab, everything works fine, and I think there's two reasons for that:
1. Matlab uses DGESVD instead of DGESDD which in general seems to be more robust.
2. Matlab uses an iteration limit of 75 in the routine. (They changed it in the source and recompiled it.)
Now the question is: Is there a simple way to change the used backend in numpy from DGESDD to DGESVD without having to modify the numpy source ?
Thanks in advance
Mischa
What worked for me was to only compute the "economy size" SVD of that matrix X:
U,S,V = np.linalg.svd(X, full_matrices=False)
I'm a little late, but maybe this will help someone else...
I had a similar problem in julia.
I found this approach from the R help list, which should work for any environment using the lapack library:
Basically, if svd(M) fails, try svd(M'), and swap the resulting U,V appropriately.
Here's how I'm doing it in julia:
try
U,S,V = svd( E_restricted )
failed = false
catch
failed = true
end
if failed
# try it with matrix transposed
try
V,S,U = svd( E_restricted' )
failed = false
catch
failed = true
end
end
if failed
error("ERROR: svd(E) and svd(E') failed!")
end