covariance

Why does MATLAB native function cov (covariance matrix computation) use a different divisor than I expect?

天大地大妈咪最大 提交于 2019-12-06 11:58:27
Given a data matrix data of M dimensions and N samples, say, data = randn(N, M); I could compute the covariance matrix with data_mu = data - ones(N, 1)*mean(data); cov_matrix = (data_mu'*data_mu)./N If I use the native MATLAB function cov_matrix2 = cov(data) this will always be equal to cov_matrix = (data_mu'*data_mu)./(N-1) That is, the denominator is (N - 1) is one less. Why?? Can you reproduce it? Is this a bug?? I use MATLAB version 7.6.0.324 (2008). That is, the denominator is (N - 1) is one less. Why?? Can you reproduce it? Is this a bug?? See the cov documentation . It has to do with

How to Convert IList<SomeObject> to IList<ISomeInterface> where SomeObject implements ISomeInterface using covariance in C# 4.0

℡╲_俬逩灬. 提交于 2019-12-06 11:53:13
How to Convert IList to IList where SomeObject implements ISomeInterface using covariance in C# 4.0 I have something similar to following IList<Items> GetItems; IList<IItems> items = GetItems() as IList<IItems>; but items is null; the answer here was for pre 4.0: Converting an array of type T to an array of type I where T implements I in C# why not simply use IList<Items> GetItems; IList<IItems> items = GetItems().Cast<IItems>().ToList(); For this to work as you are thinking then I believe IList would have to be declared as covariant, not the items in the list. And IList does not support

Why A->B doesn't make List<A>->List<B>? Wouldn't that remove need for wildcards?

喜夏-厌秋 提交于 2019-12-06 11:03:59
Disclaimer: I'm not a professional developer, and I'm not intending to become one. Reading book about Java, as I wanted to try Android programming, no previous Java experience whatsoever. I'm reading this book - and I rather like it. I've read part of chapter about generic classes, got to the point where they mention wildcards, and got confused. If B extends A: List<B> is not a subtype of List<A> (as I understand it they're exactly the same) List<? extends B> is a subtype of List<? extends A> The latter allows for writing functions that accept arguments that are of generic type - for example

numpy.polyfit has no keyword 'cov'

依然范特西╮ 提交于 2019-12-06 09:28:35
I'm trying to use polyfit to find the best fitting straight line to a set of data, but I also need to know the uncertainty on the parameters, so I want the covariance matrix too. The online documentation suggests I write: polyfit(x, y, 2, cov=True) but this gives the error: TypeError: polyfit() got an unexpected keyword argument 'cov' And sure enough help(polyfit) shows no keyword argument 'cov'. So does the online documentation refer to a previous release of numpy? (I have 1.6.1, the newest one). I could write my own polyfit function, but has anyone got any suggestions for why I don't have a

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

左心房为你撑大大i 提交于 2019-12-06 06:04:47
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 IDataTransferObject's shouldn't the covariance/contravariance stuff in .Net 4 allow this code? I know I can change it

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

亡梦爱人 提交于 2019-12-06 04:34:59
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 ? .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 Dictionary<int,Flea>{ [1]=new Flea() }; IEnumerable<Animal> animals=dict.Values; This works because

weighted covariance matrix in numpy

随声附和 提交于 2019-12-06 03:47:20
I want to compute the covariance C of n measurements of p quantities, where each individual quantity measurement is given its own weight. That is, my weight array W has the same shape as my quantity array Q ( n by p ). The native np.cov() function only supports weights given to individual measurements (i.e., a vector of length n ). I can initialize a p by p matrix and iterate, but if p is large, then it's a very slow process. Since Q is known to have mean zero for each quantity (column of Q ), the explicit formula for each element of C is C[i,j] = np.sum( Q[:, i] * Q[:, j] * W[:, i] * W[:, j])

Covariance & Contravariance with List vs IEnumerable

天大地大妈咪最大 提交于 2019-12-06 02:47:28
So, let's say I have: Public Interface ISomeInterface End Interface Public Class SomeClass Implements ISomeInterface End Class If I have MyList as List(Of SomeClass) , I cannot directly set a List(Of ISomeInterface) = MyList . However, I can Set an IEnumerable(Of ISomeInterface) = MyList . With my understanding of Covariance I thought that it should work list to list since List(Of T) implements IEnumerable(Of T) . Clearly, I am missing something. Why does it work that way? Specifically why Can't I do something like: Dim Animals As new List(Of Animal) Dim Cats As List(Of IAnimal) = Animals

Covariant virtual functions return type problem

空扰寡人 提交于 2019-12-05 22:20:34
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 type to object type in either or both Base1 and Base2 (e.g. virtual Child2 getChildren() , I get the

Valid type casting of both covariant and contravariant class at runtime in Scala

只谈情不闲聊 提交于 2019-12-05 17:45:27
I wrote a class implementing the command design pattern : class MyCommand[-T, +R](val name: String, val execute: T => R) , prepared two command and stored it in a MutableList: val commands = new mutable.MutableList[MyCommand[Nothing, Any]] commands += new MyCommand[String, String]("lower", s => s.toLowerCase()) commands += new MyCommand[Date, Long]("time", d => d.getTime) Then I have two data to be executed: val data = Array("StRiNG", new Date()) The problem for me is that I don't know how to determine which datum is applicable to the command: data.foreach { d => commands.foreach { c => //