Finding any element in symmetric min max heap - find

I am looking to find (and update) a single element in a symmetric min-max heap. In this project I need to be able to update ANY element in logarithmic time. I have no idea how this would work though.
Finding an element in a min-heap or a max-heap is linear in runtime. According to everything I find online, a symmetric min-max heap can find the min and max elements in constant time but nothing even mentions finding another element.
The only thing I can think of is searching the entire heap but that gives linear runtime.

Related

Matlab optimization toolbox, optimizing hessian

Never used this toolbox before, I have a very large problem (i.e. number of variables) to be optimzed. I'm aware it's possible to optimize the hessian computation, which is my issue given the error:
Error using eye
Requested 254016x254016 (480.7GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may
take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information.
But according to this quote (from a forum) it must be possible to optimize the hessian computation:
If you are going to use the trust-region algorithm, you will need to
choose some combination of the options 'Hessian', 'HessMult', and
'HessPattern' to avoid full, explicit computation of the Hessian.
I struggle to find examples of this settings, does anyone know?
My problem is a sparse problem, if such information is necessary.
Basically I'm sure there's some extra options to be put in a line like:
option = optimoptions(#fminunc,...
'Display','iter','GradObj','on','MaxIter',30,...
'ObjectiveLimit',10e-10,'Algorithm','quasi-newton');
You probably need to add 'HessPattern',Hstr to optimoptions. An example is given here (In this example, Hstr is defined in brownhstr.mat; you need to calculate your own hessian sparsity pattern matrix Hstr).

Optimal way to find closest object

Given an array of points in 3D space, I need to find the closest point to a given point p.
I am looking to optimize performance for this search. Currently, I am using square of magnitude as a metric to compare distances, because of the obvious optimization in comparison to Euclidean distance (which requires the calculation of the square root).
I am aware of the existence of the Manhattan distance. However, I am not sure whether this metric could be used in this case. I need to do this evaluation correctly.
Is there a better way of achieving this calculation, performance wise? Perhaps storing the points in a specialized data structure, or using a different metric?
I read the related question (Fastest way to find the closest point to a given point in 3D, in Python), but am still wondering about the optimal metric for comparison.

Is there Sparse Matrix in Matlab allowing reading data entry in O(1) time?

To efficiently add/delete any non-zero entry in the sparse matrix, binary-tree etc will be used to let such operation completed in O(logN) time where N is the number of non-zero entries. Thus, reading a non-zero entry can also cost O(logN) time.
However, in practice, we may have no need to add/delete any entry on a sparse matrix A, but only need to read its non-zero entries to do matrix-vector multiplication Ax. So, I hope to read any non-zero entry of A very fast, maybe in O(1) time.
My question is, Matlab can do such thing?
It is theoretically possible. From what I saw on the internet (this and this), Matlab uses Dictionary of keys (DOK) to store sparse matrix, though I couldn't find any solid statement on that part. A dictionary has an access time of O(1) ofc.
To answer if Matlab actually does this I would suggest running some simple testing with time measuring (using timeit or tic + toc).

better building of kd-trees

Has anyone ever tried improving kd-trees using the following method?
Dividing each numeric dimension via some 1-d clustering method (e.g. Jenks Natural Breaks Optimization, or FayyadIranni or xyz...)
Sorting the dimensions on the expected value of the variance reduction within each division of that dimension
Building the KD-tree top-down selecting attributes from the order found in (2)
Breaking dimensions at each level of the KD-tree using the divisions found in (1)
And just to say the obvious. If (3) terminates when #rows is (say) less than 30 then nearest neighbor would require 30 distance measures, not N.
You want the tree to be balanced, so there is not much leeway in terms of where to split.
Also, you want the construction to be fast.
If you put in an O(n^2) method during construction, construction will likely be the new bottleneck.
In many cases, the very simple (original) k-d-tree is just as fast as any of the "optimized" techniques that try to determine the "best" splitting axis.

Is it possible to calculate Euclidean Distance between two varying length matrices?

I have started working on online signature data-set for verification purpose. I have two matrices containing digitized data of two signatures of varying length (the number of rows differ). e.g. one is 177×7 and second is 170×7.
I want to treat each column as one time series and I'd like to compare one time series of a signature with the corresponding time series of second signature.
How should I align the two time series?
I think this question really belongs on Math.StackExchange, but I will do my best to answer it here. The short answer is that the Euclidean distance cannot be applied in this case and you will need to define your own notion of distance. This may or may not actually be feasible.
The notion of distance relies on the existence of a "metric" defined on the space of interest. If your vectors are of different lengths then traditional metrics (including the Euclidean distance) are ill-defined and you need to define a new metric that works for you.
There are two things you'll need to do here:
Define the space you're working with. This seems to be the set of vectors of length 177 or length 170. This is a very unusual set.
Define your metric (and ensure that it actually meets all the properties of a metric).
The most obvious solution is to project vectors of length 177 into the space of vectors of length 170 and then compute the Euclidean distance as usual. For example, you could just ignore the last 7 elements of the vector. Note that this is not a metric on your original set as it violates the condition ( d(x,y)=0 iff x=y ), but it is a metric on the projected vectors. There may be a clever solution on the original set, but there is not an obvious one. Again, the people on Math.StackExchange may be able to help you more.