covariance

How to compute a covariance matrix

痴心易碎 提交于 2019-12-10 14:24:31
问题 this question seems surprisingly obscure...I asked google before posting it here and the closest thing I found that resemble an answer is this : Covariance matrix computation However I am not sure of the answer, from the comments. What would be the best way to correctly compute a covariance matrix in C#? Any good free library? Thanks! 回答1: I finally found the AlgLib library which looks promising. It has a function to calculate covariance matrix : public static void covm(double[,] x, out

Casting from IEnumerable<Object> to IEnumerable<string>

不打扰是莪最后的温柔 提交于 2019-12-10 13:12:51
问题 Recently I found a very surprising behavior in c#. I had a method which takes IEnumerable<Object> as a parameter and i was passing IEnumerable<string> but it's not possible. While in c# everything can be upcast to Object than why this is not possible? It's totally confusing for me. Please someone clear me on this issue. 回答1: The technical term for this is that generics are invariant in C# 3.0 and earlier. From C#4.0 onward, the cast works. What invariant means is that there is no relationship

PyMC - wishart distribution for covariance estimate

时光毁灭记忆、已成空白 提交于 2019-12-10 11:49:41
问题 I need to model and estimate a variance-covariance matrix from asset class returns so I was looking at the stock returns example given in chapter 6 of https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers Here is my simple implementation where I start with a sample using a multivariate normal with a known mean and variance-covariance matrix. I then try to estimate it using a non-informative priror. The estimate is different from the known prior so I'm

Covariant type parameter

旧时模样 提交于 2019-12-10 11:34:33
问题 I have been trying to push my understanding of Scala a little bit further lately and I cannot really figure out some things about covariant/contravariant type parameters. Let's say I have a class called Basket as follows : class Basket[+A <: Fruit](items: List[A]) { // ... def addAll[B >: A <: Fruit](newItems: List[B]): Basket[B] = new Basket(items ++ newItems) // ... } and some classes like this: trait Fruit class Banana extends Fruit class Orange extends Fruit I know for sure that these

Efficiently Obtain IReadOnlyDictionary<int, Animals> from Dictionary<int, Fleas>

荒凉一梦 提交于 2019-12-10 11:22:18
问题 public class Flea : Animals {...} var fleas = new Dictionary<int, Flea>(); public IReadOnlyDictionary<string, Animal> Animals => fleas.ToDictionary(pair => pair.Key, pair => (Animal)pair.Value); Q Is there a more efficient way to obtain Animals from fleas ? 回答1: .NET supports covariance in interfaces, delegates, generic types and arrays. The interface or type has to specify it's covariant though with the out keyword. You can write IEnumerable<Animal> animals=new List<Flea>(); or var dict=new

Problem with Covariant return types from an abstract method

与世无争的帅哥 提交于 2019-12-10 11:19:26
问题 I’m trying to wrap up a two day beat down on Abstract methods and return type Covariance, I’ve already posted two similar questions and I am eternally grateful to the community for the info provided, I just need one last push to get to the finish line. Here is what I am trying to do: 2 abstract classes, RecruiterBase and CandidateBase, both have concreate implementations of RecruiterA and CandidateA. RecruiterBase has an abstract method to get all recruited candidates returning IQueryable. My

Shouldn't Covariance/Contravariance allow this in C# 4.5?

≯℡__Kan透↙ 提交于 2019-12-10 10:54:21
问题 private Dictionary<Type, List<IDataTransferObject>> dataStore = new Dictionary<Type, List<IDataTransferObject>>(); public void Insert<T>(T dto) where T : IDataTransferObject { if (!dataStore.ContainsKey(typeof(T))) { dataStore.Add(typeof(T), new List<T>()); } dataStore[typeof(T)].Add(dto); } The above code gives me a compile error on the dataStore.Add line because it doesn't like me trying to assign a List<T> to a List<IDataTransferObject> . Since my method restricts T to only

Covariant virtual functions return type problem

情到浓时终转凉″ 提交于 2019-12-10 10:23:12
问题 I have following code: #include <iostream> using namespace std; class Child1 { int i; }; class Child2 : public Child1 { int j; }; class Base1 { public: virtual Child1& getChildren() { cout << "Children1" << endl; return children; } private: Child1 children; }; class Base2 : public Base1 { public: virtual Child2& getChildren() { cout << "Children2" << endl; return children; } private: Child2 children; }; This code compiles fine but when I change the return type of getChildren() from reference

Some questions about covariance in Scala

喜夏-厌秋 提交于 2019-12-10 04:09:58
问题 I'm trying to understand covariance in Scala, but I cant find any examples that help me with this problem. I' ve got this code: class GenericCellImm[+T] (val x: T) {} and it compile well, but when I use it class GenericCellMut[+T] (var x: T) { } it doesn't compile. Why I can't use var (but I can use val) when I'm writing this code? How can I fix it? Also here is similar situation abstract class Sequence[+A] { def append(x: Sequence[A]): Sequence[A]} What is the problem? 回答1: You can't write

Covariance matrix computation

杀马特。学长 韩版系。学妹 提交于 2019-12-10 02:58:39
问题 Input : random vector X=xi, i=1..n. vector of means for X=meanxi, i=1..n Output : covariance matrix Sigma (n*n). Computation : 1) find all cov(xi,xj)= 1/n * (xi-meanxi) * (xj-meanxj), i,j=1..n 2) Sigma(i,j)=cov(xi,xj), symmetric matrix. Is this algorithm correct and has no side-effects? 回答1: Each xi should be a vector (random variable) with it's own variance and mean. Covariance matrix is symmetric, so you just need to compute one half of it (and copy the rest) and has variance of xi at main