kalman filter parameter identification - python

I'm doing a project on traffic flow prediction using Kalman filter, the difficulty I've come across is regarding Kalman filter parameters.
these are the state prediction model and the flow observation equations:
x(k+1) =M(k).x(k)+w(k); z(k) = H.x(k)+v(k)
how can I find M(k), H, w(k), v(k)?

Related

Modularity maximization and GenLouvain implementation in python

I have a temporal multilayer network that I want to find communities by using modularity maximization.
I was wondering if there is an equivalent version of Matlab GenLouvain in Python for maximizing modularity in community detection?
Preliminary search yielded this library, but the corresponding GitHub repository is gone.
https://pypi.org/project/louvain/
There are several other algorithms, such as Leiden algorithm (https://www.nature.com/articles/s41598-019-41695-z) for maximizing modularity with python implementation (https://github.com/vtraag/leidenalg) but I am trying to explore my options at the moment and run different solvers on the supra-modularity matrix I have. So, I want to start with the good old GenLouvain and then compare different solvers with python implementation.
Does anyone have any suggestions?
It's been a while I posted this question but as given above I found out the leidenalg is the best implementation in Python for Multilayer Modularity Maximization(MMM) with the improvement of intermediate refinement step, handling arbitrarily disconnected communities appropriately.
Here's a piece of code I use to implement MMM with the configuration null model.
def leiden(self, G, interslice, resolution):
## G: the appropriate igraph as explained in the documentation
## interslice: float, interlayer edge weights for the diagonal coupling of consecutive layers
## resolution: float, spatial resolution parameter
layers, interslice_layer, G_full = la.time_slices_to_layers(G, interslice_weight = interslice)
partitions = [la.RBConfigurationVertexPartition(H,
weights = 'weight',
resolution_parameter = resolution) for H in layers]
## resolution parameter below has to be 0 to recover the original multilayer modularity equation
interslice_partition = la.RBConfigurationVertexPartition(interslice_layer,
weights = 'weight',
resolution_parameter = 0)
optimiser = la.Optimiser()
diff = optimiser.optimise_partition_multiplex(partitions + [interslice_partition])
return(partitions, interslice_partition)
Having said that, MMM is not the greatest approach to perform dynamic community detection. There are more temporal community detection tools in the literature that is utilizing random walks, stochastic block models, tensor factorization methods one should check.
There is now a Python reimplementation of GenLouvain called PyGenStability available here. It optimizes Markov Stability (a generalization of Modularity) with the Louvain or Leiden algorithms.
i currently use CPMVertexPartion from leidenalg to analyse my networks. by varying the resolution parameter i can find maximum modularity Q.
my network is dense, beta approx >10, and modularity can improve up to 0.5

How to build a model to predict a graph (not a image) in time series?

There is an adjacent matrix dataset that is based on time series. I would like to know if it is possible to build a neural network model to predict tn time point's matrix by using the previous time-series data. In my opinion, traditional models such as CNN may not fit for the sparse matrix graph.
Maybe you should give a look at Graph Neural Networks (specialy Spatial-Temporal Graph Networks). They use temporal information about graphs and its adjacency matrix to predict future nodes states, such values in the next-step.
You can read this survey paper as a start point and follow its cited works therefore.

Looking for recommendations on how to approch a face verification system and trying to find pre-trained models

I have failed miserably trying to train a face verification network on my own hardware. Here by face verification i mean looking at two photos and telling its the same person or not. So any recommendations for pre trained models?
there are many articles on implementation of face-net for face identification but none for face verification. Can anyone guide me if you know of any pre trained models that i can use?
Basically, you will need a FaceNet pretrained model. A FaceNet model creates an embedding vector for a human face in an image. As mentioned in the paper, researchers have used clustering algorithms using the embedded face vectors. Hence, you get a 128 or 256-dimensional vector which represents that human face.
After you've generated an embedding vector from the images of the two subjects, you can find the cosine similarity of both the vectors, which is a common metric used for vectors comparison.
By some experimenting, you can find some threshold similarity score, meaning, if the similarity scores exceed this threshold score, the faces are of the same subjects.
You can discover some references here:
https://medium.com/#vinayakvarrier/building-a-real-time-face-recognition-system-using-pre-trained-facenet-model-f1a277a06947
https://machinelearningmastery.com/how-to-develop-a-face-recognition-system-using-facenet-in-keras-and-an-svm-classifier/

What anomaly detection algorithms does Microsoft offer in the Anomaly Detection API

I am exploring the Microsoft Azure anomaly detection API for potential use in my organization. I want to know what algorithms (such as isolation forest, one-class SVM, autoencoder based anomaly detection) are available in the library. What choice of statistical models do I have through this API?
Do you mean the Anomaly detector in Azure cognitive service.
So far as I observed, the API is not only take single model or algorithm.
You can check its response, if you don't give period information, it will return one, it means the algorithm behind also calculate the period of the time series, maybe it is one feature they used to select model or algo.
I tried to send seasonal time series, non-seasonal time series, uptrend and down trend, it all return correct good result. Not sure they can expose the detail about the algorithms. But I can see same behavior if I used DFT, STL for seasonal time series and ESD or simple Zscore for non seasonal.
Sometimes the "entire" detection cannot return expected value as the "last" detection in a stream mode, but according to the API reference, https://aka.ms/anomaly-detector-rest-api-ref
, it seems the "entire" API build a single model or select one algo to do the detection and points after the target point are taken into account, so it should be anomaly in the whole time series. But the "last" api only use the points before the target point, so it mean the anomaly according to the history. It is a little confused though, but in streaming monitoring scenario, I think the "last" it the right choice, it is faster and more accurate.
According to Microsoft Tech Community
The following algorithms are used:
Fourier Transformation
Extreme Studentized Deviate (ESD)
STL Decomposition
Dynamic Threshold
Z-score detector
Some advanced algorithms to be disclosed pending paper publishing.

Predicting from inferred parameters in pymc3

I am trying to understand this from a non-Bayesian background.
In linear regression or blackbox machine learning tools the work flow is something like the following.
Get data
Prepare data
Model data (learn from it [or part of it, the training set])
Test model (usually on the test set)
If model is good according to some metric, goto 6, else
investigate and revise work.
Model is good enough; use it to predict/classify, etc.
So let's say I use pymc3 to try to understand the relationship between advertising expenditure and revenue from goods sold. If all stages from 1 to 5 go well, then in frequentest statistics used in R and machine learning packages such as scikit-learn, I only need to pass new unseen data to the learned model and invoke the predict method. This will usually print out a predicted value of Y (revenue from goods sold), given some unseen value(s) of X (advertising expenditure), with some confidence intervals or some other margin of error still being taken into account.
How would one go about doing that in pymc3? If I end up with many slopes and many betas then which should I use for predicting? And wouldn't taking the mean of all slopes and all betas to use be like throwing away a lot of otherwise useful learned knowledge?
I find if difficult to understand how sampling from the posterior can help in this. One can imagine bosses who need to be told about an expected revenue from goods sold Y figure given some advertising expenditure X amount, with some confidence and error margins. Aside from plotting, I don't know how sampling from posterior can be incorporated into a management report and make it useful for cash flow planning by interested parties.
I know some of us are spoiled coming from R and maybe scikit-learn, but wouldn't it be nice if there was a predict method that dealt with this matter in a more uniform and standardized way?
Thanks
One way of taking into account the uncertainty in parameters when making predictions with a model is to use the posterior predictive distribution. This distribution tells you the probability of a new observation, conditioned on the data that you used to constrain the model parameters. If the revenue is Y, the advertising expenditure is X, the model parameters are theta and the data used to constrain the model are X', then you can write
The left hand side is the probability of attaining revenue Y given an expenditure X, and the data used to constrain the model X'. This is the posterior predictive distribution of your model, and should be used when making predictions. p(Y | X, theta) is the probability of revenue Y given some set of model parameters theta and the expenditure X. p(theta | X') is the posterior distribution on the model parameters given the data that you used to constrain the model.
When using software like pymc3, you obtain samples from p(theta | X'). You can use these to do the integral above in a Monte-Carlo fashion. If you have N samples from the posterior in your MCMC chain, then you can do the sum
in other words, you compute p(Y | X, theta_n) for every set of parameters in your MCMC, and then take the average (note that this isnt the same as `taking the mean of all slopes and all betas' as you mentioned in your question, because you are computing the average of a pdf rather than the parameters themselves). In practice this should be easy to code, you just need to implement the function p(Y | X, theta) and then plug in your posterior parameter samples, then take the mean at the end. This gives you the fairest representation of your model prediction given your MCMC sampling.

Categories